use of org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry 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.genius.idmanager.ReleasedIdHolder.DelayedIdEntry in project genius by opendaylight.
the class IdManager method allocateIdBlockFromReleasedIdsHolder.
private long allocateIdBlockFromReleasedIdsHolder(IdLocalPool localIdPool, ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool, WriteTransaction tx) {
if (releasedIdsBuilderParent.getAvailableIdCount() == 0) {
LOG.debug("Ids unavailable in releasedIds of parent pool {}", parentIdPool);
return 0;
}
List<DelayedIdEntries> delayedIdEntriesParent = releasedIdsBuilderParent.getDelayedIdEntries();
int idCount = Math.min(delayedIdEntriesParent.size(), parentIdPool.getBlockSize());
List<DelayedIdEntries> idEntriesToBeRemoved = delayedIdEntriesParent.subList(0, idCount);
ReleasedIdHolder releasedIds = (ReleasedIdHolder) localIdPool.getReleasedIds();
List<DelayedIdEntry> delayedIdEntriesLocalCache = releasedIds.getDelayedEntries();
List<DelayedIdEntry> delayedIdEntriesFromParentPool = idEntriesToBeRemoved.stream().map(delayedIdEntry -> new DelayedIdEntry(delayedIdEntry.getId(), delayedIdEntry.getReadyTimeSec())).sorted(comparing(DelayedIdEntry::getReadyTimeSec)).collect(toCollection(ArrayList::new));
delayedIdEntriesFromParentPool.addAll(delayedIdEntriesLocalCache);
releasedIds.replaceDelayedEntries(delayedIdEntriesFromParentPool);
releasedIds.setAvailableIdCount(releasedIds.getAvailableIdCount() + idCount);
localIdPool.setReleasedIds(releasedIds);
delayedIdEntriesParent.removeAll(idEntriesToBeRemoved);
releasedIdsBuilderParent.setDelayedIdEntries(delayedIdEntriesParent);
InstanceIdentifier<ReleasedIdsHolder> releasedIdsHolderInstanceIdentifier = InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(parentIdPool.getPoolName())).child(ReleasedIdsHolder.class).build();
releasedIdsBuilderParent.setAvailableIdCount(releasedIdsBuilderParent.getAvailableIdCount() - idCount);
LOG.debug("Allocated {} ids from releasedIds of parent pool {}", idCount, parentIdPool);
tx.merge(CONFIGURATION, releasedIdsHolderInstanceIdentifier, releasedIdsBuilderParent.build(), true);
return idCount;
}
use of org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry in project genius by opendaylight.
the class IdUtils method syncReleaseIdHolder.
public void syncReleaseIdHolder(ReleasedIdHolder releasedIdHolder, IdPoolBuilder idPool) {
long delayTime = releasedIdHolder.getTimeDelaySec();
ReleasedIdsHolderBuilder releasedIdsBuilder = new ReleasedIdsHolderBuilder();
List<DelayedIdEntries> delayedIdEntriesList = new ArrayList<>();
List<DelayedIdEntry> delayList = releasedIdHolder.getDelayedEntries();
for (DelayedIdEntry delayedId : delayList) {
DelayedIdEntries delayedIdEntry = createDelayedIdEntry(delayedId.getId(), delayedId.getReadyTimeSec());
delayedIdEntriesList.add(delayedIdEntry);
}
releasedIdsBuilder.setAvailableIdCount((long) delayedIdEntriesList.size()).setDelayedTimeSec(delayTime).setDelayedIdEntries(delayedIdEntriesList);
idPool.setReleasedIdsHolder(releasedIdsBuilder.build());
}
Aggregations