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.

61 lines
1.5 KiB

13 years ago
  1. package topology
  2. import "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  3. type DataCenter struct {
  4. NodeImpl
  5. }
  6. func NewDataCenter(id string) *DataCenter {
  7. dc := &DataCenter{}
  8. dc.id = NodeId(id)
  9. dc.nodeType = "DataCenter"
  10. dc.children = make(map[NodeId]Node)
  11. dc.NodeImpl.value = dc
  12. return dc
  13. }
  14. func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
  15. for _, c := range dc.Children() {
  16. rack := c.(*Rack)
  17. if string(rack.Id()) == rackName {
  18. return rack
  19. }
  20. }
  21. rack := NewRack(rackName)
  22. dc.LinkChildNode(rack)
  23. return rack
  24. }
  25. func (dc *DataCenter) ToMap() interface{} {
  26. m := make(map[string]interface{})
  27. m["Id"] = dc.Id()
  28. m["Max"] = dc.GetMaxVolumeCount()
  29. m["MaxSsd"] = dc.GetMaxSsdVolumeCount()
  30. m["Free"] = dc.FreeSpace()
  31. var racks []interface{}
  32. for _, c := range dc.Children() {
  33. rack := c.(*Rack)
  34. racks = append(racks, rack.ToMap())
  35. }
  36. m["Racks"] = racks
  37. return m
  38. }
  39. func (dc *DataCenter) ToDataCenterInfo() *master_pb.DataCenterInfo {
  40. m := &master_pb.DataCenterInfo{
  41. Id: string(dc.Id()),
  42. VolumeCount: uint64(dc.GetVolumeCount()),
  43. MaxVolumeCount: uint64(dc.GetMaxVolumeCount()),
  44. MaxSsdVolumeCount: uint64(dc.GetMaxSsdVolumeCount()),
  45. SsdVolumeCount: uint64(dc.GetSsdVolumeCount()),
  46. FreeVolumeCount: uint64(dc.FreeSpace()),
  47. ActiveVolumeCount: uint64(dc.GetActiveVolumeCount()),
  48. RemoteVolumeCount: uint64(dc.GetRemoteVolumeCount()),
  49. }
  50. for _, c := range dc.Children() {
  51. rack := c.(*Rack)
  52. m.RackInfos = append(m.RackInfos, rack.ToRackInfo())
  53. }
  54. return m
  55. }