Browse Source

fix:Increase the number of clusters, adapters, and tasks

Former-commit-id: 65112cc063
pull/26/head
qiwang 1 year ago
parent
commit
bf8969f1a6
7 changed files with 110 additions and 30 deletions
  1. +10
    -0
      api/desc/core/pcm-core.api
  2. +3
    -0
      api/desc/pcm.api
  3. +28
    -0
      api/internal/handler/adapters/getclustersumhandler.go
  4. +2
    -28
      api/internal/handler/routes.go
  5. +58
    -0
      api/internal/logic/adapters/getclustersumlogic.go
  6. +9
    -0
      api/internal/types/types.go
  7. +0
    -2
      go.mod

+ 10
- 0
api/desc/core/pcm-core.api View File

@@ -763,4 +763,14 @@ type ClusterResp {

type ClusterListResp {
List []ClusterInfo `json:"list,omitempty"`
}

type clusterSumReq {

}

type clusterSumReqResp{
ClusterSum int `json:"ClusterSum,omitempty"`
AdapterSum int `json:"AdapterSum,omitempty"`
TaskSum int `json:"TaskSum,omitempty"`
}

+ 3
- 0
api/desc/pcm.api View File

@@ -613,6 +613,9 @@ service pcm {

@handler GetAdapterClusterHandler
get /adapter/relation (AdapterReq) returns (AdapterRelationResp)

@handler GetClusterSumHandler
get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp)
}

@server(


+ 28
- 0
api/internal/handler/adapters/getclustersumhandler.go View File

@@ -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)
}
}
}

+ 2
- 28
api/internal/handler/routes.go View File

@@ -752,36 +752,10 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/adapter/relation",
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,
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"),


+ 58
- 0
api/internal/logic/adapters/getclustersumlogic.go View File

@@ -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
}

+ 9
- 0
api/internal/types/types.go View File

@@ -731,6 +731,15 @@ type ClusterListResp struct {
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 {
SlurmVersion string `json:"slurmVersion"`
Name string `json:"name"`


+ 0
- 2
go.mod View File

@@ -2,8 +2,6 @@ module gitlink.org.cn/jcce-pcm/pcm-coordinator

go 1.21

toolchain go1.21.0

require (
github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos v0.0.0-20230419021610-13bbc83fbc3c
github.com/Masterminds/squirrel v1.5.4


Loading…
Cancel
Save