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.

scheduler.go 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package scheduler
  2. import (
  3. "encoding/json"
  4. "github.com/pkg/errors"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
  7. "gorm.io/gorm"
  8. )
  9. type scheduler struct {
  10. task *types.TaskInfo
  11. participantIds []int64
  12. scheduleService scheduleService
  13. }
  14. func NewScheduler(scheduleService scheduleService, val string) (*scheduler, error) {
  15. var task *types.TaskInfo
  16. err := json.Unmarshal([]byte(val), &task)
  17. if err != nil {
  18. return nil, errors.New("create scheduler failed : " + err.Error())
  19. }
  20. return &scheduler{task: task, scheduleService: scheduleService}, nil
  21. }
  22. func (s scheduler) MatchLabels(dbEngin *gorm.DB) {
  23. //if len(task.MatchLabels) != 0 {
  24. // participantId, err := scheduler.MatchLabels(l.svcCtx.DbEngin, task)
  25. // if err != nil {
  26. // return err
  27. // }
  28. //}
  29. var ids []int64
  30. count := 0
  31. for key := range s.task.MatchLabels {
  32. var participantId []int64
  33. dbEngin.Raw("select participant_id from sc_participant_label_info where `key` = ? and value = ?", key, s.task.MatchLabels[key]).Scan(&participantId)
  34. if count == 0 {
  35. ids = participantId
  36. }
  37. //if len(participantId) == 0 || len(ids) == 0 {
  38. // return nil, nil
  39. //}
  40. ids = intersect(ids, participantId)
  41. count++
  42. }
  43. s.participantIds = micsSlice(ids, 1)
  44. }
  45. func (s scheduler) AssignAndSchedule() {
  46. }
  47. func (s scheduler) SaveToDb(dbEngin *gorm.DB) error {
  48. if len(s.participantIds) == 0 {
  49. return errors.New("participantIds 为空")
  50. }
  51. structForDb, err := s.scheduleService.getNewStructForDb(s.task, s.participantIds)
  52. if err != nil {
  53. return err
  54. }
  55. tx := dbEngin.Create(structForDb)
  56. if tx.Error != nil {
  57. logx.Error(tx.Error)
  58. return tx.Error
  59. }
  60. return nil
  61. }

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.