topology_map.go 1.3 KB

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