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.

commitgeneraltasklogic.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package cloud
  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/models"
  7. "sigs.k8s.io/yaml"
  8. "strings"
  9. "time"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  11. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type CommitGeneralTaskLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewCommitGeneralTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitGeneralTaskLogic {
  20. return &CommitGeneralTaskLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) error {
  27. var yamlStr []string
  28. for _, s := range req.ReqBody {
  29. j2, err := yaml.YAMLToJSON([]byte(s))
  30. if err != nil {
  31. logx.Errorf("Failed to convert yaml to JSON, err: %v", err)
  32. return err
  33. }
  34. yamlStr = append(yamlStr, string(j2))
  35. }
  36. result := strings.Join(yamlStr, ",")
  37. //TODO The namespace is fixed to ns-admin for the time being. Later, the namespace is obtained based on the user
  38. taskModel := models.Task{
  39. Status: constants.Saved,
  40. Name: req.Name,
  41. CommitTime: time.Now(),
  42. NsID: "ns-admin",
  43. YamlString: "[" + result + "]",
  44. }
  45. // Save the task data to the database
  46. tx := l.svcCtx.DbEngin.Create(&taskModel)
  47. if tx.Error != nil {
  48. return tx.Error
  49. }
  50. var clusterIds []int64
  51. l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id = ? and id in ?", req.AdapterId, req.ClusterIds).Scan(&clusterIds)
  52. if len(clusterIds) == 0 || clusterIds == nil {
  53. return errors.Errorf("the cluster does not match the drive resources. Check the data")
  54. }
  55. //保存数据到cloud表
  56. return nil
  57. }

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.