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.

60 lines
1.3 KiB

  1. package topology
  2. import (
  3. _ "fmt"
  4. "code.google.com/p/weed-fs/weed/storage"
  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) GetTopology() *Topology {
  35. p := dn.parent
  36. for p.Parent() != nil {
  37. p = p.Parent()
  38. }
  39. t := p.(*Topology)
  40. return t
  41. }
  42. func (dn *DataNode) MatchLocation(ip string, port int) bool {
  43. return dn.Ip == ip && dn.Port == port
  44. }
  45. func (dn *DataNode) Url() string {
  46. return dn.Ip + ":" + strconv.Itoa(dn.Port)
  47. }
  48. func (dn *DataNode) ToMap() interface{} {
  49. ret := make(map[string]interface{})
  50. ret["Url"] = dn.Url()
  51. ret["Volumes"] = dn.GetVolumeCount()
  52. ret["Max"] = dn.GetMaxVolumeCount()
  53. ret["Free"] = dn.FreeSpace()
  54. ret["PublicUrl"] = dn.PublicUrl
  55. return ret
  56. }