You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

  1. package topology
  2. import ()
  3. func (t *Topology) ToMap() interface{} {
  4. m := make(map[string]interface{})
  5. m["Max"] = t.GetMaxVolumeCount()
  6. m["Free"] = t.FreeSpace()
  7. var dcs []interface{}
  8. for _, c := range t.Children() {
  9. dc := c.(*DataCenter)
  10. dcs = append(dcs, dc.ToMap())
  11. }
  12. m["DataCenters"] = dcs
  13. var layouts []interface{}
  14. for _, layout := range t.replicaType2VolumeLayout {
  15. if layout != nil {
  16. layouts = append(layouts, layout.ToMap())
  17. }
  18. }
  19. m["layouts"] = layouts
  20. return m
  21. }
  22. func (t *Topology) ToVolumeMap() interface{} {
  23. m := make(map[string]interface{})
  24. m["Max"] = t.GetMaxVolumeCount()
  25. m["Free"] = t.FreeSpace()
  26. dcs := make(map[NodeId]interface{})
  27. for _, c := range t.Children() {
  28. dc := c.(*DataCenter)
  29. racks := make(map[NodeId]interface{})
  30. for _, r := range dc.Children() {
  31. rack := r.(*Rack)
  32. dataNodes := make(map[NodeId]interface{})
  33. for _, d := range rack.Children() {
  34. dn := d.(*DataNode)
  35. var volumes []interface{}
  36. for _, v := range dn.volumes {
  37. volumes = append(volumes, v)
  38. }
  39. dataNodes[d.Id()] = volumes
  40. }
  41. racks[r.Id()] = dataNodes
  42. }
  43. dcs[dc.Id()] = racks
  44. }
  45. m["DataCenters"] = dcs
  46. return m
  47. }