topology_map.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package topology
  2. import "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  3. func (t *Topology) ToMap() interface{} {
  4. m := make(map[string]interface{})
  5. m["Max"] = t.diskUsages.GetMaxVolumeCount()
  6. m["Free"] = t.diskUsages.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 _, col := range t.collectionMap.Items() {
  15. c := col.(*Collection)
  16. for _, layout := range c.storageType2VolumeLayout.Items() {
  17. if layout != nil {
  18. tmp := layout.(*VolumeLayout).ToMap()
  19. tmp["collection"] = c.Name
  20. layouts = append(layouts, tmp)
  21. }
  22. }
  23. }
  24. m["Layouts"] = layouts
  25. return m
  26. }
  27. func (t *Topology) ToVolumeMap() interface{} {
  28. m := make(map[string]interface{})
  29. m["Max"] = t.diskUsages.GetMaxVolumeCount()
  30. m["Free"] = t.diskUsages.FreeSpace()
  31. dcs := make(map[NodeId]interface{})
  32. for _, c := range t.Children() {
  33. dc := c.(*DataCenter)
  34. racks := make(map[NodeId]interface{})
  35. for _, r := range dc.Children() {
  36. rack := r.(*Rack)
  37. dataNodes := make(map[NodeId]interface{})
  38. for _, d := range rack.Children() {
  39. dn := d.(*DataNode)
  40. var volumes []interface{}
  41. for _, v := range dn.GetVolumes() {
  42. volumes = append(volumes, v)
  43. }
  44. dataNodes[d.Id()] = volumes
  45. }
  46. racks[r.Id()] = dataNodes
  47. }
  48. dcs[dc.Id()] = racks
  49. }
  50. m["DataCenters"] = dcs
  51. return m
  52. }
  53. func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocation) {
  54. for _, c := range t.Children() {
  55. dc := c.(*DataCenter)
  56. for _, r := range dc.Children() {
  57. rack := r.(*Rack)
  58. for _, d := range rack.Children() {
  59. dn := d.(*DataNode)
  60. volumeLocation := &master_pb.VolumeLocation{
  61. Url: dn.Url(),
  62. PublicUrl: dn.PublicUrl,
  63. }
  64. for _, v := range dn.GetVolumes() {
  65. volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(v.Id))
  66. }
  67. for _, s := range dn.GetEcShards() {
  68. volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(s.VolumeId))
  69. }
  70. volumeLocations = append(volumeLocations, volumeLocation)
  71. }
  72. }
  73. }
  74. return
  75. }
  76. func (t *Topology) ToTopologyInfo() *master_pb.TopologyInfo {
  77. m := &master_pb.TopologyInfo{
  78. Id: string(t.Id()),
  79. DiskInfos: t.diskUsages.ToDiskInfo(),
  80. }
  81. for _, c := range t.Children() {
  82. dc := c.(*DataCenter)
  83. m.DataCenterInfos = append(m.DataCenterInfos, dc.ToDataCenterInfo())
  84. }
  85. return m
  86. }