本文整理匯總了Golang中github.com/heketi/heketi/utils.GenUUID函數的典型用法代碼示例。如果您正苦於以下問題:Golang GenUUID函數的具體用法?Golang GenUUID怎麽用?Golang GenUUID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GenUUID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
zones, nodes, drives := 10, 100, 48
list := []*Device{}
index := 0
for z := 0; z < zones; z++ {
for n := 0; n < nodes; n++ {
nid := utils.GenUUID()[:4]
for d := 0; d < drives; d++ {
did := utils.GenUUID()[:4]
dev := &Device{
deviceid: did,
nodeid: nid,
zone: z,
}
list = append(list, dev)
index++
//s = append(s, fmt.Sprintf("d%v:n%v:z%v", utils.GenUUID()[:4], nid, z))
}
}
}
fmt.Println(list)
fmt.Println("-------")
t := NewTopology()
for _, d := range list {
t.Add(d)
}
l := t.Rebalance()
fmt.Println(l)
fmt.Println(len(l))
}
示例2: TestSimpleAllocatorAddRemoveDevice
func TestSimpleAllocatorAddRemoveDevice(t *testing.T) {
/*
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Setup database
app := NewTestApp(tmpfile)
defer app.Close()
*/
a := NewSimpleAllocator()
tests.Assert(t, a != nil)
cluster := createSampleClusterEntry()
node := createSampleNodeEntry()
node.Info.ClusterId = cluster.Info.Id
device := createSampleDeviceEntry(node.Info.Id, 10000)
tests.Assert(t, len(a.rings) == 0)
err := a.AddDevice(cluster, node, device)
tests.Assert(t, err == nil)
tests.Assert(t, len(a.rings) == 1)
tests.Assert(t, a.rings[cluster.Info.Id] != nil)
// Get the nodes from the ring
ch, _, errc := a.GetNodes(cluster.Info.Id, utils.GenUUID())
var devices int
for d := range ch {
devices++
tests.Assert(t, d == device.Info.Id)
}
err = <-errc
tests.Assert(t, devices == 1)
tests.Assert(t, err == nil)
// Now remove the device
err = a.RemoveDevice(cluster, node, device)
tests.Assert(t, err == nil)
tests.Assert(t, len(a.rings) == 1)
// Get the nodes from the ring
ch, _, errc = a.GetNodes(cluster.Info.Id, utils.GenUUID())
devices = 0
for d := range ch {
devices++
tests.Assert(t, false, d)
}
err = <-errc
tests.Assert(t, devices == 0)
tests.Assert(t, err == nil)
}
示例3: createSampleNodeEntry
func createSampleNodeEntry() *NodeEntry {
req := &NodeAddRequest{
ClusterId: "123",
Hostnames: HostAddresses{
Manage: []string{"manage" + utils.GenUUID()[:8]},
Storage: []string{"storage" + utils.GenUUID()[:8]},
},
Zone: 99,
}
return NewNodeEntryFromRequest(req)
}
示例4: NewBrick
func NewBrick(size uint64, db *GlusterFSDB) *Brick {
return &Brick{
Id: utils.GenUUID(),
Size: size,
db: db,
}
}
示例5: TestSimpleAllocatorGetDeviceList
func TestSimpleAllocatorGetDeviceList(t *testing.T) {
r := NewSimpleAllocatorRing()
tests.Assert(t, r != nil)
zones, nodes, drives := 1, 2, 4
// Create ring
for z := 0; z < zones; z++ {
// Generate nodes for this zone
for n := 0; n < nodes; n++ {
nid := utils.GenUUID()
// Generate drives for this node
for d := 0; d < drives; d++ {
did := utils.GenUUID()
// Setup simple device
dev := &SimpleDevice{
zone: z,
deviceId: did,
nodeId: nid,
}
r.Add(dev)
}
}
}
tests.Assert(t, r.balancedList == nil)
// Rebalance
r.Rebalance()
tests.Assert(t, r.balancedList != nil)
tests.Assert(t, len(r.balancedList) == zones*nodes*drives)
// Get a list for a brick with "00000" id
// It should return a list equal to balancedList
tests.Assert(t,
reflect.DeepEqual(r.GetDeviceList("0000000"), r.balancedList))
tests.Assert(t,
reflect.DeepEqual(r.GetDeviceList("0000001"), append(r.balancedList[1:], r.balancedList[0])))
// 14 is larger than 1*2*4, 8.. So the index is 14%8 = 6
tests.Assert(t,
reflect.DeepEqual(r.GetDeviceList("000000e"), append(r.balancedList[6:], r.balancedList[:6]...)))
}
示例6: TestSimpleAllocatorRingRebalance
func TestSimpleAllocatorRingRebalance(t *testing.T) {
r := NewSimpleAllocatorRing()
tests.Assert(t, r != nil)
zones, nodes, drives := 10, 100, 48
// Add 10*100*48 devices to the ring
for z := 0; z < zones; z++ {
// Generate nodes for this zone
for n := 0; n < nodes; n++ {
nid := utils.GenUUID()
// Generate drives for this node
for d := 0; d < drives; d++ {
did := utils.GenUUID()
// Setup simple device
dev := &SimpleDevice{
zone: z,
deviceId: did,
nodeId: nid,
}
r.Add(dev)
}
}
}
tests.Assert(t, r.balancedList == nil)
// Rebalance
r.Rebalance()
tests.Assert(t, r.balancedList != nil)
tests.Assert(t, len(r.balancedList) == zones*nodes*drives)
// Check balance
// 1. No zones should be next to eachother in the list
// 2. Every other element should not have the same node
for i := range r.balancedList[:len(r.balancedList)-1] {
tests.Assert(t, r.balancedList[i].zone != r.balancedList[i+1].zone)
}
for i := range r.balancedList[:len(r.balancedList)-2] {
tests.Assert(t, r.balancedList[i].nodeId != r.balancedList[i+2].nodeId)
}
}
示例7: NewVolumeEntryFromRequest
func NewVolumeEntryFromRequest(req *VolumeCreateRequest) *VolumeEntry {
godbc.Require(req != nil)
vol := NewVolumeEntry()
vol.Info.Id = utils.GenUUID()
vol.Info.Durability = req.Durability
vol.Info.Snapshot = req.Snapshot
vol.Info.Size = req.Size
// Set default durability values
durability := vol.Info.Durability.Type
switch {
case durability == DURABILITY_STRING_REPLICATE:
logger.Debug("[%v] Replica %v",
vol.Info.Id,
vol.Info.Durability.Replicate.Replica)
vol.Durability = &vol.Info.Durability.Replicate
case durability == DURABILITY_STRING_EC:
logger.Debug("[%v] EC %v + %v ",
vol.Info.Id,
vol.Info.Durability.Disperse.Data,
vol.Info.Durability.Disperse.Redundancy)
vol.Durability = &vol.Info.Durability.Disperse
case durability == DURABILITY_STRING_DISTRIBUTE_ONLY || durability == "":
logger.Debug("[%v] Distributed", vol.Info.Id, vol.Info.Durability.Replicate.Replica)
vol.Durability = NewNoneDurability()
default:
panic(fmt.Sprintf("BUG: Unknown type: %v\n", vol.Info.Durability))
}
// Set the default values accordingly
vol.Durability.SetDurability()
// Set default name
if req.Name == "" {
vol.Info.Name = "vol_" + vol.Info.Id
} else {
vol.Info.Name = req.Name
}
// Set default thinp factor
if vol.Info.Snapshot.Enable && vol.Info.Snapshot.Factor == 0 {
vol.Info.Snapshot.Factor = DEFAULT_THINP_SNAPSHOT_FACTOR
} else if !vol.Info.Snapshot.Enable {
vol.Info.Snapshot.Factor = 1
}
// If it is zero, then it will be assigned during volume creation
vol.Info.Clusters = req.Clusters
return vol
}
示例8: TestSimpleAllocatorEmpty
func TestSimpleAllocatorEmpty(t *testing.T) {
a := NewSimpleAllocator()
tests.Assert(t, a != nil)
err := a.RemoveDevice(createSampleClusterEntry(),
createSampleNodeEntry(),
createSampleDeviceEntry("aaa", 10))
tests.Assert(t, err == ErrNotFound)
err = a.RemoveCluster("aaa")
tests.Assert(t, err == ErrNotFound)
ch, _, errc := a.GetNodes(utils.GenUUID(), utils.GenUUID())
for d := range ch {
tests.Assert(t, false, d)
}
err = <-errc
tests.Assert(t, err == ErrNotFound)
}
示例9: NewNodeEntryFromRequest
func NewNodeEntryFromRequest(req *NodeAddRequest) *NodeEntry {
godbc.Require(req != nil)
node := NewNodeEntry()
node.Info.Id = utils.GenUUID()
node.Info.ClusterId = req.ClusterId
node.Info.Hostnames = req.Hostnames
node.Info.Zone = req.Zone
return node
}
示例10: NewDeviceEntryFromRequest
func NewDeviceEntryFromRequest(req *Device, nodeid string) *DeviceEntry {
godbc.Require(req != nil)
device := NewDeviceEntry()
device.Info.Id = utils.GenUUID()
device.Info.Name = req.Name
device.Info.Weight = req.Weight
device.NodeId = nodeid
return device
}
示例11: createSampleDeviceEntry
func createSampleDeviceEntry(nodeid string, disksize uint64) *DeviceEntry {
req := &DeviceAddRequest{}
req.NodeId = nodeid
req.Name = "/dev/" + utils.GenUUID()[:8]
req.Weight = 123
d := NewDeviceEntryFromRequest(req)
d.StorageSet(disksize)
return d
}
示例12: NewHandler
// Use to create a new asynchronous operation handler.
// Only use this function if you need to do every step by hand.
// It is recommended to use AsyncHttpRedirectFunc() instead
func (a *AsyncHttpManager) NewHandler() *AsyncHttpHandler {
handler := &AsyncHttpHandler{
manager: a,
id: utils.GenUUID(),
}
a.lock.Lock()
defer a.lock.Unlock()
a.handlers[handler.id] = handler
return handler
}
示例13: TestSimpleAllocatorInitFromDb
func TestSimpleAllocatorInitFromDb(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Setup database
app := NewTestApp(tmpfile)
defer app.Close()
// Create large cluster
err := setupSampleDbWithTopology(app,
1, // clusters
10, // nodes_per_cluster
20, // devices_per_node,
600*GB, // disksize)
)
tests.Assert(t, err == nil)
// Get the cluster list
var clusterId string
err = app.db.View(func(tx *bolt.Tx) error {
clusters, err := ClusterList(tx)
if err != nil {
return err
}
tests.Assert(t, len(clusters) == 1)
clusterId = clusters[0]
return nil
})
tests.Assert(t, err == nil)
// Create an allocator and initialize it from the DB
a := NewSimpleAllocatorFromDb(app.db)
tests.Assert(t, a != nil)
// Get the nodes from the ring
ch, _, errc := a.GetNodes(clusterId, utils.GenUUID())
var devices int
for d := range ch {
devices++
tests.Assert(t, d != "")
}
err = <-errc
tests.Assert(t, devices == 10*20)
tests.Assert(t, err == nil)
}
示例14: TestDeviceEntryNewBrickEntry
func TestDeviceEntryNewBrickEntry(t *testing.T) {
req := &DeviceAddRequest{}
req.NodeId = "abc"
req.Name = "/dev/" + utils.GenUUID()
req.Weight = 123
d := NewDeviceEntryFromRequest(req)
d.Info.Storage.Free = 900
d.Info.Storage.Total = 1000
d.Info.Storage.Used = 100
// Alignment
d.ExtentSize = 8
// Too large
brick := d.NewBrickEntry(1000000000, 1.5)
tests.Assert(t, brick == nil)
// --- Now check with a real value ---
// Check newly created brick
size := 201
tpsize := uint64(float32(size) * 1.5)
// Alignment
tpsize += d.ExtentSize - (tpsize % d.ExtentSize)
// Calculate metadatasize
metadatasize := d.poolMetadataSize(tpsize)
// Alignment
metadatasize += d.ExtentSize - (metadatasize % d.ExtentSize)
total := tpsize + metadatasize
brick = d.NewBrickEntry(200, 1.5)
tests.Assert(t, brick != nil)
tests.Assert(t, brick.TpSize == tpsize)
tests.Assert(t, brick.PoolMetadataSize == metadatasize, brick.PoolMetadataSize, metadatasize)
tests.Assert(t, brick.Info.Size == 200)
// Check it was substracted from device storage
tests.Assert(t, d.Info.Storage.Used == 100+total)
tests.Assert(t, d.Info.Storage.Free == 900-total)
tests.Assert(t, d.Info.Storage.Total == 1000)
}
示例15: TestNewDeviceEntryNewInfoResponseBadBrickIds
func TestNewDeviceEntryNewInfoResponseBadBrickIds(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create a device
req := &DeviceAddRequest{}
req.NodeId = "abc"
req.Name = "/dev/" + utils.GenUUID()
req.Weight = 123
// Add bad brick ids
d := NewDeviceEntryFromRequest(req)
d.Info.Storage.Free = 10
d.Info.Storage.Total = 100
d.Info.Storage.Used = 1000
d.BrickAdd("abc")
d.BrickAdd("def")
// Save element in database
err := app.db.Update(func(tx *bolt.Tx) error {
return d.Save(tx)
})
tests.Assert(t, err == nil)
var info *DeviceInfoResponse
err = app.db.View(func(tx *bolt.Tx) error {
device, err := NewDeviceEntryFromId(tx, d.Info.Id)
if err != nil {
return err
}
info, err = device.NewInfoResponse(tx)
if err != nil {
return err
}
return nil
})
tests.Assert(t, err == ErrNotFound)
}