From 1b8fc75c95e2a540d36defa7a15aba0a4bd89e0c Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Thu, 15 Jun 2023 18:38:24 +0800 Subject: [PATCH] pcm interface:list cluster for compute center Former-commit-id: e2d56722f518340ed00e0822ee74e4537db05cc3 --- adaptor/PCM-CORE/api/desc/core/pcm-core.api | 3 +-- adaptor/PCM-CORE/api/desc/pcm.api | 2 +- adaptor/PCM-CORE/api/internal/handler/routes.go | 2 +- .../PCM-CORE/api/internal/logic/core/listclusterlogic.go | 8 +++++++- adaptor/PCM-CORE/api/internal/types/types.go | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/adaptor/PCM-CORE/api/desc/core/pcm-core.api b/adaptor/PCM-CORE/api/desc/core/pcm-core.api index 457e79a9..e474bb7e 100644 --- a/adaptor/PCM-CORE/api/desc/core/pcm-core.api +++ b/adaptor/PCM-CORE/api/desc/core/pcm-core.api @@ -271,10 +271,9 @@ type ( } ) - type ( listClusterReq { - CenterId int32 `json:"centerId"` + CenterId int32 `path:"centerId"` } listClusterResp { Code int32 `json:"code"` diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index e660a839..b0ad1e03 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -34,7 +34,7 @@ service pcm { get /core/listCenter () returns (listCenterResp) @handler listClusterHandler - get /core/listCluster (listClusterReq) returns (listClusterResp) + get /core/listCluster/:centerId (listClusterReq) returns (listClusterResp) @handler submitJobHandler post /core/submitJob (submitJobReq) returns (submitJobResp) diff --git a/adaptor/PCM-CORE/api/internal/handler/routes.go b/adaptor/PCM-CORE/api/internal/handler/routes.go index 639aa308..28e7f4ca 100644 --- a/adaptor/PCM-CORE/api/internal/handler/routes.go +++ b/adaptor/PCM-CORE/api/internal/handler/routes.go @@ -39,7 +39,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/core/listCluster", + Path: "/core/listCluster/:centerId", Handler: core.ListClusterHandler(serverCtx), }, { diff --git a/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go b/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go index c1afbef3..1c47a553 100644 --- a/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go +++ b/adaptor/PCM-CORE/api/internal/logic/core/listclusterlogic.go @@ -30,8 +30,14 @@ func (l *ListClusterLogic) ListCluster(req *types.ListClusterReq) (*types.ListCl //var centersModel []model.ComputeCenter var resp types.ListClusterResp - l.svcCtx.DbEngin.Raw("select * from compute_cluster").Scan(&clustersModel) + l.svcCtx.DbEngin.Raw("select * from compute_cluster where center_id = ?", req.CenterId).Scan(&clustersModel) + if clustersModel == nil { + resp.Code = 200 + resp.Msg = "success" + resp.Data.TotalCount = 0 + return &resp, nil + } var clustersModelV = *clustersModel for _, clusterModel := range clustersModelV { diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index bb317233..7cc418da 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -250,7 +250,7 @@ type Center struct { } type ListClusterReq struct { - CenterId int32 `json:"centerId"` + CenterId int32 `path:"centerId"` } type ListClusterResp struct {