use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder in project genius by opendaylight.
the class IdUtils method createGlobalPool.
protected IdPool createGlobalPool(String poolName, long low, long high, long blockSize) {
AvailableIdsHolder availableIdsHolder = createAvailableIdsHolder(low, high, low - 1);
ReleasedIdsHolder releasedIdsHolder = createReleasedIdsHolder(DEFAULT_AVAILABLE_ID_COUNT, 0);
int size = (int) blockSize;
return new IdPoolBuilder().setKey(new IdPoolKey(poolName)).setBlockSize(size).setPoolName(poolName).setAvailableIdsHolder(availableIdsHolder).setReleasedIdsHolder(releasedIdsHolder).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder 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.AvailableIdsHolder 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.id.pools.id.pool.AvailableIdsHolder 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.id.pools.id.pool.AvailableIdsHolder in project genius by opendaylight.
the class IdUtils method syncAvailableIdHolder.
public void syncAvailableIdHolder(AvailableIdHolder availableIdHolder, IdPoolBuilder idPool) {
long cur = availableIdHolder.getCur().get();
long low = availableIdHolder.getLow();
long high = availableIdHolder.getHigh();
AvailableIdsHolder availableIdsHolder = createAvailableIdsHolder(low, high, cur);
idPool.setAvailableIdsHolder(availableIdsHolder);
}
Aggregations