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.

99 lines
2.7 KiB

9 years ago
  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.GetMaxVolumeCount()
  6. m["MaxSsd"] = t.GetMaxSsdVolumeCount()
  7. m["Free"] = t.FreeSpace()
  8. var dcs []interface{}
  9. for _, c := range t.Children() {
  10. dc := c.(*DataCenter)
  11. dcs = append(dcs, dc.ToMap())
  12. }
  13. m["DataCenters"] = dcs
  14. var layouts []interface{}
  15. for _, col := range t.collectionMap.Items() {
  16. c := col.(*Collection)
  17. for _, layout := range c.storageType2VolumeLayout.Items() {
  18. if layout != nil {
  19. tmp := layout.(*VolumeLayout).ToMap()
  20. tmp["collection"] = c.Name
  21. layouts = append(layouts, tmp)
  22. }
  23. }
  24. }
  25. m["Layouts"] = layouts
  26. return m
  27. }
  28. func (t *Topology) ToVolumeMap() interface{} {
  29. m := make(map[string]interface{})
  30. m["Max"] = t.GetMaxVolumeCount()
  31. m["MaxSsd"] = t.GetMaxSsdVolumeCount()
  32. m["Free"] = t.FreeSpace()
  33. dcs := make(map[NodeId]interface{})
  34. for _, c := range t.Children() {
  35. dc := c.(*DataCenter)
  36. racks := make(map[NodeId]interface{})
  37. for _, r := range dc.Children() {
  38. rack := r.(*Rack)
  39. dataNodes := make(map[NodeId]interface{})
  40. for _, d := range rack.Children() {
  41. dn := d.(*DataNode)
  42. var volumes []interface{}
  43. for _, v := range dn.GetVolumes() {
  44. volumes = append(volumes, v)
  45. }
  46. dataNodes[d.Id()] = volumes
  47. }
  48. racks[r.Id()] = dataNodes
  49. }
  50. dcs[dc.Id()] = racks
  51. }
  52. m["DataCenters"] = dcs
  53. return m
  54. }
  55. func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocation) {
  56. for _, c := range t.Children() {
  57. dc := c.(*DataCenter)
  58. for _, r := range dc.Children() {
  59. rack := r.(*Rack)
  60. for _, d := range rack.Children() {
  61. dn := d.(*DataNode)
  62. volumeLocation := &master_pb.VolumeLocation{
  63. Url: dn.Url(),
  64. PublicUrl: dn.PublicUrl,
  65. }
  66. for _, v := range dn.GetVolumes() {
  67. volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(v.Id))
  68. }
  69. for _, s := range dn.GetEcShards() {
  70. volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(s.VolumeId))
  71. }
  72. volumeLocations = append(volumeLocations, volumeLocation)
  73. }
  74. }
  75. }
  76. return
  77. }
  78. func (t *Topology) ToTopologyInfo() *master_pb.TopologyInfo {
  79. m := &master_pb.TopologyInfo{
  80. Id: string(t.Id()),
  81. VolumeCount: uint64(t.GetVolumeCount()),
  82. MaxVolumeCount: uint64(t.GetMaxVolumeCount()),
  83. MaxSsdVolumeCount: uint64(t.GetMaxSsdVolumeCount()),
  84. FreeVolumeCount: uint64(t.FreeSpace()),
  85. ActiveVolumeCount: uint64(t.GetActiveVolumeCount()),
  86. RemoteVolumeCount: uint64(t.GetRemoteVolumeCount()),
  87. SsdVolumeCount: uint64(t.GetSsdVolumeCount()),
  88. }
  89. for _, c := range t.Children() {
  90. dc := c.(*DataCenter)
  91. m.DataCenterInfos = append(m.DataCenterInfos, dc.ToDataCenterInfo())
  92. }
  93. return m
  94. }