Search in sources :

Example 1 with LockManagerService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService in project netvirt by opendaylight.

the class VpnUtil method lockSubnet.

public static void lockSubnet(LockManagerService lockManager, String subnetId) {
    TryLockInput input = new TryLockInputBuilder().setLockName(subnetId).setTime(3000L).setTimeUnit(TimeUnits.Milliseconds).build();
    Future<RpcResult<Void>> result = lockManager.tryLock(input);
    try {
        if (result != null && result.get().isSuccessful()) {
            LOG.debug("lockSubnet: Acquired lock for {}", subnetId);
        } else {
            LOG.error("Unable to get lock for subnet {}", subnetId);
            throw new RuntimeException("Unable to get lock for subnet " + subnetId);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Unable to get lock for subnet {}", subnetId, e);
        throw new RuntimeException("Unable to get lock for subnet " + subnetId, e);
    }
}
Also used : TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with LockManagerService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService in project genius by opendaylight.

the class IdUtils method unlock.

public void unlock(LockManagerService lockManager, String poolName) {
    UnlockInput input = new UnlockInputBuilder().setLockName(poolName).build();
    Future<RpcResult<Void>> result = lockManager.unlock(input);
    try {
        if (result != null && result.get().isSuccessful()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unlocked {}", poolName);
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unable to unlock pool {}", poolName);
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Unable to unlock for pool {}", poolName, e);
        throw new RuntimeException(String.format("Unable to unlock pool %s", poolName), e);
    }
}
Also used : UnlockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UnlockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with LockManagerService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService in project netvirt by opendaylight.

the class VpnUtil method unlockSubnet.

// We store the cause, which is what we really care about
@SuppressWarnings("checkstyle:AvoidHidingCauseException")
public static void unlockSubnet(LockManagerService lockManager, String subnetId) {
    UnlockInput input = new UnlockInputBuilder().setLockName(subnetId).build();
    Future<RpcResult<Void>> result = lockManager.unlock(input);
    try {
        if (result != null && result.get().isSuccessful()) {
            LOG.debug("unlockSubnet: Unlocked {}", subnetId);
        } else {
            LOG.debug("unlockSubnet: Unable to unlock subnet {}", subnetId);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("unlockSubnet: Unable to unlock subnet {}", subnetId);
        throw new RuntimeException(String.format("Unable to unlock subnetId %s", subnetId), e.getCause());
    }
}
Also used : UnlockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UnlockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with LockManagerService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService in project genius by opendaylight.

the class IdUtils method lock.

public void lock(LockManagerService lockManager, String poolName) throws IdManagerException {
    LockInput input = new LockInputBuilder().setLockName(poolName).build();
    Future<RpcResult<Void>> result = lockManager.lock(input);
    try {
        if (result != null && result.get().isSuccessful()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Acquired lock {}", poolName);
            }
        } else {
            throw new IdManagerException(String.format("Unable to getLock for pool %s", poolName));
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Unable to getLock for pool {}", poolName, e);
        throw new RuntimeException(String.format("Unable to getLock for pool %s", poolName), e);
    }
}
Also used : LockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) LockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 UnlockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInput)2 UnlockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInputBuilder)2 LockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput)1 LockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder)1 TryLockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput)1 TryLockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder)1