Search in sources :

Example 6 with AvailableIdsHolder

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 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

AvailableIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder)6 ReleasedIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder)4 DelayedIdEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)3 IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)2 IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)2 ArrayList (java.util.ArrayList)1 DelayedIdEntry (org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry)1 IdPools (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools)1 IdPoolBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder)1 AvailableIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder)1 GetAvailableResourcesOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetAvailableResourcesOutput)1 GetAvailableResourcesOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetAvailableResourcesOutputBuilder)1 GetResourcePoolOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetResourcePoolOutput)1 GetResourcePoolOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetResourcePoolOutputBuilder)1 AvailableIds (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIds)1 AvailableIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIdsBuilder)1 DelayedResourceEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.released.resource.ids.DelayedResourceEntries)1 DelayedResourceEntriesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.released.resource.ids.DelayedResourceEntriesBuilder)1