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.8 kB

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

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.