Chris Lu
12 years ago
7 changed files with 68 additions and 68 deletions
-
5weed-fs/src/cmd/weed/master.go
-
58weed-fs/src/pkg/topology/configuration.go
-
14weed-fs/src/pkg/topology/data_center.go
-
21weed-fs/src/pkg/topology/ip_range.go
-
2weed-fs/src/pkg/topology/node.go
-
10weed-fs/src/pkg/topology/rack.go
-
26weed-fs/src/pkg/topology/topology.go
@ -1,34 +1,56 @@ |
|||||
package topology |
package topology |
||||
|
|
||||
import ( |
import ( |
||||
"encoding/xml" |
|
||||
|
"encoding/xml" |
||||
) |
) |
||||
|
|
||||
|
type loc struct { |
||||
|
dcName string |
||||
|
rackName string |
||||
|
} |
||||
type rack struct { |
type rack struct { |
||||
Name string `xml:"name,attr"` |
|
||||
Ips []string `xml:"Ip"` |
|
||||
|
Name string `xml:"name,attr"` |
||||
|
Ips []string `xml:"Ip"` |
||||
} |
} |
||||
type dataCenter struct { |
type dataCenter struct { |
||||
Name string `xml:"name,attr"` |
|
||||
Racks []rack `xml:"Rack"` |
|
||||
|
Name string `xml:"name,attr"` |
||||
|
Racks []rack `xml:"Rack"` |
||||
} |
} |
||||
type topology struct { |
type topology struct { |
||||
DataCenters []dataCenter `xml:"DataCenter"` |
|
||||
|
DataCenters []dataCenter `xml:"DataCenter"` |
||||
|
} |
||||
|
type Configuration struct { |
||||
|
XMLName xml.Name `xml:"Configuration"` |
||||
|
Topo topology `xml:"Topology"` |
||||
|
ip2location map[string]loc |
||||
} |
} |
||||
type configuration struct { |
|
||||
XMLName xml.Name `xml:"Configuration"` |
|
||||
Topo topology `xml:"Topology"` |
|
||||
|
|
||||
|
func NewConfiguration(b []byte) (*Configuration, error) { |
||||
|
c := &Configuration{} |
||||
|
err := xml.Unmarshal(b, c) |
||||
|
c.ip2location = make(map[string]loc) |
||||
|
for _, dc := range c.Topo.DataCenters { |
||||
|
for _, rack := range dc.Racks { |
||||
|
for _, ip := range rack.Ips { |
||||
|
c.ip2location[ip] = loc{dcName: dc.Name, rackName: rack.Name} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return c, err |
||||
} |
} |
||||
|
|
||||
func NewConfiguration(b []byte) (*configuration, error){ |
|
||||
c := &configuration{} |
|
||||
err := xml.Unmarshal(b, c) |
|
||||
return c, err |
|
||||
|
func (c *Configuration) String() string { |
||||
|
if b, e := xml.MarshalIndent(c, " ", " "); e == nil { |
||||
|
return string(b) |
||||
|
} |
||||
|
return "" |
||||
} |
} |
||||
|
|
||||
func (c *configuration) String() string{ |
|
||||
if b, e := xml.MarshalIndent(c, " ", " "); e==nil { |
|
||||
return string(b) |
|
||||
} |
|
||||
return "" |
|
||||
|
func (c *Configuration) Locate(ip string) (dc string, rack string) { |
||||
|
if c != nil && c.ip2location != nil { |
||||
|
if loc, ok := c.ip2location[ip]; ok { |
||||
|
return loc.dcName, loc.rackName |
||||
|
} |
||||
|
} |
||||
|
return "DefaultDataCenter", "DefaultRack" |
||||
} |
} |
@ -1,21 +0,0 @@ |
|||||
package topology |
|
||||
|
|
||||
import ( |
|
||||
|
|
||||
) |
|
||||
|
|
||||
|
|
||||
type IpRange struct { |
|
||||
inclusives []string |
|
||||
exclusives []string |
|
||||
} |
|
||||
|
|
||||
func (r *IpRange) Match(ip string) bool { |
|
||||
// TODO
|
|
||||
// for _, exc := range r.exclusives {
|
|
||||
// if exc
|
|
||||
// }
|
|
||||
// for _, inc := range r.inclusives {
|
|
||||
// }
|
|
||||
return true |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue