You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

registerclusterlogic.go 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package cloud
  2. import (
  3. "context"
  4. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
  5. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
  6. "strconv"
  7. "time"
  8. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  9. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type RegisterClusterLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewRegisterClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterClusterLogic {
  18. return &RegisterClusterLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (*types.CloudResp, error) {
  25. var phyInfos []models.ScParticipantPhyInfo
  26. var resp types.CloudResp
  27. l.svcCtx.DbEngin.Raw("select * from sc_participant_phy_info where `name` = ?", req.Name).Scan(&phyInfos)
  28. if len(phyInfos) != 0 {
  29. resp.Code = "400"
  30. resp.Msg = "cluster name already exist"
  31. resp.Data = ""
  32. return &resp, nil
  33. }
  34. participant := models.ScParticipantPhyInfo{}
  35. participant.Token = req.Token
  36. participant.Name = req.Name
  37. participant.Address = req.Address
  38. participant.Type = "CLOUD"
  39. participant.Id = utils.GenSnowflakeID()
  40. participant.MetricsUrl = req.MetricsUrl
  41. participant.CreatedTime = time.Now()
  42. participant.UpdatedTime = time.Now()
  43. labelInfo := models.ScParticipantLabelInfo{}
  44. labelInfo.Id = utils.GenSnowflakeID()
  45. labelInfo.ParticipantId = participant.Id
  46. labelInfo.CreatedTime = time.Now()
  47. labelInfo.Key = "cloud"
  48. labelInfo.Value = "sealos"
  49. tx := l.svcCtx.DbEngin.Create(&participant)
  50. if tx.Error != nil {
  51. return nil, tx.Error
  52. }
  53. tx2 := l.svcCtx.DbEngin.Create(&labelInfo)
  54. if tx2.Error != nil {
  55. return nil, tx.Error
  56. }
  57. resp.Code = string(200)
  58. resp.Msg = "success"
  59. resp.Data = "participantId:" + strconv.FormatInt(participant.Id, 10)
  60. return &resp, nil
  61. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.