예제 #1
0
파일: util.go 프로젝트: skyrings/skyring
func LockCluster(ctxt string, cluster models.Cluster, operation string) (*lock.AppLock, error) {
	locks := make(map[uuid.UUID]string)
	locks[cluster.ClusterId] = fmt.Sprintf("%s - %s", operation, cluster.Name)
	appLock := lock.NewAppLock(locks)
	if err := GetApp().GetLockManager().AcquireLock(ctxt, *appLock); err != nil {
		return nil, err
	}
	return appLock, nil
}
예제 #2
0
파일: util.go 프로젝트: skyrings/skyring
func LockNodes(ctxt string, 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(ctxt, *appLock); err != nil {
		return nil, err
	}
	return appLock, nil
}
예제 #3
0
파일: util.go 프로젝트: skyrings/skyring
func lockNode(ctxt string, 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 {
			return nil, fmt.Errorf("Unable to create the UUID for locking for host: %s. error: %v", hostname, err)
		}
		nodeId = *id
	}
	locks[nodeId] = fmt.Sprintf("%s : %s", operation, hostname)
	appLock := lock.NewAppLock(locks)
	if err := GetApp().GetLockManager().AcquireLock(ctxt, *appLock); err != nil {
		return nil, err
	}
	return appLock, nil
}