repeat cluster name validate

Former-commit-id: 9c04866bf2dce4392d3c1224c1b7b9100d4283b9
This commit is contained in:
zhouqunjie 2023-11-23 20:54:36 +08:00
parent dfdedd7689
commit d80c49dccb
4 changed files with 24 additions and 12 deletions

View File

@ -22,7 +22,6 @@ type (
Name string `form:"name"` // 名称 Name string `form:"name"` // 名称
Address string `form:"address"` // 地址 Address string `form:"address"` // 地址
token string `form:"token"` // 数算集群token token string `form:"token"` // 数算集群token
Type string `form:"type"` // 参与者类型:CLOUD-数算集群;AI-智算集群HPC-超算集群
MetricsUrl string `form:"metricsUrl"` //监控url MetricsUrl string `form:"metricsUrl"` //监控url
} }

View File

@ -177,11 +177,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/cloud/deleteCluster", Path: "/cloud/deleteCluster",
Handler: cloud.DeleteClusterHandler(serverCtx), Handler: cloud.DeleteClusterHandler(serverCtx),
}, },
{
Method: http.MethodGet,
Path: "/cloud/listCluster",
Handler: cloud.ListCloudClusterHandler(serverCtx),
},
{ {
Method: http.MethodGet, Method: http.MethodGet,
Path: "/cloud/noticeTenant", Path: "/cloud/noticeTenant",

View File

@ -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{}) tx := l.svcCtx.DbEngin.Where("name = ?", req.Name).Delete(&models.ScParticipantPhyInfo{})
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, tx.Error
} }
return resp.Code = string(200)
resp.Msg = "success"
resp.Data = ""
return &resp, nil
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils" "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"strconv"
"time" "time"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" "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) { func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (*types.CloudResp, error) {
// 查询出所有p端信息 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 := models.ScParticipantPhyInfo{}
participant.Token = req.Token participant.Token = req.Token
participant.Name = req.Name participant.Name = req.Name
participant.Address = req.Address participant.Address = req.Address
participant.Type = req.Type participant.Type = "SEALOS"
participant.Id = utils.GenSnowflakeID() participant.Id = utils.GenSnowflakeID()
participant.MetricsUrl = req.MetricsUrl participant.MetricsUrl = req.MetricsUrl
participant.CreatedTime = time.Now() participant.CreatedTime = time.Now()
@ -43,5 +54,8 @@ func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (r
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, tx.Error
} }
return resp.Code = string(200)
resp.Msg = "success"
resp.Data = "participantId:" + strconv.FormatInt(participant.Id, 10)
return &resp, nil
} }