Search in sources :

Example 96 with InterProcessLock

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

the class BackupOps method deleteBackup.

/**
 * Delete backup file on all nodes
 *
 * @param backupTag
 *            The tag of the backup
 */
public void deleteBackup(String backupTag) {
    checkOnStandby();
    validateBackupName(backupTag);
    InterProcessLock lock = null;
    try {
        lock = getLock(BackupConstants.BACKUP_LOCK, BackupConstants.LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
        deleteBackupWithoutLock(backupTag, false);
    } finally {
        releaseLock(lock);
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 97 with InterProcessLock

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

the class BackupOps method createBackup.

/**
 * Create backup file on all nodes
 *
 * @param backupTag
 *            The tag of this backup
 * @param force
 *            Ignore the errors during the creation
 */
public void createBackup(String backupTag, boolean force) {
    checkOnStandby();
    if (backupTag == null) {
        backupTag = createBackupName();
    } else {
        validateBackupName(backupTag);
    }
    precheckForCreation(backupTag);
    InterProcessLock backupLock = null;
    InterProcessLock recoveryLock = null;
    try {
        backupLock = getLock(BackupConstants.BACKUP_LOCK, BackupConstants.LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
        recoveryLock = getLock(RecoveryConstants.RECOVERY_LOCK, BackupConstants.LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
        createBackupWithoutLock(backupTag, force);
    } finally {
        releaseLock(recoveryLock);
        releaseLock(backupLock);
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 98 with InterProcessLock

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

the class BackupOps method getLock.

public InterProcessLock getLock(String name, long time, TimeUnit unit) {
    InterProcessLock lock = null;
    log.info("Try to acquire lock: {}", name);
    try {
        lock = coordinatorClient.getLock(name);
        if (time >= 0) {
            boolean acquired = lock.acquire(time, unit);
            if (!acquired) {
                log.error("Unable to acquire lock: {}", name);
                if (name.equals(RecoveryConstants.RECOVERY_LOCK)) {
                    throw BackupException.fatals.unableToGetRecoveryLock(name);
                }
                throw BackupException.fatals.unableToGetLock(name);
            }
        } else {
            // no timeout
            lock.acquire();
        }
    } catch (Exception e) {
        log.error("Failed to acquire lock: {}", name);
        throw BackupException.fatals.failedToGetLock(name, e);
    }
    log.info("Got lock: {}", name);
    return lock;
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) URISyntaxException(java.net.URISyntaxException) CancellationException(java.util.concurrent.CancellationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) RetryableBackupException(com.emc.storageos.management.backup.exceptions.RetryableBackupException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) BackupException(com.emc.storageos.management.backup.exceptions.BackupException)

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