use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey in project genius by opendaylight.
the class IdManager method allocateIdBlockFromReleasedIdsHolder.
private long allocateIdBlockFromReleasedIdsHolder(IdLocalPool localIdPool, ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool, WriteTransaction tx) {
if (releasedIdsBuilderParent.getAvailableIdCount() == 0) {
LOG.debug("Ids unavailable in releasedIds of parent pool {}", parentIdPool);
return 0;
}
List<DelayedIdEntries> delayedIdEntriesParent = releasedIdsBuilderParent.getDelayedIdEntries();
int idCount = Math.min(delayedIdEntriesParent.size(), parentIdPool.getBlockSize());
List<DelayedIdEntries> idEntriesToBeRemoved = delayedIdEntriesParent.subList(0, idCount);
ReleasedIdHolder releasedIds = (ReleasedIdHolder) localIdPool.getReleasedIds();
List<DelayedIdEntry> delayedIdEntriesLocalCache = releasedIds.getDelayedEntries();
List<DelayedIdEntry> delayedIdEntriesFromParentPool = idEntriesToBeRemoved.stream().map(delayedIdEntry -> new DelayedIdEntry(delayedIdEntry.getId(), delayedIdEntry.getReadyTimeSec())).sorted(comparing(DelayedIdEntry::getReadyTimeSec)).collect(toCollection(ArrayList::new));
delayedIdEntriesFromParentPool.addAll(delayedIdEntriesLocalCache);
releasedIds.replaceDelayedEntries(delayedIdEntriesFromParentPool);
releasedIds.setAvailableIdCount(releasedIds.getAvailableIdCount() + idCount);
localIdPool.setReleasedIds(releasedIds);
delayedIdEntriesParent.removeAll(idEntriesToBeRemoved);
releasedIdsBuilderParent.setDelayedIdEntries(delayedIdEntriesParent);
InstanceIdentifier<ReleasedIdsHolder> releasedIdsHolderInstanceIdentifier = InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(parentIdPool.getPoolName())).child(ReleasedIdsHolder.class).build();
releasedIdsBuilderParent.setAvailableIdCount(releasedIdsBuilderParent.getAvailableIdCount() - idCount);
LOG.debug("Allocated {} ids from releasedIds of parent pool {}", idCount, parentIdPool);
tx.merge(CONFIGURATION, releasedIdsHolderInstanceIdentifier, releasedIdsBuilderParent.build(), true);
return idCount;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey 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.IdPoolKey in project genius by opendaylight.
the class IdManagerTest method getIdPoolIdentifier.
private InstanceIdentifier<IdPool> getIdPoolIdentifier(String poolName) {
InstanceIdentifier.InstanceIdentifierBuilder<IdPool> idBuilder = InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(poolName));
InstanceIdentifier<IdPool> id = idBuilder.build();
return id;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey in project genius by opendaylight.
the class IdHolderSyncJob method call.
@Override
public List<ListenableFuture<Void>> call() {
IdPoolBuilder idPool = new IdPoolBuilder().setKey(new IdPoolKey(localPoolName));
idHolder.refreshDataStore(idPool);
InstanceIdentifier<IdPool> localPoolInstanceIdentifier = idUtils.getIdPoolInstance(localPoolName);
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
tx.merge(CONFIGURATION, localPoolInstanceIdentifier, idPool.build(), true);
idUtils.incrementPoolUpdatedMap(localPoolName);
if (LOG.isDebugEnabled()) {
LOG.debug("IdHolder synced {}", idHolder);
}
}));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey in project genius by opendaylight.
the class LocalPoolCreateJob method call.
@Override
public List<ListenableFuture<Void>> call() {
String localPoolName = idLocalPool.getPoolName();
if (LOG.isDebugEnabled()) {
LOG.debug("Started localPoolCreateJob for {}", localPoolName);
}
InstanceIdentifier<IdPool> localPoolInstanceIdentifier = idUtils.getIdPoolInstance(localPoolName);
IdPoolBuilder idPool = new IdPoolBuilder().setKey(new IdPoolKey(localPoolName)).setBlockSize(blockSize).setParentPoolName(parentPoolName).setPoolName(localPoolName);
idLocalPool.getAvailableIds().refreshDataStore(idPool);
idLocalPool.getReleasedIds().refreshDataStore(idPool);
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.put(LogicalDatastoreType.CONFIGURATION, localPoolInstanceIdentifier, idPool.build(), WriteTransaction.CREATE_MISSING_PARENTS)));
}
Aggregations