diff --git a/api/desc/cloud/pcm-cloud.api b/api/desc/cloud/pcm-cloud.api index 37c97b18..dc4cce6a 100644 --- a/api/desc/cloud/pcm-cloud.api +++ b/api/desc/cloud/pcm-cloud.api @@ -22,7 +22,6 @@ type ( Name string `form:"name"` // 名称 Address string `form:"address"` // 地址 token string `form:"token"` // 数算集群token - Type string `form:"type"` // 参与者类型:CLOUD-数算集群;AI-智算集群;HPC-超算集群 MetricsUrl string `form:"metricsUrl"` //监控url } diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 2443ad28..510e12e2 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -177,11 +177,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/cloud/deleteCluster", Handler: cloud.DeleteClusterHandler(serverCtx), }, - { - Method: http.MethodGet, - Path: "/cloud/listCluster", - Handler: cloud.ListCloudClusterHandler(serverCtx), - }, { Method: http.MethodGet, Path: "/cloud/noticeTenant", diff --git a/api/internal/logic/cloud/deleteclusterlogic.go b/api/internal/logic/cloud/deleteclusterlogic.go index fadb5eef..494621aa 100644 --- a/api/internal/logic/cloud/deleteclusterlogic.go +++ b/api/internal/logic/cloud/deleteclusterlogic.go @@ -23,11 +23,15 @@ func NewDeleteClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Del } } -func (l *DeleteClusterLogic) DeleteCluster(req *types.DeleteClusterReq) (resp *types.CloudResp, err error) { +func (l *DeleteClusterLogic) DeleteCluster(req *types.DeleteClusterReq) (*types.CloudResp, error) { // 删除集群信息 + var resp types.CloudResp tx := l.svcCtx.DbEngin.Where("name = ?", req.Name).Delete(&models.ScParticipantPhyInfo{}) if tx.Error != nil { return nil, tx.Error } - return + resp.Code = string(200) + resp.Msg = "success" + resp.Data = "" + return &resp, nil } diff --git a/api/internal/logic/cloud/registerclusterlogic.go b/api/internal/logic/cloud/registerclusterlogic.go index e72e6b10..93916bfe 100644 --- a/api/internal/logic/cloud/registerclusterlogic.go +++ b/api/internal/logic/cloud/registerclusterlogic.go @@ -4,6 +4,7 @@ import ( "context" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" + "strconv" "time" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" @@ -26,14 +27,24 @@ func NewRegisterClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *R } } -func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (resp *types.CloudResp, err error) { - // 查询出所有p端信息 +func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (*types.CloudResp, error) { + var ms []models.ScParticipantPhyInfo + var resp types.CloudResp + + l.svcCtx.DbEngin.Raw("select * from sc_participant_phy_info where `name` = ?", req.Name).Scan(&ms) + if len(ms) != 0 { + resp.Code = "400" + resp.Msg = "cluster name already exist" + resp.Data = "" + return &resp, nil + } + participant := models.ScParticipantPhyInfo{} participant.Token = req.Token participant.Name = req.Name participant.Address = req.Address - participant.Type = req.Type + participant.Type = "SEALOS" participant.Id = utils.GenSnowflakeID() participant.MetricsUrl = req.MetricsUrl participant.CreatedTime = time.Now() @@ -43,5 +54,8 @@ func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (r if tx.Error != nil { return nil, tx.Error } - return + resp.Code = string(200) + resp.Msg = "success" + resp.Data = "participantId:" + strconv.FormatInt(participant.Id, 10) + return &resp, nil }