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.

schedulesubmitlogic.go 3.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package schedule
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/schedulers"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/schedulers/option"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  9. "strconv"
  10. "strings"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type ScheduleSubmitLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewScheduleSubmitLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleSubmitLogic {
  19. return &ScheduleSubmitLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *ScheduleSubmitLogic) ScheduleSubmit(req *types.ScheduleReq) (resp *types.ScheduleResp, err error) {
  26. resp = &types.ScheduleResp{}
  27. opt := &option.AiOption{
  28. AdapterId: req.AiOption.AdapterId,
  29. TaskName: req.AiOption.TaskName,
  30. ResourceType: req.AiOption.ResourceType,
  31. Replica: req.AiOption.Replica,
  32. ComputeCard: req.AiOption.ComputeCard,
  33. Tops: req.AiOption.Tops,
  34. TaskType: req.AiOption.TaskType,
  35. DatasetsName: req.AiOption.Datasets,
  36. AlgorithmName: req.AiOption.Algorithm,
  37. StrategyName: req.AiOption.Strategy,
  38. ClusterToStaticWeight: req.AiOption.StaticWeightMap,
  39. Params: req.AiOption.Params,
  40. Envs: req.AiOption.Envs,
  41. Cmd: req.AiOption.Cmd,
  42. ClusterIds: req.AiOption.AiClusterIds,
  43. }
  44. aiSchdl, err := schedulers.NewAiScheduler(l.ctx, "", l.svcCtx.Scheduler, opt)
  45. if err != nil {
  46. return nil, err
  47. }
  48. results, err := l.svcCtx.Scheduler.AssignAndSchedule(aiSchdl)
  49. if err != nil {
  50. return nil, err
  51. }
  52. switch opt.GetOptionType() {
  53. case option.AI:
  54. rs := (results).([]*schedulers.AiResult)
  55. var synergystatus int64
  56. if len(rs) > 1 {
  57. synergystatus = 1
  58. }
  59. strategyCode, err := l.svcCtx.Scheduler.AiStorages.GetStrategyCode(req.AiOption.Strategy)
  60. id, err := l.svcCtx.Scheduler.AiStorages.SaveTask(req.AiOption.TaskName, strategyCode, synergystatus)
  61. if err != nil {
  62. return nil, err
  63. }
  64. for _, r := range rs {
  65. scheResult := &types.ScheduleResult{}
  66. scheResult.ClusterId = r.ClusterId
  67. scheResult.TaskId = strconv.FormatInt(id, 10)
  68. scheResult.JobId = r.JobId
  69. scheResult.Strategy = r.Strategy
  70. scheResult.Card = strings.ToUpper(r.Card)
  71. scheResult.Replica = r.Replica
  72. scheResult.Msg = r.Msg
  73. opt.ComputeCard = strings.ToUpper(r.Card)
  74. clusterName, _ := l.svcCtx.Scheduler.AiStorages.GetClusterNameById(r.ClusterId)
  75. err := l.svcCtx.Scheduler.AiStorages.SaveAiTask(id, opt, r.ClusterId, clusterName, r.JobId, constants.Saved, r.Msg)
  76. if err != nil {
  77. return nil, err
  78. }
  79. resp.Results = append(resp.Results, scheResult)
  80. }
  81. }
  82. return resp, nil
  83. }

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.