Ejemplo n.º 1
0
func lockNodes(nodes models.Nodes, operation string) (*lock.AppLock, error) {
	locks := make(map[uuid.UUID]string)
	for _, node := range nodes {
		locks[node.NodeId] = fmt.Sprintf("%s : %s", operation, node.Hostname)
	}
	appLock := lock.NewAppLock(locks)
	if err := GetApp().GetLockManager().AcquireLock(*appLock); err != nil {
		return nil, err
	}
	return appLock, nil
}
Ejemplo n.º 2
0
func lockNode(nodeId uuid.UUID, hostname string, operation string) (*lock.AppLock, error) {
	//lock the node
	locks := make(map[uuid.UUID]string)
	if nodeId.IsZero() {
		//Generate temporary UUID from hostname for the node
		//for locking as the UUID is not available at this point
		id, err := uuid.Parse(util.Md5FromString(hostname))
		if err != nil {
			logger.Get().Error(fmt.Sprintf("Unable to create the UUID for locking for host: %s:", hostname), err)
			return nil, err
		}
		nodeId = *id
	}
	locks[nodeId] = fmt.Sprintf("%s : %s", operation, hostname)
	appLock := lock.NewAppLock(locks)
	if err := GetApp().GetLockManager().AcquireLock(*appLock); err != nil {
		return nil, err
	}
	return appLock, nil
}