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.

52 lines
1.2 KiB

  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 _, c := range t.collectionMap {
  14. for _, layout := range c.storageType2VolumeLayout {
  15. if layout != nil {
  16. tmp := layout.ToMap()
  17. tmp["collection"] = c.Name
  18. layouts = append(layouts, tmp)
  19. }
  20. }
  21. }
  22. m["layouts"] = layouts
  23. return m
  24. }
  25. func (t *Topology) ToVolumeMap() interface{} {
  26. m := make(map[string]interface{})
  27. m["Max"] = t.GetMaxVolumeCount()
  28. m["Free"] = t.FreeSpace()
  29. dcs := make(map[NodeId]interface{})
  30. for _, c := range t.Children() {
  31. dc := c.(*DataCenter)
  32. racks := make(map[NodeId]interface{})
  33. for _, r := range dc.Children() {
  34. rack := r.(*Rack)
  35. dataNodes := make(map[NodeId]interface{})
  36. for _, d := range rack.Children() {
  37. dn := d.(*DataNode)
  38. var volumes []interface{}
  39. for _, v := range dn.volumes {
  40. volumes = append(volumes, v)
  41. }
  42. dataNodes[d.Id()] = volumes
  43. }
  44. racks[r.Id()] = dataNodes
  45. }
  46. dcs[dc.Id()] = racks
  47. }
  48. m["DataCenters"] = dcs
  49. return m
  50. }