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.

dataLocality.go 1.4 kB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package strategy
  2. import (
  3. "errors"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  5. )
  6. type DataLocality struct {
  7. replicas int32
  8. dataDistribute *types.DataDistribute
  9. }
  10. func NewDataLocality(replicas int32, dataDistribute *types.DataDistribute) *DataLocality {
  11. return &DataLocality{dataDistribute: dataDistribute, replicas: replicas}
  12. }
  13. func (d *DataLocality) Schedule() ([]*AssignedCluster, error) {
  14. if d.replicas < 1 {
  15. return nil, errors.New("replicas must be greater than 0")
  16. }
  17. var results []*AssignedCluster
  18. clusterDataMap := make(map[string]int32, 0)
  19. for _, distribute := range d.dataDistribute.Model {
  20. for _, cluster := range distribute.Clusters {
  21. clusterDataMap[cluster.ClusterID]++
  22. }
  23. }
  24. for _, distribute := range d.dataDistribute.Image {
  25. for _, cluster := range distribute.Clusters {
  26. clusterDataMap[cluster.ClusterID]++
  27. }
  28. }
  29. for _, distribute := range d.dataDistribute.Code {
  30. for _, cluster := range distribute.Clusters {
  31. clusterDataMap[cluster.ClusterID]++
  32. }
  33. }
  34. for _, distribute := range d.dataDistribute.Dataset {
  35. for _, cluster := range distribute.Clusters {
  36. clusterDataMap[cluster.ClusterID]++
  37. }
  38. }
  39. if d.replicas == 1 {
  40. cluster := &AssignedCluster{Replicas: d.replicas}
  41. var largest int32
  42. for k, v := range clusterDataMap {
  43. if v > largest {
  44. largest = v
  45. cluster.ClusterId = k
  46. }
  47. }
  48. results = append(results, cluster)
  49. }
  50. return results, nil
  51. }

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.