use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries in project genius by opendaylight.
the class UpdateIdEntryJob method call.
@Override
public List<ListenableFuture<Void>> call() throws TransactionCommitFailedException {
String uniqueIdKey = idUtils.getUniqueKey(parentPoolName, idKey);
try {
txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
idUtils.updateChildPool(tx, parentPoolName, localPoolName);
if (!newIdValues.isEmpty()) {
IdEntries newIdEntry = idUtils.createIdEntries(idKey, newIdValues);
tx.merge(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey), newIdEntry);
} else {
tx.delete(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey));
}
}).get();
LOG.info("Updated id entry with idValues {}, idKey {}, pool {}", newIdValues, idKey, localPoolName);
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error updating id entry job", e);
} finally {
CountDownLatch latch = idUtils.getReleaseIdLatch(uniqueIdKey);
if (latch != null) {
latch.countDown();
}
// Once the id is written to DS, removing the id value from map.
idUtils.removeAllocatedIds(uniqueIdKey);
idUtils.unlock(lockManager, uniqueIdKey);
}
return Collections.emptyList();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries in project genius by opendaylight.
the class IdManager method releaseIdFromLocalPool.
private void releaseIdFromLocalPool(String parentPoolName, String localPoolName, String idKey) throws ReadFailedException, IdManagerException {
String idLatchKey = idUtils.getUniqueKey(parentPoolName, idKey);
LOG.debug("Releasing ID {} from pool {}", idKey, localPoolName);
CountDownLatch latch = idUtils.getReleaseIdLatch(idLatchKey);
if (latch != null) {
try {
if (!latch.await(10, TimeUnit.SECONDS)) {
LOG.warn("Timed out while releasing id {} from id pool {}", idKey, parentPoolName);
}
} catch (InterruptedException ignored) {
LOG.warn("Thread interrupted while releasing id {} from id pool {}", idKey, parentPoolName);
} finally {
idUtils.removeReleaseIdLatch(idLatchKey);
}
}
localPoolName = localPoolName.intern();
InstanceIdentifier<IdPool> parentIdPoolInstanceIdentifier = idUtils.getIdPoolInstance(parentPoolName);
IdPool parentIdPool = singleTxDB.syncRead(CONFIGURATION, parentIdPoolInstanceIdentifier);
List<IdEntries> idEntries = parentIdPool.getIdEntries();
List<IdEntries> newIdEntries = idEntries;
if (idEntries == null) {
throw new IdDoesNotExistException(parentPoolName, idKey);
}
InstanceIdentifier<IdEntries> existingId = idUtils.getIdEntry(parentIdPoolInstanceIdentifier, idKey);
Optional<IdEntries> existingIdEntryObject = singleTxDB.syncReadOptional(CONFIGURATION, existingId);
if (!existingIdEntryObject.isPresent()) {
LOG.info("Specified Id key {} does not exist in id pool {}", idKey, parentPoolName);
idUtils.unlock(lockManager, idLatchKey);
return;
}
IdEntries existingIdEntry = existingIdEntryObject.get();
List<Long> idValuesList = existingIdEntry.getIdValue();
IdLocalPool localIdPoolCache = localPool.get(parentPoolName);
boolean isRemoved = newIdEntries.remove(existingIdEntry);
LOG.debug("The entry {} is removed {}", existingIdEntry, isRemoved);
updateDelayedEntriesInLocalCache(idValuesList, parentPoolName, localIdPoolCache);
IdHolderSyncJob poolSyncJob = new IdHolderSyncJob(localPoolName, localIdPoolCache.getReleasedIds(), txRunner, idUtils);
jobCoordinator.enqueueJob(localPoolName, poolSyncJob, IdUtils.RETRY_COUNT);
scheduleCleanUpTask(localIdPoolCache, parentPoolName, parentIdPool.getBlockSize());
LOG.debug("Released id ({}, {}) from pool {}", idKey, idValuesList, localPoolName);
// Updating id entries in the parent pool. This will be used for restart scenario
UpdateIdEntryJob job = new UpdateIdEntryJob(parentPoolName, localPoolName, idKey, null, txRunner, idUtils, lockManager);
jobCoordinator.enqueueJob(parentPoolName, job, IdUtils.RETRY_COUNT);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries in project genius by opendaylight.
the class IdManagerTest method getUpdatedActualParentPool.
private IdPool getUpdatedActualParentPool() throws ReadFailedException {
IdPool idPoolParentFromDS = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(ID_POOL_NAME)).build());
List<ChildPools> childPool = idPoolParentFromDS.getChildPools();
List<ChildPools> updatedChildPool = childPool.stream().map(child -> new ChildPoolsBuilder(child).setLastAccessTime(0L).build()).collect(Collectors.toList());
List<IdEntries> idEntries = idPoolParentFromDS.getIdEntries();
IdPoolBuilder idPoolBuilder = new IdPoolBuilder(idPoolParentFromDS);
if (idEntries != null) {
List<IdEntries> sortedIdEntries = idEntries.stream().sorted(comparing(IdEntries::getIdKey)).collect(Collectors.toList());
idPoolBuilder.setIdEntries(sortedIdEntries);
}
IdPool actualIdPoolParent = idPoolBuilder.setChildPools(updatedChildPool).build();
return actualIdPoolParent;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries in project genius by opendaylight.
the class IdManagerTest method testMultithreadedIdAllocationFromReleaseIds.
@Test
// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
public void testMultithreadedIdAllocationFromReleaseIds() throws Throwable {
CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
idManagerService.createIdPool(createIdPoolInput);
idManagerService.allocateId(allocateIdInput);
// Should wait for all job to complete.
coordinatorEventsWaiter.awaitEventsConsumption();
String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
IdPool parentIdPool = new IdPoolBuilder().setPoolName(ID_POOL_NAME).setKey(new IdPoolKey(ID_POOL_NAME)).setReleasedIdsHolder(createReleaseIdHolder(Collections.emptyList())).build();
IdPool childPool = new IdPoolBuilder().setPoolName(localPoolName).setKey(new IdPoolKey(localPoolName)).setReleasedIdsHolder(createReleaseIdHolder(Arrays.asList(1L, 2L, 3L))).setAvailableIdsHolder(createAvailableIdHolder(0L, 9L, 10L)).build();
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.merge(LogicalDatastoreType.CONFIGURATION, getIdPoolIdentifier(ID_POOL_NAME), parentIdPool);
tx.merge(LogicalDatastoreType.CONFIGURATION, getIdPoolIdentifier(localPoolName), childPool);
tx.submit().get();
// Wait for the changes to be available on the caches.
asyncEventsWaiter.awaitEventsConsumption();
requestIdsConcurrently(false);
coordinatorEventsWaiter.awaitEventsConsumption();
asyncEventsWaiter.awaitEventsConsumption();
IdPool actualIdPoolChild = getUpdatedActualChildPool();
IdPool actualIdPoolParent = getUpdatedActualParentPool();
// Cannot compare the idEntries since we cannot guarantee which idKey gets what value.
// However the allocated id values uniqueness is verified in requestIdsConcurrently method.
AssertDataObjects.assertEqualBeans(ExpectedAllocateIdMultipleRequestsFromReleaseIds.idPoolParent().getReleasedIdsHolder(), actualIdPoolParent.getReleasedIdsHolder());
AssertDataObjects.assertEqualBeans(ExpectedAllocateIdMultipleRequestsFromReleaseIds.idPoolChild(), actualIdPoolChild);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries in project genius by opendaylight.
the class IdManagerTest method testMultithreadedIdAllocationFromAvailableIds.
@Test
// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
public void testMultithreadedIdAllocationFromAvailableIds() throws Throwable {
CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
idManagerService.createIdPool(createIdPoolInput);
requestIdsConcurrently(false);
coordinatorEventsWaiter.awaitEventsConsumption();
IdPool actualIdPoolChild = getUpdatedActualChildPool();
IdPool actualIdPoolParent = getUpdatedActualParentPool();
// Cannot compare the idEntries since we cannot guarantee which idKey gets what value.
// However the allocated id values uniqueness is verified in requestIdsConcurrently method.
AssertDataObjects.assertEqualBeans(ExpectedAllocateIdMultipleRequestsFromAvailableIds.idPoolParent().getAvailableIdsHolder(), actualIdPoolParent.getAvailableIdsHolder());
AssertDataObjects.assertEqualBeans(ExpectedAllocateIdMultipleRequestsFromAvailableIds.idPoolChild(), actualIdPoolChild);
}
Aggregations