func (self *MetaDataNodeState) RegisterDataNode(addr string, blocks []BlockID) NodeID {
	name := strings.Replace(namesgenerator.GetRandomName(0), "_", "-", -1)
	nodeID := NodeID(name)
	self.HasBlocks(nodeID, blocks)

	self.mutex.Lock()
	defer self.mutex.Unlock()
	self.dataNodes[nodeID] = addr
	self.dataNodesUtilization[nodeID] = len(blocks)
	self.dataNodesLastSeen[nodeID] = time.Now()

	return nodeID
}
Ejemplo n.º 2
0
func (daemon *Daemon) generateNewName(id string) (string, error) {
	var name string
	for i := 1; i < 6; i++ {
		name = namesgenerator.GetRandomName(i)
		if name[0] != '/' {
			name = "/" + name
		}

		if _, err := daemon.containerGraph.Set(name, id); err != nil {
			if !graphdb.IsNonUniqueNameError(err) {
				return "", err
			}
			continue
		}
		return name, nil
	}

	name = "/" + utils.TruncateID(id)
	if _, err := daemon.containerGraph.Set(name, id); err != nil {
		return "", err
	}
	return name, nil
}