Search in sources :

Example 91 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class DrUtil method getDROperationLock.

/**
 * @param checkAllSitesOperations
 * @return DR operation lock only when successfully acquired lock and there's no ongoing DR operation, throw Exception otherwise
 */
public InterProcessLock getDROperationLock(boolean checkAllSitesOperations) {
    // Try to acquire lock, succeed or throw Exception
    InterProcessLock lock = coordinator.getLock(DR_OPERATION_LOCK);
    boolean acquired;
    try {
        acquired = lock.acquire(LOCK_WAIT_TIME_SEC, TimeUnit.SECONDS);
    } catch (Exception e) {
        try {
            lock.release();
        } catch (Exception ex) {
            log.error("Fail to release DR operation lock", ex);
        }
        throw APIException.internalServerErrors.failToAcquireDROperationLock();
    }
    if (!acquired) {
        throw APIException.internalServerErrors.failToAcquireDROperationLock();
    }
    // Has successfully acquired lock
    if (!checkAllSitesOperations) {
        return lock;
    }
    // Check if there's ongoing DR operation on any site, if there is, release lock and throw exception
    Site ongoingSite = null;
    List<Site> sites = listSites();
    for (Site site : sites) {
        if (site.getState().isDROperationOngoing()) {
            ongoingSite = site;
            break;
        }
    }
    if (ongoingSite != null) {
        try {
            lock.release();
        } catch (Exception e) {
            log.error("Fail to release DR operation lock", e);
        }
        throw APIException.internalServerErrors.concurrentDROperationNotAllowed(ongoingSite.getName(), ongoingSite.getState().toString());
    }
    return lock;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) IOException(java.io.IOException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException)

Example 92 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method loadInetAddressFromCoordinator.

/**
 * Try to look up the node in zk configuration - this is called ONLY if map does not have it.
 *
 * @param nodeId
 *            the node in the lookup, any node
 * @return DualInetAddress of the node
 */
public DualInetAddress loadInetAddressFromCoordinator(String nodeId) {
    DualInetAddress dualAddress = null;
    // grab the lock
    InterProcessLock lock = null;
    try {
        lock = getLock(NODE_DUALINETADDR_CONFIG + nodeId);
        lock.acquire();
        Configuration config = queryConfiguration(Constants.NODE_DUALINETADDR_CONFIG, nodeId);
        if (config != null) {
            dualAddress = parseInetAddressConfig(config);
        }
    } catch (Exception e) {
        log.warn("Unexpected exception during loadInetAddressFromCoordinator()", e);
    } finally {
        if (lock != null) {
            try {
                lock.release();
            } catch (Exception e) {
                log.warn("Unexpected exception unlocking loadInetAddressFromCoordinator()", e);
            }
        }
    }
    // Add it to the map
    if (dualAddress != null) {
        inetAddressLookupMap.put(nodeId, dualAddress);
    }
    return dualAddress;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 93 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class EncryptionProviderImpl method restoreKey.

public void restoreKey(SecretKey key) throws Exception {
    InterProcessLock lock = null;
    try {
        lock = _coordinator.getLock(CONFIG_KIND);
        lock.acquire();
        persistKey(key);
    } finally {
        if (lock != null) {
            lock.release();
        }
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 94 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class EncryptionProviderImpl method cacheKey.

/**
 * Reads existing encryption key from coordinator and caches it
 *
 * @throws Exception
 */
private synchronized void cacheKey() throws Exception {
    Configuration config = _coordinator.queryConfiguration(CONFIG_KIND, _encryptId);
    if (config != null) {
        readKey(config);
    } else {
        // key has not been generated
        InterProcessLock lock = null;
        try {
            lock = _coordinator.getLock(CONFIG_KIND);
            lock.acquire();
            config = _coordinator.queryConfiguration(CONFIG_KIND, _encryptId);
            if (config == null) {
                _logger.warn("Encryption key not found, initializing it");
                generateKey();
            } else {
                readKey(config);
            }
        } finally {
            if (lock != null) {
                lock.release();
            }
        }
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 95 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class BackupOps method updateRestoreStatus.

public void updateRestoreStatus(String backupName, boolean isLocal, BackupRestoreStatus.Status newStatus, String details, Map<String, Long> downloadSize, long increasedSize, boolean increaseCompletedNodeNumber, List<String> backupfileNames, boolean doLog, boolean doLock) {
    InterProcessLock lock = null;
    try {
        if (doLock) {
            lock = getLock(BackupConstants.RESTORE_STATUS_UPDATE_LOCK, -1, // -1= no timeout
            TimeUnit.MILLISECONDS);
            if (doLog) {
                log.info("get lock {}", BackupConstants.RESTORE_STATUS_UPDATE_LOCK);
            }
        }
        BackupRestoreStatus currentStatus = queryBackupRestoreStatus(backupName, isLocal);
        if (!canBeUpdated(newStatus, currentStatus)) {
            log.info("Can't update the status from {} to {}", currentStatus, newStatus);
            return;
        }
        currentStatus.setBackupName(backupName);
        if (newStatus != null) {
            currentStatus.setStatusWithDetails(newStatus, details);
        }
        if (downloadSize != null) {
            currentStatus.setSizeToDownload(downloadSize);
        }
        if (increasedSize > 0) {
            String localHostID = getLocalHostID();
            currentStatus.increaseDownloadedSize(localHostID, increasedSize);
        }
        if (increaseCompletedNodeNumber) {
            currentStatus.increaseNodeCompleted();
        }
        if (backupfileNames != null) {
            currentStatus.setBackupFileNames(backupfileNames);
        }
        updateBackupRestoreStatus(currentStatus, backupName);
        persistBackupRestoreStatus(currentStatus, isLocal, doLog);
        if (doLog) {
            log.info("Persist backup restore newStatus {} to zk successfully", currentStatus);
        }
    } finally {
        if (doLock) {
            if (doLog) {
                log.info("To release lock {}", BackupConstants.RESTORE_STATUS_UPDATE_LOCK);
            }
            releaseLock(lock);
        }
    }
}
Also used : BackupRestoreStatus(com.emc.vipr.model.sys.backup.BackupRestoreStatus) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Aggregations

InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)98 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)25 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)21 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 IOException (java.io.IOException)15 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 Configuration (com.emc.storageos.coordinator.common.Configuration)12 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)12 UnknownHostException (java.net.UnknownHostException)12 Site (com.emc.storageos.coordinator.client.model.Site)11 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)11 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)9 ArrayList (java.util.ArrayList)9 POST (javax.ws.rs.POST)9 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)8 Path (javax.ws.rs.Path)8 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)6