use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder 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.IdPoolBuilder in project genius by opendaylight.
the class IdManager method getIdsFromOtherChildPools.
private long getIdsFromOtherChildPools(ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool) throws OperationFailedException {
List<ChildPools> childPoolsList = parentIdPool.getChildPools();
// Sorting the child pools on last accessed time so that the pool that
// was not accessed for a long time comes first.
childPoolsList.sort(comparing(ChildPools::getLastAccessTime));
long currentTime = System.currentTimeMillis() / 1000;
for (ChildPools childPools : childPoolsList) {
if (childPools.getLastAccessTime() + DEFAULT_IDLE_TIME > currentTime) {
break;
}
if (!childPools.getChildPoolName().equals(idUtils.getLocalPoolName(parentIdPool.getPoolName()))) {
InstanceIdentifier<IdPool> idPoolInstanceIdentifier = idUtils.getIdPoolInstance(childPools.getChildPoolName());
IdPool otherChildPool = singleTxDB.syncRead(CONFIGURATION, idPoolInstanceIdentifier);
ReleasedIdsHolderBuilder releasedIds = idUtils.getReleaseIdsHolderBuilder(otherChildPool);
List<DelayedIdEntries> delayedIdEntriesChild = releasedIds.getDelayedIdEntries();
List<DelayedIdEntries> delayedIdEntriesParent = releasedIdsBuilderParent.getDelayedIdEntries();
if (delayedIdEntriesParent == null) {
delayedIdEntriesParent = new LinkedList<>();
}
delayedIdEntriesParent.addAll(delayedIdEntriesChild);
delayedIdEntriesChild.clear();
AvailableIdsHolderBuilder availableIds = idUtils.getAvailableIdsHolderBuilder(otherChildPool);
while (idUtils.isIdAvailable(availableIds)) {
long cursor = availableIds.getCursor() + 1;
delayedIdEntriesParent.add(idUtils.createDelayedIdEntry(cursor, currentTime));
availableIds.setCursor(cursor);
}
long totalAvailableIdCount = releasedIds.getDelayedIdEntries().size() + idUtils.getAvailableIdsCount(availableIds);
long count = releasedIdsBuilderParent.getAvailableIdCount() + totalAvailableIdCount;
releasedIdsBuilderParent.setDelayedIdEntries(delayedIdEntriesParent).setAvailableIdCount(count);
singleTxDB.syncUpdate(CONFIGURATION, idPoolInstanceIdentifier, new IdPoolBuilder().setKey(new IdPoolKey(otherChildPool.getPoolName())).setAvailableIdsHolder(availableIds.build()).setReleasedIdsHolder(releasedIds.build()).build());
return totalAvailableIdCount;
}
}
return 0;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder in project genius by opendaylight.
the class IdManagerTest method testAllocateIdBlockFromReleasedIds.
@Test
public void testAllocateIdBlockFromReleasedIds() throws Exception {
CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY2).setPoolName(ID_POOL_NAME).build();
idManagerService.createIdPool(createIdPoolInput);
idManagerService.allocateId(allocateIdInput);
coordinatorEventsWaiter.awaitEventsConsumption();
asyncEventsWaiter.awaitEventsConsumption();
String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
IdPool parentIdPool = new IdPoolBuilder().setPoolName(ID_POOL_NAME).setKey(new IdPoolKey(ID_POOL_NAME)).setAvailableIdsHolder(createAvailableIdHolder(ID_LOW, ID_HIGH, ID_HIGH + 1)).setReleasedIdsHolder(createReleaseIdHolder(Arrays.asList(1L, 2L, 3L))).build();
IdPool childPool = new IdPoolBuilder().setPoolName(localPoolName).setKey(new IdPoolKey(localPoolName)).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();
AllocateIdInput allocateIdInput2 = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
assertEquals(idManagerService.allocateId(allocateIdInput2).get().getResult().getIdValue().longValue(), 1L);
coordinatorEventsWaiter.awaitEventsConsumption();
validateIdPools(ExpectedAllocateIdFromReleasedId.idPoolParent(), ExpectedAllocateIdFromReleasedId.idPoolChild());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder in project genius by opendaylight.
the class IdUtils method syncReleaseIdHolder.
public void syncReleaseIdHolder(ReleasedIdHolder releasedIdHolder, IdPoolBuilder idPool) {
long delayTime = releasedIdHolder.getTimeDelaySec();
ReleasedIdsHolderBuilder releasedIdsBuilder = new ReleasedIdsHolderBuilder();
List<DelayedIdEntries> delayedIdEntriesList = new ArrayList<>();
List<DelayedIdEntry> delayList = releasedIdHolder.getDelayedEntries();
for (DelayedIdEntry delayedId : delayList) {
DelayedIdEntries delayedIdEntry = createDelayedIdEntry(delayedId.getId(), delayedId.getReadyTimeSec());
delayedIdEntriesList.add(delayedIdEntry);
}
releasedIdsBuilder.setAvailableIdCount((long) delayedIdEntriesList.size()).setDelayedTimeSec(delayTime).setDelayedIdEntries(delayedIdEntriesList);
idPool.setReleasedIdsHolder(releasedIdsBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder in project genius by opendaylight.
the class IdUtils method syncAvailableIdHolder.
public void syncAvailableIdHolder(AvailableIdHolder availableIdHolder, IdPoolBuilder idPool) {
long cur = availableIdHolder.getCur().get();
long low = availableIdHolder.getLow();
long high = availableIdHolder.getHigh();
AvailableIdsHolder availableIdsHolder = createAvailableIdsHolder(low, high, cur);
idPool.setAvailableIdsHolder(availableIdsHolder);
}
Aggregations