2012-08-24 03:56:09 +00:00
|
|
|
package topology
|
|
|
|
|
2012-08-28 08:04:39 +00:00
|
|
|
import (
|
|
|
|
"pkg/storage"
|
|
|
|
)
|
2012-08-24 03:56:09 +00:00
|
|
|
|
2012-08-24 06:35:30 +00:00
|
|
|
type DataCenterId string
|
2012-08-24 05:33:37 +00:00
|
|
|
type DataCenter struct {
|
|
|
|
Id DataCenterId
|
|
|
|
racks map[RackId]*Rack
|
|
|
|
ipRange IpRange
|
2012-08-28 08:04:39 +00:00
|
|
|
|
|
|
|
//transient
|
|
|
|
allocation StorageCapacity
|
|
|
|
topology *Topology
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DataCenter) CreateOneVolume(r int, vid storage.VolumeId) storage.VolumeId {
|
|
|
|
for _, rack := range d.racks {
|
|
|
|
freeSpace := rack.allocation.maxVolumeCount - rack.allocation.countVolumeCount
|
|
|
|
if r > freeSpace {
|
|
|
|
r -= freeSpace
|
|
|
|
} else {
|
|
|
|
rack.CreateOneVolume(r, vid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vid
|
|
|
|
}
|
|
|
|
func (d *DataCenter) AddVolume(rack *Rack, v *storage.VolumeInfo) {
|
|
|
|
d.allocation.countVolumeCount += 1
|
|
|
|
d.topology.AddVolume(d, v)
|
|
|
|
}
|
|
|
|
func (d *DataCenter) AddNode(rack *Rack, n *Node) {
|
|
|
|
d.allocation.countVolumeCount += len(n.volumes)
|
|
|
|
d.allocation.maxVolumeCount += n.maxVolumeCount
|
|
|
|
d.topology.AddNode(d, n)
|
|
|
|
}
|
|
|
|
func (d *DataCenter) RemoveNode(rack *Rack, n *Node) {
|
|
|
|
d.allocation.countVolumeCount -= len(n.volumes)
|
|
|
|
d.allocation.maxVolumeCount -= n.maxVolumeCount
|
|
|
|
d.topology.RemoveNode(d, n)
|
|
|
|
}
|
|
|
|
func (d *DataCenter) AddRack(rack *Rack) {
|
|
|
|
d.racks[rack.Id] = rack
|
|
|
|
d.allocation.countVolumeCount += rack.allocation.countVolumeCount
|
|
|
|
d.allocation.maxVolumeCount += rack.allocation.maxVolumeCount
|
|
|
|
d.topology.AddRack(d, rack)
|
|
|
|
}
|
|
|
|
func (d *DataCenter) RemoveRack(rack *Rack) {
|
|
|
|
delete(d.racks, rack.Id)
|
|
|
|
d.allocation.countVolumeCount -= rack.allocation.countVolumeCount
|
|
|
|
d.allocation.maxVolumeCount -= rack.allocation.maxVolumeCount
|
|
|
|
d.topology.AddRack(d, rack)
|
2012-08-24 05:33:37 +00:00
|
|
|
}
|