2012-08-24 13:33:37 +08:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2012-09-03 05:33:48 +08:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2012-08-28 16:04:39 +08:00
|
|
|
"pkg/storage"
|
2012-08-24 13:33:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Topology struct {
|
2012-09-03 05:33:48 +08:00
|
|
|
NodeImpl
|
2012-08-31 16:35:11 +08:00
|
|
|
}
|
2012-08-28 16:04:39 +08:00
|
|
|
|
2012-09-03 05:33:48 +08:00
|
|
|
func NewTopology(id string) *Topology {
|
|
|
|
t := &Topology{}
|
|
|
|
t.id = NodeId(id)
|
|
|
|
t.nodeType = "Topology"
|
|
|
|
t.children = make(map[NodeId]Node)
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
func (t *Topology) RandomlyReserveOneVolume() (bool, *Server, storage.VolumeId) {
|
|
|
|
vid := t.nextVolumeId()
|
|
|
|
ret, node := t.ReserveOneVolume(rand.Intn(t.FreeSpace()), vid)
|
|
|
|
fmt.Println("node.IsServer", node.IsServer())
|
2012-09-01 17:43:43 +08:00
|
|
|
return ret, node, vid
|
2012-08-28 16:04:39 +08:00
|
|
|
}
|
2012-08-29 15:58:03 +08:00
|
|
|
|
2012-08-28 16:04:39 +08:00
|
|
|
func (t *Topology) nextVolumeId() storage.VolumeId {
|
2012-09-03 05:33:48 +08:00
|
|
|
vid := t.GetMaxVolumeId()
|
2012-08-29 16:37:40 +08:00
|
|
|
return vid.Next()
|
2012-08-28 16:04:39 +08:00
|
|
|
}
|