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.

94 lines
2.5 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["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 _, 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.GetMaxVolumeCount()
  30. m["Free"] = t.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. VolumeCount: uint64(t.GetVolumeCount()),
  80. MaxVolumeCount: uint64(t.GetMaxVolumeCount()),
  81. FreeVolumeCount: uint64(t.FreeSpace()),
  82. ActiveVolumeCount: uint64(t.GetActiveVolumeCount()),
  83. }
  84. for _, c := range t.Children() {
  85. dc := c.(*DataCenter)
  86. m.DataCenterInfos = append(m.DataCenterInfos, dc.ToDataCenterInfo())
  87. }
  88. return m
  89. }