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.

common.go 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package scheduler
  13. import (
  14. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/pkg/response"
  15. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/scheduler/algo"
  16. "gorm.io/gorm"
  17. "math/rand"
  18. "time"
  19. )
  20. type scheduleService interface {
  21. getNewStructForDb(task *response.TaskInfo, resource interface{}, participantId int64) (interface{}, error)
  22. pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Strategy, error)
  23. genTaskAndProviders(task *response.TaskInfo, dbEngin *gorm.DB) (*algo.Task, []*algo.Provider)
  24. }
  25. type providerParams struct {
  26. Disk_avail float64
  27. Mem_avail float64
  28. Cpu_avail float64
  29. Participant_id int64
  30. }
  31. // 求交集
  32. func intersect(slice1, slice2 []int64) []int64 {
  33. m := make(map[int64]int)
  34. nn := make([]int64, 0)
  35. for _, v := range slice1 {
  36. m[v]++
  37. }
  38. for _, v := range slice2 {
  39. times, _ := m[v]
  40. if times == 1 {
  41. nn = append(nn, v)
  42. }
  43. }
  44. return nn
  45. }
  46. func micsSlice(origin []int64, count int) []int64 {
  47. tmpOrigin := make([]int64, len(origin))
  48. copy(tmpOrigin, origin)
  49. //一定要seed
  50. rand.Seed(time.Now().Unix())
  51. rand.Shuffle(len(tmpOrigin), func(i int, j int) {
  52. tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i]
  53. })
  54. result := make([]int64, 0, count)
  55. for index, value := range tmpOrigin {
  56. if index == count {
  57. break
  58. }
  59. result = append(result, value)
  60. }
  61. return result
  62. }

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.