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.

55 lines
1.1 KiB

13 years ago
  1. package topology
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  4. )
  5. type DataCenter struct {
  6. NodeImpl
  7. }
  8. func NewDataCenter(id string) *DataCenter {
  9. dc := &DataCenter{}
  10. dc.id = NodeId(id)
  11. dc.nodeType = "DataCenter"
  12. dc.diskUsages = newDiskUsages()
  13. dc.children = make(map[NodeId]Node)
  14. dc.NodeImpl.value = dc
  15. return dc
  16. }
  17. func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
  18. for _, c := range dc.Children() {
  19. rack := c.(*Rack)
  20. if string(rack.Id()) == rackName {
  21. return rack
  22. }
  23. }
  24. rack := NewRack(rackName)
  25. dc.LinkChildNode(rack)
  26. return rack
  27. }
  28. func (dc *DataCenter) ToMap() interface{} {
  29. m := make(map[string]interface{})
  30. m["Id"] = dc.Id()
  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. DiskInfos: dc.diskUsages.ToDiskInfo(),
  43. }
  44. for _, c := range dc.Children() {
  45. rack := c.(*Rack)
  46. m.RackInfos = append(m.RackInfos, rack.ToRackInfo())
  47. }
  48. return m
  49. }