Former-commit-id: 65112cc063
pull/26/head
| @@ -763,4 +763,14 @@ type ClusterResp { | |||||
| type ClusterListResp { | type ClusterListResp { | ||||
| List []ClusterInfo `json:"list,omitempty"` | List []ClusterInfo `json:"list,omitempty"` | ||||
| } | |||||
| type clusterSumReq { | |||||
| } | |||||
| type clusterSumReqResp{ | |||||
| ClusterSum int `json:"ClusterSum,omitempty"` | |||||
| AdapterSum int `json:"AdapterSum,omitempty"` | |||||
| TaskSum int `json:"TaskSum,omitempty"` | |||||
| } | } | ||||
| @@ -613,6 +613,9 @@ service pcm { | |||||
| @handler GetAdapterClusterHandler | @handler GetAdapterClusterHandler | ||||
| get /adapter/relation (AdapterReq) returns (AdapterRelationResp) | get /adapter/relation (AdapterReq) returns (AdapterRelationResp) | ||||
| @handler GetClusterSumHandler | |||||
| get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp) | |||||
| } | } | ||||
| @server( | @server( | ||||
| @@ -0,0 +1,28 @@ | |||||
| package adapters | |||||
| import ( | |||||
| "net/http" | |||||
| "github.com/zeromicro/go-zero/rest/httpx" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | |||||
| ) | |||||
| func GetClusterSumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| return func(w http.ResponseWriter, r *http.Request) { | |||||
| var req types.ClusterSumReq | |||||
| if err := httpx.Parse(r, &req); err != nil { | |||||
| httpx.ErrorCtx(r.Context(), w, err) | |||||
| return | |||||
| } | |||||
| l := adapters.NewGetClusterSumLogic(r.Context(), svcCtx) | |||||
| resp, err := l.GetClusterSum(&req) | |||||
| if err != nil { | |||||
| httpx.ErrorCtx(r.Context(), w, err) | |||||
| } else { | |||||
| httpx.OkJsonCtx(r.Context(), w, resp) | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -752,36 +752,10 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||||
| Path: "/adapter/relation", | Path: "/adapter/relation", | ||||
| Handler: adapters.GetAdapterClusterHandler(serverCtx), | Handler: adapters.GetAdapterClusterHandler(serverCtx), | ||||
| }, | }, | ||||
| }, | |||||
| rest.WithPrefix("/pcm/v1"), | |||||
| ) | |||||
| server.AddRoutes( | |||||
| []rest.Route{ | |||||
| { | |||||
| Method: http.MethodGet, | |||||
| Path: "/schedule/ai/getResourceTypes", | |||||
| Handler: schedule.ScheduleGetAiResourceTypesHandler(serverCtx), | |||||
| }, | |||||
| { | |||||
| Method: http.MethodGet, | |||||
| Path: "/schedule/ai/getTaskTypes", | |||||
| Handler: schedule.ScheduleGetAiTaskTypesHandler(serverCtx), | |||||
| }, | |||||
| { | |||||
| Method: http.MethodGet, | |||||
| Path: "/schedule/ai/getDatasets", | |||||
| Handler: schedule.ScheduleGetDatasetsHandler(serverCtx), | |||||
| }, | |||||
| { | { | ||||
| Method: http.MethodGet, | Method: http.MethodGet, | ||||
| Path: "/schedule/ai/getStrategies", | |||||
| Handler: schedule.ScheduleGetStrategyHandler(serverCtx), | |||||
| }, | |||||
| { | |||||
| Method: http.MethodPost, | |||||
| Path: "/schedule/submit", | |||||
| Handler: schedule.ScheduleSubmitHandler(serverCtx), | |||||
| Path: "/adapter/clusterSum", | |||||
| Handler: adapters.GetClusterSumHandler(serverCtx), | |||||
| }, | }, | ||||
| }, | }, | ||||
| rest.WithPrefix("/pcm/v1"), | rest.WithPrefix("/pcm/v1"), | ||||
| @@ -0,0 +1,58 @@ | |||||
| package adapters | |||||
| import ( | |||||
| "context" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | |||||
| "github.com/zeromicro/go-zero/core/logx" | |||||
| ) | |||||
| type GetClusterSumLogic struct { | |||||
| logx.Logger | |||||
| ctx context.Context | |||||
| svcCtx *svc.ServiceContext | |||||
| } | |||||
| func NewGetClusterSumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClusterSumLogic { | |||||
| return &GetClusterSumLogic{ | |||||
| Logger: logx.WithContext(ctx), | |||||
| ctx: ctx, | |||||
| svcCtx: svcCtx, | |||||
| } | |||||
| } | |||||
| func (l *GetClusterSumLogic) GetClusterSum(req *types.ClusterSumReq) (resp *types.ClusterSumReqResp, err error) { | |||||
| // todo: add your logic here and delete this line | |||||
| resp = &types.ClusterSumReqResp{} | |||||
| var AdapterSum int // | |||||
| var ClusterSum int // | |||||
| var TaskSum int // | |||||
| // | |||||
| sqlStr := "SELECT COUNT(*) FROM `t_adapter` t where t.type = 0`" | |||||
| tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&AdapterSum) | |||||
| if tx.Error != nil { | |||||
| logx.Error(err) | |||||
| return nil, tx.Error | |||||
| } | |||||
| // | |||||
| sqlStrCluster := "SELECT COUNT(*) FROM `t_cluster`t where t.label ='openstack' || t.label='kubernetes'\n" | |||||
| txCluster := l.svcCtx.DbEngin.Raw(sqlStrCluster).Scan(&ClusterSum) | |||||
| if txCluster.Error != nil { | |||||
| logx.Error(err) | |||||
| return nil, txCluster.Error | |||||
| } | |||||
| // | |||||
| sqlStrTask := "SELECT COUNT(*) FROM `task`" | |||||
| txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&TaskSum) | |||||
| if txTask.Error != nil { | |||||
| logx.Error(err) | |||||
| return nil, txTask.Error | |||||
| } | |||||
| resp.TaskSum = TaskSum | |||||
| resp.ClusterSum = ClusterSum | |||||
| resp.AdapterSum = AdapterSum | |||||
| return resp, nil | |||||
| } | |||||
| @@ -731,6 +731,15 @@ type ClusterListResp struct { | |||||
| List []ClusterInfo `json:"list,omitempty"` | List []ClusterInfo `json:"list,omitempty"` | ||||
| } | } | ||||
| type ClusterSumReq struct { | |||||
| } | |||||
| type ClusterSumReqResp struct { | |||||
| ClusterSum int `json:"ClusterSum,omitempty"` | |||||
| AdapterSum int `json:"AdapterSum,omitempty"` | |||||
| TaskSum int `json:"TaskSum,omitempty"` | |||||
| } | |||||
| type Job struct { | type Job struct { | ||||
| SlurmVersion string `json:"slurmVersion"` | SlurmVersion string `json:"slurmVersion"` | ||||
| Name string `json:"name"` | Name string `json:"name"` | ||||
| @@ -2,8 +2,6 @@ module gitlink.org.cn/jcce-pcm/pcm-coordinator | |||||
| go 1.21 | go 1.21 | ||||
| toolchain go1.21.0 | |||||
| require ( | require ( | ||||
| github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos v0.0.0-20230419021610-13bbc83fbc3c | github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos v0.0.0-20230419021610-13bbc83fbc3c | ||||
| github.com/Masterminds/squirrel v1.5.4 | github.com/Masterminds/squirrel v1.5.4 | ||||