use of org.opendaylight.yangtools.yang.common.OperationFailedException in project genius by opendaylight.
the class IdManager method allocateIdFromLocalPool.
private List<Long> allocateIdFromLocalPool(String parentPoolName, String localPoolName, String idKey, long size) throws OperationFailedException, IdManagerException {
LOG.debug("Allocating id from local pool {}. Parent pool {}. Idkey {}", localPoolName, parentPoolName, idKey);
String uniqueIdKey = idUtils.getUniqueKey(parentPoolName, idKey);
CompletableFuture<List<Long>> futureIdValues = new CompletableFuture<>();
CompletableFuture<List<Long>> existingFutureIdValue = idUtils.putAllocatedIdsIfAbsent(uniqueIdKey, futureIdValues);
if (existingFutureIdValue != null) {
try {
return existingFutureIdValue.get();
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Could not obtain id from existing futureIdValue for idKey {} and pool {}.", idKey, parentPoolName);
throw new IdManagerException(e.getMessage(), e);
}
}
try {
List<Long> newIdValuesList = checkForIdInIdEntries(parentPoolName, idKey, uniqueIdKey, futureIdValues, false);
if (!newIdValuesList.isEmpty()) {
return newIdValuesList;
}
// This get will not help in concurrent reads. Hence the same read needs to be done again.
IdLocalPool localIdPool = getOrCreateLocalIdPool(parentPoolName, localPoolName);
LOG.debug("Got pool {}", localIdPool);
long newIdValue = -1;
localPoolName = localPoolName.intern();
if (size == 1) {
newIdValue = getIdFromLocalPoolCache(localIdPool, parentPoolName);
newIdValuesList.add(newIdValue);
} else {
getRangeOfIds(parentPoolName, localPoolName, size, newIdValuesList, localIdPool, newIdValue);
}
LOG.debug("The newIdValues {} for the idKey {}", newIdValuesList, idKey);
idUtils.putReleaseIdLatch(uniqueIdKey, new CountDownLatch(1));
UpdateIdEntryJob job = new UpdateIdEntryJob(parentPoolName, localPoolName, idKey, newIdValuesList, txRunner, idUtils, lockManager);
jobCoordinator.enqueueJob(parentPoolName, job, IdUtils.RETRY_COUNT);
futureIdValues.complete(newIdValuesList);
return newIdValuesList;
} catch (OperationFailedException | IdManagerException e) {
idUtils.unlock(lockManager, uniqueIdKey);
throw e;
}
}
use of org.opendaylight.yangtools.yang.common.OperationFailedException 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