added queryresources api

This commit is contained in:
tzwang 2024-12-01 19:34:50 +08:00
parent a2ae89e103
commit b39e821aec
5 changed files with 27 additions and 9 deletions

View File

@ -939,7 +939,7 @@ service pcm {
get /schedule/getClusterBalanceById/:adapterId/:clusterId (GetClusterBalanceByIdReq) returns (GetClusterBalanceByIdResp)
@handler QueryResourcesHandler
get /schedule/queryResources returns (QueryResourcesResp)
get /schedule/queryResources (QueryResourcesReq) returns (QueryResourcesResp)
}
@server(

View File

@ -151,9 +151,11 @@ type (
Balance float64 `json:"balance"`
}
QueryResourcesReq{
AdapterId string `form:"adapterId"`
}
QueryResourcesResp{
Code int32 `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
)

View File

@ -4,14 +4,23 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/schedule"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
func QueryResourcesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.QueryResourcesReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := schedule.NewQueryResourcesLogic(r.Context(), svcCtx)
resp, err := l.QueryResources()
resp, err := l.QueryResources(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -23,8 +23,13 @@ func NewQueryResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Qu
}
}
func (l *QueryResourcesLogic) QueryResources() (resp *types.QueryResourcesResp, err error) {
// todo: add your logic here and delete this line
func (l *QueryResourcesLogic) QueryResources(req *types.QueryResourcesReq) (resp *types.QueryResourcesResp, err error) {
resp = &types.QueryResourcesResp{}
return
_, err = l.svcCtx.Scheduler.AiService.AiCollectorAdapterMap[req.AdapterId]["req.ClusterId"].GetResourceUsage(l.ctx)
if err != nil {
return nil, err
}
return resp, nil
}

View File

@ -5870,9 +5870,11 @@ type GetClusterBalanceByIdResp struct {
Balance float64 `json:"balance"`
}
type QueryResourcesReq struct {
AdapterId string `form:"adapterId"`
}
type QueryResourcesResp struct {
Code int32 `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}