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.

updateclusterlogic.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package adapters
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/clause"
  9. "strconv"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  11. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type UpdateClusterLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewUpdateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClusterLogic {
  20. return &UpdateClusterLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) {
  27. cluster := &types.ClusterInfo{}
  28. result := l.svcCtx.DbEngin.Table("t_cluster").First(&cluster, req.Id)
  29. if errors.Is(result.Error, gorm.ErrRecordNotFound) {
  30. return nil, errors.New("cluster does not exist")
  31. }
  32. utils.Convert(req, &cluster)
  33. // 获取集群经纬度
  34. location, err := GeoMap(req.RegionName)
  35. if err != nil {
  36. return nil, err
  37. }
  38. cluster.Location = location
  39. l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster)
  40. // 更新资源价格表
  41. clusterId, err := strconv.ParseInt(req.Id, 10, 64)
  42. if err != nil {
  43. return nil, err
  44. }
  45. resourceCost := &types.ResourceCost{
  46. ResourceID: clusterId,
  47. Price: req.Price,
  48. ResourceType: constants.CLUSTER,
  49. CostType: req.CostType,
  50. }
  51. dbResult := l.svcCtx.DbEngin.Clauses(clause.OnConflict{
  52. Columns: []clause.Column{{Name: "resource_id"}},
  53. DoUpdates: clause.AssignmentColumns([]string{"price", "cost_type"}),
  54. }).Create(&resourceCost)
  55. if dbResult.Error != nil {
  56. return nil, dbResult.Error
  57. }
  58. return
  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.