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.

createclusterlogic.go 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package adapters
  2. import (
  3. "context"
  4. "errors"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  6. "gorm.io/gorm"
  7. "time"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type CreateClusterLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewCreateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateClusterLogic {
  18. return &CreateClusterLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *CreateClusterLogic) CreateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) {
  25. adapter := &types.AdapterInfo{}
  26. result := l.svcCtx.DbEngin.Table("t_adapter").First(&adapter, req.AdapterId)
  27. if errors.Is(result.Error, gorm.ErrRecordNotFound) {
  28. return nil, errors.New("adapter does not exist")
  29. }
  30. cluster := types.ClusterInfo{}
  31. utils.Convert(req, &cluster)
  32. cluster.Id = utils.GenSnowflakeIDStr()
  33. cluster.CreateTime = time.Now().Format("2006-01-02 15:04:05")
  34. cluster.OwnerId = "0"
  35. tx := l.svcCtx.DbEngin.Table("t_cluster").Create(&cluster)
  36. if tx.Error != nil {
  37. logx.Errorf(tx.Error.Error())
  38. return nil, errors.New("cluster create failed")
  39. }
  40. return
  41. }

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.