use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder in project genius by opendaylight.
the class IdUtils method freeExcessAvailableIds.
/**
* Changes made to the parameters passed are not persisted to the Datastore.
* Method invoking should ensure that these gets persisted.
*/
public void freeExcessAvailableIds(ReleasedIdHolder releasedIdHolder, ReleasedIdsHolderBuilder releasedIdsParent, long idCountToBeFreed) {
List<DelayedIdEntries> existingDelayedIdEntriesInParent = releasedIdsParent.getDelayedIdEntries();
long availableIdCountChild = releasedIdHolder.getAvailableIdCount();
if (existingDelayedIdEntriesInParent == null) {
existingDelayedIdEntriesInParent = new LinkedList<>();
}
idCountToBeFreed = Math.min(idCountToBeFreed, availableIdCountChild);
for (int index = 0; index < idCountToBeFreed; index++) {
Optional<Long> idValueOptional = releasedIdHolder.allocateId();
if (!idValueOptional.isPresent()) {
break;
}
long idValue = idValueOptional.get();
DelayedIdEntries delayedIdEntries = new DelayedIdEntriesBuilder().setId(idValue).setReadyTimeSec(System.currentTimeMillis() / 1000).build();
existingDelayedIdEntriesInParent.add(delayedIdEntries);
}
long availableIdCountParent = releasedIdsParent.getAvailableIdCount();
releasedIdsParent.setDelayedIdEntries(existingDelayedIdEntriesInParent).setAvailableIdCount(availableIdCountParent + idCountToBeFreed);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder in project genius by opendaylight.
the class CleanUpJob method cleanupExcessIds.
private void cleanupExcessIds() throws IdManagerException, ReadFailedException, TransactionCommitFailedException {
// We can update the availableCount here... and update it in DS using IdHolderSyncJob
long totalAvailableIdCount = idLocalPool.getAvailableIds().getAvailableIdCount() + idLocalPool.getReleasedIds().getAvailableIdCount();
if (totalAvailableIdCount > blockSize * 2) {
if (LOG.isDebugEnabled()) {
LOG.debug("Condition for cleanUp Satisfied for localPool {} - totalAvailableIdCount {}", idLocalPool, totalAvailableIdCount);
}
String parentPoolNameIntern = parentPoolName.intern();
InstanceIdentifier<ReleasedIdsHolder> releasedIdInstanceIdentifier = idUtils.getReleasedIdsHolderInstance(parentPoolNameIntern);
// cannot rely on DSJC because that is not cluster-aware
try {
idUtils.lock(lockManager, parentPoolNameIntern);
Optional<ReleasedIdsHolder> releasedIdsHolder = SingleTransactionDataBroker.syncReadOptional(broker, CONFIGURATION, releasedIdInstanceIdentifier);
if (!releasedIdsHolder.isPresent()) {
LOG.error("ReleasedIds not present in parent pool. Unable to cleanup excess ids");
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Releasing excesss Ids from local pool");
}
ReleasedIdHolder releasedIds = (ReleasedIdHolder) idLocalPool.getReleasedIds();
ReleasedIdsHolderBuilder releasedIdsParent = new ReleasedIdsHolderBuilder(releasedIdsHolder.get());
idUtils.freeExcessAvailableIds(releasedIds, releasedIdsParent, totalAvailableIdCount - blockSize * 2);
IdHolderSyncJob job = new IdHolderSyncJob(idLocalPool.getPoolName(), releasedIds, txRunner, idUtils);
jobCoordinator.enqueueJob(idLocalPool.getPoolName(), job, IdUtils.RETRY_COUNT);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, releasedIdInstanceIdentifier, releasedIdsParent.build());
} finally {
idUtils.unlock(lockManager, parentPoolNameIntern);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder in project genius by opendaylight.
the class IdManagerTest method getUpdatedActualChildPool.
private IdPool getUpdatedActualChildPool() throws ReadFailedException {
String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
IdPool idPoolChildFromDS = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(localPoolName)).build());
List<DelayedIdEntries> actualDelayedIdEntries = idPoolChildFromDS.getReleasedIdsHolder().getDelayedIdEntries();
IdPool actualIdPoolChild = idPoolChildFromDS;
if (actualDelayedIdEntries != null) {
List<DelayedIdEntries> updatedDelayedIdEntries = actualDelayedIdEntries.stream().map(delayedIdEntry -> new DelayedIdEntriesBuilder().setId(delayedIdEntry.getId()).setReadyTimeSec(0L).build()).collect(Collectors.toList());
ReleasedIdsHolder releasedId = new ReleasedIdsHolderBuilder(idPoolChildFromDS.getReleasedIdsHolder()).setDelayedIdEntries(updatedDelayedIdEntries).build();
actualIdPoolChild = new IdPoolBuilder(idPoolChildFromDS).setReleasedIdsHolder(releasedId).build();
}
return actualIdPoolChild;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder in project genius by opendaylight.
the class IdManager method allocateIdBlockFromParentPool.
private long allocateIdBlockFromParentPool(IdLocalPool localPoolCache, IdPool parentIdPool, WriteTransaction tx) throws OperationFailedException, IdManagerException {
long idCount = -1;
ReleasedIdsHolderBuilder releasedIdsBuilderParent = idUtils.getReleaseIdsHolderBuilder(parentIdPool);
while (true) {
idCount = allocateIdBlockFromAvailableIdsHolder(localPoolCache, parentIdPool, tx);
if (idCount > 0) {
return idCount;
}
idCount = allocateIdBlockFromReleasedIdsHolder(localPoolCache, releasedIdsBuilderParent, parentIdPool, tx);
if (idCount > 0) {
return idCount;
}
idCount = getIdsFromOtherChildPools(releasedIdsBuilderParent, parentIdPool);
if (idCount <= 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unable to allocate Id block from global pool");
}
throw new IdManagerException(String.format("Ids exhausted for pool : %s", parentIdPool.getPoolName()));
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder 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));
}
}
Aggregations