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.

committasklogic.go 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package core
  2. import (
  3. "context"
  4. "github.com/ghodss/yaml"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/mqs"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/response"
  9. "strings"
  10. "time"
  11. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  12. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type CommitTaskLogic struct {
  16. logx.Logger
  17. ctx context.Context
  18. svcCtx *svc.ServiceContext
  19. }
  20. func NewCommitTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitTaskLogic {
  21. return &CommitTaskLogic{
  22. Logger: logx.WithContext(ctx),
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. }
  26. }
  27. func (l *CommitTaskLogic) CommitTask(req *types.CommitTaskReq) error {
  28. //req.YamlList转换为json
  29. var yamlStr []string
  30. for _, s := range req.YamlList {
  31. j2, err := yaml.YAMLToJSON([]byte(s))
  32. if err != nil {
  33. logx.Errorf("Failed to convert yaml to JSON, err: %v", err)
  34. return err
  35. }
  36. yamlStr = append(yamlStr, string(j2))
  37. }
  38. result := strings.Join(yamlStr, ",")
  39. taskModel := models.Task{
  40. Status: constants.Saved,
  41. Name: req.Name,
  42. CommitTime: time.Now(),
  43. NsID: req.NsID,
  44. YamlString: "[" + result + "]",
  45. }
  46. // 保存任务数据到数据库
  47. tx := l.svcCtx.DbEngin.Create(&taskModel)
  48. if tx.Error != nil {
  49. return tx.Error
  50. }
  51. task := response.TaskInfo{
  52. TaskId: taskModel.Id,
  53. MatchLabels: req.MatchLabels,
  54. NsID: req.NsID,
  55. Metadata: req.YamlList,
  56. Replicas: req.Replicas,
  57. }
  58. mqs.InsQueue.Beta.Add(&task)
  59. return nil
  60. }

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.