use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools in project genius by opendaylight.
the class IdManagerTest method getUpdatedActualParentPool.
private IdPool getUpdatedActualParentPool() throws ReadFailedException {
IdPool idPoolParentFromDS = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(ID_POOL_NAME)).build());
List<ChildPools> childPool = idPoolParentFromDS.getChildPools();
List<ChildPools> updatedChildPool = childPool.stream().map(child -> new ChildPoolsBuilder(child).setLastAccessTime(0L).build()).collect(Collectors.toList());
List<IdEntries> idEntries = idPoolParentFromDS.getIdEntries();
IdPoolBuilder idPoolBuilder = new IdPoolBuilder(idPoolParentFromDS);
if (idEntries != null) {
List<IdEntries> sortedIdEntries = idEntries.stream().sorted(comparing(IdEntries::getIdKey)).collect(Collectors.toList());
idPoolBuilder.setIdEntries(sortedIdEntries);
}
IdPool actualIdPoolParent = idPoolBuilder.setChildPools(updatedChildPool).build();
return actualIdPoolParent;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools in project genius by opendaylight.
the class IdUtils method updateChildPool.
public void updateChildPool(WriteTransaction tx, String poolName, String localPoolName) {
ChildPools childPool = createChildPool(localPoolName);
InstanceIdentifier<ChildPools> childPoolInstanceIdentifier = getChildPoolsInstanceIdentifier(poolName, localPoolName);
tx.merge(LogicalDatastoreType.CONFIGURATION, childPoolInstanceIdentifier, childPool, true);
}
Aggregations