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.

schedulecreatetasklogic.go 3.0 kB

11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package schedule
  2. import (
  3. "context"
  4. "fmt"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/strategy"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  8. "slices"
  9. "strconv"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type ScheduleCreateTaskLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewScheduleCreateTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleCreateTaskLogic {
  18. return &ScheduleCreateTaskLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *ScheduleCreateTaskLogic) ScheduleCreateTask(req *types.CreateTaskReq) (resp *types.CreateTaskResp, err error) {
  25. resp = &types.CreateTaskResp{}
  26. if len(req.Resources) == 0 && len(req.Clusters) == 0 && len(req.StaticWeight) == 0 {
  27. return nil, fmt.Errorf("must specify at least one resource")
  28. }
  29. if len(req.Clusters) != 0 {
  30. schedatas := generateScheduleResult(req.DataDistributes, req.Clusters)
  31. taskId := l.createTask()
  32. resp.ScheduleDatas = schedatas
  33. resp.TaskID = taskId
  34. return resp, nil
  35. }
  36. if len(req.StaticWeight) != 0 {
  37. strgy := strategy.NewStaticWeightStrategy(req.StaticWeight, 1)
  38. sche, err := strgy.Schedule()
  39. if err != nil {
  40. return nil, err
  41. }
  42. var clusters []string
  43. for _, c := range sche {
  44. if c.Replicas == 0 {
  45. continue
  46. }
  47. clusters = append(clusters, c.ClusterId)
  48. }
  49. schedatas := generateScheduleResult(req.DataDistributes, clusters)
  50. taskId := l.createTask()
  51. resp.ScheduleDatas = schedatas
  52. resp.TaskID = taskId
  53. return resp, nil
  54. }
  55. if len(req.Resources) != 0 {
  56. }
  57. return
  58. }
  59. func generateScheduleResult(distribute types.DataDistribute, clusters []string) []*types.ScheduleData {
  60. var schedatas []*types.ScheduleData
  61. for _, cluster := range clusters {
  62. id, _ := strconv.ParseInt(cluster, 10, 64)
  63. for _, dd := range distribute.Dataset {
  64. if slices.Contains(dd.Clusters, id) {
  65. data := &types.ScheduleData{
  66. DataType: "dataset",
  67. PackageID: dd.PackageID,
  68. ClusterIDs: dd.Clusters,
  69. }
  70. schedatas = append(schedatas, data)
  71. }
  72. }
  73. for _, dd := range distribute.Code {
  74. if slices.Contains(dd.Clusters, id) {
  75. data := &types.ScheduleData{
  76. DataType: "code",
  77. PackageID: dd.PackageID,
  78. ClusterIDs: dd.Clusters,
  79. }
  80. schedatas = append(schedatas, data)
  81. }
  82. }
  83. for _, dd := range distribute.Image {
  84. if slices.Contains(dd.Clusters, id) {
  85. data := &types.ScheduleData{
  86. DataType: "image",
  87. PackageID: dd.PackageID,
  88. ClusterIDs: dd.Clusters,
  89. }
  90. schedatas = append(schedatas, data)
  91. }
  92. }
  93. for _, dd := range distribute.Model {
  94. if slices.Contains(dd.Clusters, id) {
  95. data := &types.ScheduleData{
  96. DataType: "model",
  97. PackageID: dd.PackageID,
  98. ClusterIDs: dd.Clusters,
  99. }
  100. schedatas = append(schedatas, data)
  101. }
  102. }
  103. }
  104. return schedatas
  105. }
  106. func (l *ScheduleCreateTaskLogic) createTask() int64 {
  107. return 123456789
  108. }

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.