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.

staticWeight.go 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package strategy
  2. import (
  3. "errors"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/algorithm/weightDistributing"
  5. )
  6. type StaticWeightStrategy struct {
  7. staticWeightMap map[string]int32
  8. replicas int32
  9. }
  10. func NewStaticWeightStrategy(staticWeightMap map[string]int32, replicas int32) *StaticWeightStrategy {
  11. return &StaticWeightStrategy{staticWeightMap: staticWeightMap,
  12. replicas: replicas,
  13. }
  14. }
  15. func (s *StaticWeightStrategy) Schedule() ([]*AssignedCluster, error) {
  16. if s.replicas < 1 {
  17. return nil, errors.New("replicas must be greater than 0")
  18. }
  19. if len(s.staticWeightMap) == 0 || s.staticWeightMap == nil {
  20. return nil, errors.New("weight must be set")
  21. }
  22. weights := make([]*weightDistributing.Weight, 0)
  23. for k, v := range s.staticWeightMap {
  24. weight := &weightDistributing.Weight{
  25. Id: k,
  26. Weight: v,
  27. }
  28. weights = append(weights, weight)
  29. }
  30. weightDistributing.DistributeReplicas(weights, s.replicas)
  31. var results []*AssignedCluster
  32. for _, weight := range weights {
  33. cluster := &AssignedCluster{ClusterId: weight.Id, Replicas: weight.Replica}
  34. results = append(results, cluster)
  35. }
  36. return results, nil
  37. }

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.