|
|
@ -1,7 +1,7 @@ |
|
|
|
package topology |
|
|
|
|
|
|
|
import ( |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
|
|
|
|
type Rack struct { |
|
|
@ -11,43 +11,44 @@ type Rack struct { |
|
|
|
|
|
|
|
func NewRack(id string) *Rack { |
|
|
|
r := &Rack{} |
|
|
|
r.id = NodeId(id) |
|
|
|
r.nodeType = "Rack" |
|
|
|
r.children = make(map[NodeId]Node) |
|
|
|
r.id = NodeId(id) |
|
|
|
r.nodeType = "Rack" |
|
|
|
r.children = make(map[NodeId]Node) |
|
|
|
return r |
|
|
|
} |
|
|
|
|
|
|
|
func (r *Rack) MatchLocationRange(ip string) bool{ |
|
|
|
if r.ipRange == nil { |
|
|
|
return true |
|
|
|
} |
|
|
|
return r.ipRange.Match(ip) |
|
|
|
func (r *Rack) MatchLocationRange(ip string) bool { |
|
|
|
if r.ipRange == nil { |
|
|
|
return true |
|
|
|
} |
|
|
|
return r.ipRange.Match(ip) |
|
|
|
} |
|
|
|
|
|
|
|
func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolumeCount int) *DataNode{ |
|
|
|
for _, c := range r.Children() { |
|
|
|
dn := c.(*DataNode) |
|
|
|
if dn.MatchLocation(ip,port) { |
|
|
|
return dn |
|
|
|
} |
|
|
|
} |
|
|
|
dn := NewDataNode("DataNode"+ip+":"+strconv.Itoa(port)) |
|
|
|
dn.Ip = ip |
|
|
|
dn.Port = port |
|
|
|
dn.PublicUrl = publicUrl |
|
|
|
dn.maxVolumeCount = maxVolumeCount |
|
|
|
r.LinkChildNode(dn) |
|
|
|
return dn |
|
|
|
func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolumeCount int) *DataNode { |
|
|
|
for _, c := range r.Children() { |
|
|
|
dn := c.(*DataNode) |
|
|
|
if dn.MatchLocation(ip, port) { |
|
|
|
dn.NodeImpl.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount) |
|
|
|
return dn |
|
|
|
} |
|
|
|
} |
|
|
|
dn := NewDataNode("DataNode" + ip + ":" + strconv.Itoa(port)) |
|
|
|
dn.Ip = ip |
|
|
|
dn.Port = port |
|
|
|
dn.PublicUrl = publicUrl |
|
|
|
dn.maxVolumeCount = maxVolumeCount |
|
|
|
r.LinkChildNode(dn) |
|
|
|
return dn |
|
|
|
} |
|
|
|
|
|
|
|
func (rack *Rack) ToMap() interface{}{ |
|
|
|
m := make(map[string]interface{}) |
|
|
|
m["Free"] = rack.FreeSpace() |
|
|
|
var dns []interface{} |
|
|
|
for _, c := range rack.Children() { |
|
|
|
dn := c.(*DataNode) |
|
|
|
dns = append(dns, dn.ToMap()) |
|
|
|
} |
|
|
|
m["DataNodes"] = dns |
|
|
|
return m |
|
|
|
func (rack *Rack) ToMap() interface{} { |
|
|
|
m := make(map[string]interface{}) |
|
|
|
m["Free"] = rack.FreeSpace() |
|
|
|
var dns []interface{} |
|
|
|
for _, c := range rack.Children() { |
|
|
|
dn := c.(*DataNode) |
|
|
|
dns = append(dns, dn.ToMap()) |
|
|
|
} |
|
|
|
m["DataNodes"] = dns |
|
|
|
return m |
|
|
|
} |