use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder in project genius by opendaylight.
the class IdManager method allocateIdBlockFromAvailableIdsHolder.
private long allocateIdBlockFromAvailableIdsHolder(IdLocalPool localIdPool, IdPool parentIdPool, WriteTransaction tx) {
long idCount = 0;
AvailableIdsHolderBuilder availableIdsBuilderParent = idUtils.getAvailableIdsHolderBuilder(parentIdPool);
long end = availableIdsBuilderParent.getEnd();
long cur = availableIdsBuilderParent.getCursor();
if (!idUtils.isIdAvailable(availableIdsBuilderParent)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Ids exhausted in parent pool {}", parentIdPool);
}
return idCount;
}
// Update availableIdsHolder of Local Pool
idCount = Math.min(end - cur, parentIdPool.getBlockSize());
AvailableIdHolder availableIds = new AvailableIdHolder(idUtils, cur + 1, cur + idCount);
localIdPool.setAvailableIds(availableIds);
// Update availableIdsHolder of Global Pool
InstanceIdentifier<AvailableIdsHolder> availableIdsHolderInstanceIdentifier = InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(parentIdPool.getPoolName())).child(AvailableIdsHolder.class).build();
availableIdsBuilderParent.setCursor(cur + idCount);
if (LOG.isDebugEnabled()) {
LOG.debug("Allocated {} ids from availableIds of global pool {}", idCount, parentIdPool);
}
tx.merge(CONFIGURATION, availableIdsHolderInstanceIdentifier, availableIdsBuilderParent.build(), true);
return idCount;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder in project genius by opendaylight.
the class IdManager method getRangeOfIds.
private void getRangeOfIds(String parentPoolName, String localPoolName, long size, List<Long> newIdValuesList, IdLocalPool localIdPool, long newIdValue) throws ReadFailedException, IdManagerException {
InstanceIdentifier<IdPool> parentIdPoolInstanceIdentifier1 = idUtils.getIdPoolInstance(parentPoolName);
IdPool parentIdPool = singleTxDB.syncRead(CONFIGURATION, parentIdPoolInstanceIdentifier1);
long totalAvailableIdCount = localIdPool.getAvailableIds().getAvailableIdCount() + localIdPool.getReleasedIds().getAvailableIdCount();
AvailableIdsHolderBuilder availableParentIds = idUtils.getAvailableIdsHolderBuilder(parentIdPool);
ReleasedIdsHolderBuilder releasedParentIds = idUtils.getReleaseIdsHolderBuilder(parentIdPool);
totalAvailableIdCount = totalAvailableIdCount + releasedParentIds.getAvailableIdCount() + idUtils.getAvailableIdsCount(availableParentIds);
if (totalAvailableIdCount > size) {
while (size > 0) {
try {
newIdValue = getIdFromLocalPoolCache(localIdPool, parentPoolName);
} catch (OperationFailedException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Releasing IDs to pool {}", localPoolName);
}
// Releasing the IDs added in newIdValuesList since
// a null list would be returned now, as the
// requested size of list IDs exceeds the number of
// available IDs.
updateDelayedEntriesInLocalCache(newIdValuesList, parentPoolName, localIdPool);
}
newIdValuesList.add(newIdValue);
size--;
}
} else {
throw new IdManagerException(String.format("Ids exhausted for pool : %s", parentPoolName));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder 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;
}
Aggregations