use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder in project genius by opendaylight.
the class LockManagerTest method testTryLock.
@Test
public // tryLock() RPC will retry only specific number of times, and it will only return after that
void testTryLock() throws InterruptedException, ExecutionException, TimeoutException {
String uniqueId = lockManagerUtils.getBladeId() + ":2";
logCaptureRule.expectError("Failed to get lock testTryLock owner " + uniqueId + " after 3 retries");
TryLockInput lockInput = new TryLockInputBuilder().setLockName("testTryLock").setTime(3L).setTimeUnit(TimeUnits.Seconds).build();
assertVoidRpcSuccess(lockManager.tryLock(lockInput));
// The second acquireLock request will retry for 3 seconds
// and since the first lock is not unlocked, the request will fail.
lockInput = new TryLockInputBuilder().setLockName("testTryLock").setTime(3000L).setTimeUnit(TimeUnits.Milliseconds).build();
assertRpcErrorWithoutCausesOrMessages(lockManager.tryLock(lockInput));
// Try to unlock the key in a separate thread before retry expires, and see
// if lock gets acquired.
runUnlockTimerTask("testTryLock", 2000);
lockInput = new TryLockInputBuilder().setLockName("testTryLock").setTime(4000000L).setTimeUnit(TimeUnits.Microseconds).build();
assertVoidRpcSuccess(lockManager.tryLock(lockInput));
}
Aggregations