Search in sources :

Example 6 with DelayedIdEntries

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries 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;
}
Also used : ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) DelayedIdEntry(org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry) IdPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) DelayedIdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)

Example 7 with DelayedIdEntries

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries 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());
}
Also used : ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) ArrayList(java.util.ArrayList) DelayedIdEntry(org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry) DelayedIdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)

Example 8 with DelayedIdEntries

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries in project genius by opendaylight.

the class ResourceManager method getAvailableResources.

@Override
public Future<RpcResult<GetAvailableResourcesOutput>> getAvailableResources(GetAvailableResourcesInput input) {
    Objects.requireNonNull(input.getResourceType(), RESOURCE_TYPE_CANNOT_BE_NULL);
    Objects.requireNonNull(resourcesCache.get(input.getResourceType()), RESOURCE_TYPE_NOT_FOUND);
    long totalIdsAvailableForAllocation = 0;
    long currentTimeSec = System.currentTimeMillis() / 1000;
    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();
        totalIdsAvailableForAllocation = availableParentIdsHolder.getEnd() - availableParentIdsHolder.getCursor();
        ReleasedIdsHolder releasedParentIdsHolder = parentIdPool.getReleasedIdsHolder();
        if (releasedParentIdsHolder != null) {
            List<DelayedIdEntries> delayedIdParentList = releasedParentIdsHolder.getDelayedIdEntries();
            if (delayedIdParentList != null && !delayedIdParentList.isEmpty()) {
                totalIdsAvailableForAllocation += delayedIdParentList.size();
            }
        }
    }
    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) {
            totalIdsAvailableForAllocation += availableLocalIdsHolder.getEnd() - availableLocalIdsHolder.getCursor();
        }
        ReleasedIdsHolder releasedLocalIdsHolder = localIdPool.getReleasedIdsHolder();
        if (releasedLocalIdsHolder != null) {
            long count = 0;
            List<DelayedIdEntries> delayedIdLocalList = releasedLocalIdsHolder.getDelayedIdEntries();
            if (delayedIdLocalList != null && !delayedIdLocalList.isEmpty()) {
                for (DelayedIdEntries delayedLocalEntry : delayedIdLocalList) {
                    if (delayedLocalEntry.getReadyTimeSec() > currentTimeSec) {
                        break;
                    }
                }
                count++;
            }
            totalIdsAvailableForAllocation += count;
        }
    }
    GetAvailableResourcesOutputBuilder outputBuilder = new GetAvailableResourcesOutputBuilder().setTotalAvailableIdCount(totalIdsAvailableForAllocation);
    RpcResultBuilder<GetAvailableResourcesOutput> rpcOutputBuilder = null;
    rpcOutputBuilder = RpcResultBuilder.success();
    rpcOutputBuilder.withResult(outputBuilder.build());
    return Futures.immediateFuture(rpcOutputBuilder.build());
}
Also used : ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) AvailableIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder) GetAvailableResourcesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetAvailableResourcesOutput) GetAvailableResourcesOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetAvailableResourcesOutputBuilder) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) DelayedIdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)

Aggregations

DelayedIdEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)8 ReleasedIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder)5 IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)4 AvailableIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder)4 ArrayList (java.util.ArrayList)3 DelayedIdEntry (org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry)3 IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)2 ReleasedIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder)2 DelayedIdEntriesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntriesBuilder)2 Optional (com.google.common.base.Optional)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator.comparing (java.util.Comparator.comparing)1 List (java.util.List)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1