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.

63 lines
1.4 KiB

  1. package topology
  2. import (
  3. "code.google.com/p/weed-fs/go/storage"
  4. _ "fmt"
  5. "strconv"
  6. )
  7. type DataNode struct {
  8. NodeImpl
  9. volumes map[storage.VolumeId]storage.VolumeInfo
  10. Ip string
  11. Port int
  12. PublicUrl string
  13. LastSeen int64 // unix time in seconds
  14. Dead bool
  15. }
  16. func NewDataNode(id string) *DataNode {
  17. s := &DataNode{}
  18. s.id = NodeId(id)
  19. s.nodeType = "DataNode"
  20. s.volumes = make(map[storage.VolumeId]storage.VolumeInfo)
  21. s.NodeImpl.value = s
  22. return s
  23. }
  24. func (dn *DataNode) AddOrUpdateVolume(v storage.VolumeInfo) {
  25. if _, ok := dn.volumes[v.Id]; !ok {
  26. dn.volumes[v.Id] = v
  27. dn.UpAdjustVolumeCountDelta(1)
  28. dn.UpAdjustActiveVolumeCountDelta(1)
  29. dn.UpAdjustMaxVolumeId(v.Id)
  30. } else {
  31. dn.volumes[v.Id] = v
  32. }
  33. }
  34. func (dn *DataNode) GetDataCenter() *DataCenter {
  35. return dn.Parent().Parent().(*NodeImpl).value.(*DataCenter)
  36. }
  37. func (dn *DataNode) GetTopology() *Topology {
  38. p := dn.Parent()
  39. for p.Parent() != nil {
  40. p = p.Parent()
  41. }
  42. t := p.(*Topology)
  43. return t
  44. }
  45. func (dn *DataNode) MatchLocation(ip string, port int) bool {
  46. return dn.Ip == ip && dn.Port == port
  47. }
  48. func (dn *DataNode) Url() string {
  49. return dn.Ip + ":" + strconv.Itoa(dn.Port)
  50. }
  51. func (dn *DataNode) ToMap() interface{} {
  52. ret := make(map[string]interface{})
  53. ret["Url"] = dn.Url()
  54. ret["Volumes"] = dn.GetVolumeCount()
  55. ret["Max"] = dn.GetMaxVolumeCount()
  56. ret["Free"] = dn.FreeSpace()
  57. ret["PublicUrl"] = dn.PublicUrl
  58. return ret
  59. }