use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries 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.released.ids.DelayedIdEntries 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.released.ids.DelayedIdEntries in project genius by opendaylight.
the class ResourceManager method getResourcePool.
@Override
public Future<RpcResult<GetResourcePoolOutput>> getResourcePool(GetResourcePoolInput input) {
Objects.requireNonNull(input.getResourceType(), RESOURCE_TYPE_CANNOT_BE_NULL);
Objects.requireNonNull(resourcesCache.get(input.getResourceType()), RESOURCE_TYPE_CANNOT_BE_NULL);
long currentTimeSec = System.currentTimeMillis() / 1000;
List<AvailableIds> availableIdsList = new ArrayList<>();
List<DelayedResourceEntries> delayedIdEntriesList = new ArrayList<>();
InstanceIdentifier<IdPool> parentId = ResourceManagerUtils.getIdPoolInstance(resourcesCache.get(input.getResourceType()));
Optional<IdPool> optionalParentIdPool = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, parentId, dataBroker);
if (optionalParentIdPool != null && optionalParentIdPool.isPresent()) {
IdPool parentIdPool = optionalParentIdPool.get();
AvailableIdsHolder availableParentIdsHolder = parentIdPool.getAvailableIdsHolder();
if (availableParentIdsHolder.getStart() < availableParentIdsHolder.getEnd()) {
availableIdsList.add(new AvailableIdsBuilder().setStart(availableParentIdsHolder.getStart()).setEnd(availableParentIdsHolder.getEnd()).build());
}
ReleasedIdsHolder releasedParentIdsHolder = parentIdPool.getReleasedIdsHolder();
if (releasedParentIdsHolder != null) {
List<DelayedIdEntries> delayedIdParentList = releasedParentIdsHolder.getDelayedIdEntries();
if (delayedIdParentList != null && !delayedIdParentList.isEmpty()) {
for (DelayedIdEntries delayedParentEntry : delayedIdParentList) {
delayedIdEntriesList.add(new DelayedResourceEntriesBuilder().setId(delayedParentEntry.getId()).setReadyTimeSec(delayedParentEntry.getReadyTimeSec()).build());
}
}
}
}
String localPool = ResourceManagerUtils.getLocalPoolName(resourcesCache.get(input.getResourceType()));
InstanceIdentifier<IdPool> localId = ResourceManagerUtils.getIdPoolInstance(localPool);
Optional<IdPool> optionalLocalId = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, localId, dataBroker);
if (optionalLocalId != null && optionalLocalId.isPresent()) {
IdPool localIdPool = optionalLocalId.get();
AvailableIdsHolder availableLocalIdsHolder = localIdPool.getAvailableIdsHolder();
if (availableLocalIdsHolder != null && availableLocalIdsHolder.getStart() < availableLocalIdsHolder.getEnd()) {
availableIdsList.add(new AvailableIdsBuilder().setStart(availableLocalIdsHolder.getStart()).setEnd(availableLocalIdsHolder.getEnd()).build());
}
ReleasedIdsHolder releasedLocalIdsHolder = localIdPool.getReleasedIdsHolder();
if (releasedLocalIdsHolder != null) {
List<DelayedIdEntries> delayedIdLocalList = releasedLocalIdsHolder.getDelayedIdEntries();
if (delayedIdLocalList != null && !delayedIdLocalList.isEmpty()) {
for (DelayedIdEntries delayedLocalEntry : delayedIdLocalList) {
if (delayedLocalEntry.getReadyTimeSec() > currentTimeSec) {
break;
}
delayedIdEntriesList.add(new DelayedResourceEntriesBuilder().setId(delayedLocalEntry.getId()).setReadyTimeSec(delayedLocalEntry.getReadyTimeSec()).build());
}
}
}
}
GetResourcePoolOutput output = new GetResourcePoolOutputBuilder().setAvailableIds(availableIdsList).setDelayedResourceEntries(delayedIdEntriesList).build();
return RpcResultBuilder.success(output).buildFuture();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries in project genius by opendaylight.
the class IdManager method updateLocalIdPoolCache.
public boolean updateLocalIdPoolCache(IdPool idPool, String parentPoolName) {
AvailableIdsHolder availableIdsHolder = idPool.getAvailableIdsHolder();
AvailableIdHolder availableIdHolder = new AvailableIdHolder(idUtils, availableIdsHolder.getStart(), availableIdsHolder.getEnd());
availableIdHolder.setCur(availableIdsHolder.getCursor());
ReleasedIdsHolder releasedIdsHolder = idPool.getReleasedIdsHolder();
ReleasedIdHolder releasedIdHolder = new ReleasedIdHolder(idUtils, releasedIdsHolder.getDelayedTimeSec());
releasedIdHolder.setAvailableIdCount(releasedIdsHolder.getAvailableIdCount());
List<DelayedIdEntries> delayedEntries = releasedIdsHolder.getDelayedIdEntries();
List<DelayedIdEntry> delayedIdEntryInCache = delayedEntries.stream().map(delayedIdEntry -> new DelayedIdEntry(delayedIdEntry.getId(), delayedIdEntry.getReadyTimeSec())).sorted(comparing(DelayedIdEntry::getReadyTimeSec)).collect(toCollection(ArrayList::new));
releasedIdHolder.replaceDelayedEntries(delayedIdEntryInCache);
IdLocalPool idLocalPool = new IdLocalPool(idUtils, idPool.getPoolName());
idLocalPool.setAvailableIds(availableIdHolder);
idLocalPool.setReleasedIds(releasedIdHolder);
localPool.put(parentPoolName, idLocalPool);
if (LOG.isDebugEnabled()) {
LOG.debug("Populating cache for {} with {}", idLocalPool.getPoolName(), idLocalPool);
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries 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