Search in sources :

Example 51 with InterProcessLock

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

the class VdcManager method enableIpsec.

private void enableIpsec() throws Exception {
    InterProcessLock lock = null;
    try {
        lock = coordinator.getCoordinatorClient().getSiteLocalLock("ipseclock");
        lock.acquire();
        log.info("Acquired the lock {}", "ipseclock");
        String preSharedKey = ipsecConfig.getPreSharedKeyFromZK();
        if (StringUtil.isBlank(preSharedKey)) {
            log.info("No pre shared key in zk, generate a new key");
            ipsecMgr.rotateKey(true);
        } else {
            log.info("First ipsec key found in zk. No need to regenerate it");
        }
    } finally {
        if (lock != null) {
            lock.release();
        }
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 52 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project nakadi by zalando.

the class TimelineSyncImpl method runLocked.

private void runLocked(final Runnable action) {
    try {
        Exception releaseException = null;
        final InterProcessLock lock = new InterProcessSemaphoreMutex(zooKeeperHolder.get(), ROOT_PATH + "/lock");
        lock.acquire();
        try {
            action.run();
        } finally {
            try {
                lock.release();
            } catch (final Exception ex) {
                LOG.error("Failed to release lock", ex);
                releaseException = ex;
            }
        }
        if (null != releaseException) {
            throw releaseException;
        }
    } catch (final RuntimeException ex) {
        throw ex;
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : InterProcessSemaphoreMutex(org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) TimeoutException(java.util.concurrent.TimeoutException) KeeperException(org.apache.zookeeper.KeeperException)

Example 53 with InterProcessLock

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

the class GarbageCollectionExecutorLoop method run.

@Override
public void run() {
    InterProcessLock lock = null;
    try {
        lock = getLockForGC();
        if (lock == null) {
            log.info("Can't get GC lock, wait for next run.");
            return;
        }
    } catch (Exception e) {
        log.warn("Failed to acquire ZK lock for GC", e);
        return;
    }
    long beginTime = System.currentTimeMillis();
    log.info("Begin to GC...");
    try {
        if (!preGC()) {
            // can't run GC now
            return;
        }
        int maxLevels = dependencyTracker.getLevels();
        for (int i = 0; i < maxLevels; i++) {
            log.info("Now processing level {}", i);
            List<Class<? extends DataObject>> list = new ArrayList(dependencyTracker.getTypesInLevel(i));
            Collections.shuffle(list);
            for (Class<? extends DataObject> clazz : list) {
                if (canRunGCOnClass(clazz)) {
                    GarbageCollectionRunnable gc = genGCTask(clazz);
                    futures.add(executorPool.submit(gc));
                }
            }
            waitTasksToComplete();
        }
    } finally {
        try {
            postGC();
        } finally {
            releaseLockForGC(lock);
            log.info("GC is finished, consume time: {} seconds", (System.currentTimeMillis() - beginTime) / 1000);
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) ExecutionException(java.util.concurrent.ExecutionException)

Example 54 with InterProcessLock

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

the class DbServiceImpl method getLock.

private InterProcessLock getLock(String name) throws Exception {
    InterProcessLock lock = null;
    while (true) {
        try {
            lock = _coordinator.getSiteLocalLock(name);
            lock.acquire();
            // got lock
            break;
        } catch (Exception e) {
            if (_coordinator.isConnected()) {
                throw e;
            }
        }
    }
    return lock;
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) IOException(java.io.IOException)

Example 55 with InterProcessLock

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

the class MigrationHandlerImpl method getLock.

private InterProcessLock getLock(String name) throws Exception {
    InterProcessLock lock = null;
    while (true) {
        try {
            lock = coordinator.getLock(name);
            lock.acquire();
            // got lock
            break;
        } catch (Exception e) {
            if (coordinator.isConnected()) {
                throw e;
            }
        }
    }
    return lock;
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) FatalCoordinatorException(com.emc.storageos.coordinator.exceptions.FatalCoordinatorException) FatalDatabaseException(com.emc.storageos.db.exceptions.FatalDatabaseException)

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