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.

commonScheduler.go 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package scheduler
  2. import (
  3. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/algo"
  4. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
  5. "math/rand"
  6. "time"
  7. )
  8. type scheduleService interface {
  9. getNewStructForDb(task *types.TaskInfo, participantIds []int64) (interface{}, error)
  10. pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Task, error)
  11. }
  12. //func MatchLabels(dbEngin *gorm.DB, task *types.TaskInfo) ([]int64, error) {
  13. // var ids []int64
  14. // count := 0
  15. // for key := range task.MatchLabels {
  16. // var participantId []int64
  17. // dbEngin.Raw("select participant_id from sc_participant_label_info where `key` = ? and value = ?", key, task.MatchLabels[key]).Scan(&participantId)
  18. // if count == 0 {
  19. // ids = participantId
  20. // }
  21. // if len(participantId) == 0 || len(ids) == 0 {
  22. // return nil, nil
  23. // }
  24. // ids = intersect(ids, participantId)
  25. // count++
  26. // }
  27. // return micsSlice(ids, 1), nil
  28. //}
  29. // 求交集
  30. func intersect(slice1, slice2 []int64) []int64 {
  31. m := make(map[int64]int)
  32. nn := make([]int64, 0)
  33. for _, v := range slice1 {
  34. m[v]++
  35. }
  36. for _, v := range slice2 {
  37. times, _ := m[v]
  38. if times == 1 {
  39. nn = append(nn, v)
  40. }
  41. }
  42. return nn
  43. }
  44. func micsSlice(origin []int64, count int) []int64 {
  45. tmpOrigin := make([]int64, len(origin))
  46. copy(tmpOrigin, origin)
  47. //一定要seed
  48. rand.Seed(time.Now().Unix())
  49. rand.Shuffle(len(tmpOrigin), func(i int, j int) {
  50. tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i]
  51. })
  52. result := make([]int64, 0, count)
  53. for index, value := range tmpOrigin {
  54. if index == count {
  55. break
  56. }
  57. result = append(result, value)
  58. }
  59. return result
  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.