2012-08-24 05:33:37 +00:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2012-09-02 21:33:48 +00:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2012-08-28 08:04:39 +00:00
|
|
|
"pkg/storage"
|
2012-08-24 05:33:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Topology struct {
|
2012-09-02 21:33:48 +00:00
|
|
|
NodeImpl
|
2012-08-31 08:35:11 +00:00
|
|
|
}
|
2012-08-28 08:04:39 +00:00
|
|
|
|
2012-09-02 21:33:48 +00: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 09:43:43 +00:00
|
|
|
return ret, node, vid
|
2012-08-28 08:04:39 +00:00
|
|
|
}
|
2012-08-29 07:58:03 +00:00
|
|
|
|
2012-08-28 08:04:39 +00:00
|
|
|
func (t *Topology) nextVolumeId() storage.VolumeId {
|
2012-09-02 21:33:48 +00:00
|
|
|
vid := t.GetMaxVolumeId()
|
2012-08-29 08:37:40 +00:00
|
|
|
return vid.Next()
|
2012-08-28 08:04:39 +00:00
|
|
|
}
|