Search in sources :

Example 1 with AvailableIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIds 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;
}
Also used : AvailableIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder) AvailableIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder) 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)

Example 2 with AvailableIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIds in project genius by opendaylight.

the class IdManager method getIdBlockFromParentPool.

/**
 * Changes made to availableIds and releasedIds will not be persisted to the datastore.
 */
private long getIdBlockFromParentPool(String parentPoolName, IdLocalPool localIdPool) throws OperationFailedException, IdManagerException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Allocating block of id from parent pool {}", parentPoolName);
    }
    InstanceIdentifier<IdPool> idPoolInstanceIdentifier = idUtils.getIdPoolInstance(parentPoolName);
    parentPoolName = parentPoolName.intern();
    idUtils.lock(lockManager, parentPoolName);
    long idCount = 0;
    try {
        // Check if the childpool already got id block.
        long availableIdCount = localIdPool.getAvailableIds().getAvailableIdCount() + localIdPool.getReleasedIds().getAvailableIdCount();
        if (availableIdCount > 0) {
            return availableIdCount;
        }
        WriteTransaction tx = broker.newWriteOnlyTransaction();
        IdPool parentIdPool = singleTxDB.syncRead(CONFIGURATION, idPoolInstanceIdentifier);
        idCount = allocateIdBlockFromParentPool(localIdPool, parentIdPool, tx);
        tx.submit().checkedGet();
    } catch (IdManagerException | NullPointerException e) {
        LOG.error("Error getting id block from parent pool", e);
    } finally {
        idUtils.unlock(lockManager, parentPoolName);
    }
    return idCount;
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)

Example 3 with AvailableIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIds 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();
}
Also used : AvailableIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder) ArrayList(java.util.ArrayList) AvailableIds(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIds) 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) GetResourcePoolOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetResourcePoolOutputBuilder) ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) DelayedResourceEntriesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.released.resource.ids.DelayedResourceEntriesBuilder) DelayedResourceEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.released.resource.ids.DelayedResourceEntries) AvailableIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIdsBuilder) GetResourcePoolOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.GetResourcePoolOutput)

Example 4 with AvailableIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.getresourcepool.output.AvailableIds 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;
}
Also used : AvailableIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder) ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) ChildPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools) IdPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) 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

IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)3 IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)2 AvailableIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder)2 AvailableIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder)2 DelayedIdEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)2 ArrayList (java.util.ArrayList)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)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 ChildPools (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools)1 ReleasedIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder)1 ReleasedIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder)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