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.

54 lines
1.2 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 _, c := range t.collectionMap {
  15. for _, layout := range c.replicaType2VolumeLayout {
  16. if layout != nil {
  17. tmp := layout.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.volumes {
  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. }