Search in sources :

Example 1 with ReleasedIdsHolder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder 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();
}
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) 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)

Example 2 with ReleasedIdsHolder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder in project genius by opendaylight.

the class CleanUpJob method cleanupExcessIds.

private void cleanupExcessIds() throws IdManagerException, ReadFailedException, TransactionCommitFailedException {
    // We can update the availableCount here... and update it in DS using IdHolderSyncJob
    long totalAvailableIdCount = idLocalPool.getAvailableIds().getAvailableIdCount() + idLocalPool.getReleasedIds().getAvailableIdCount();
    if (totalAvailableIdCount > blockSize * 2) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Condition for cleanUp Satisfied for localPool {} - totalAvailableIdCount {}", idLocalPool, totalAvailableIdCount);
        }
        String parentPoolNameIntern = parentPoolName.intern();
        InstanceIdentifier<ReleasedIdsHolder> releasedIdInstanceIdentifier = idUtils.getReleasedIdsHolderInstance(parentPoolNameIntern);
        // cannot rely on DSJC because that is not cluster-aware
        try {
            idUtils.lock(lockManager, parentPoolNameIntern);
            Optional<ReleasedIdsHolder> releasedIdsHolder = SingleTransactionDataBroker.syncReadOptional(broker, CONFIGURATION, releasedIdInstanceIdentifier);
            if (!releasedIdsHolder.isPresent()) {
                LOG.error("ReleasedIds not present in parent pool. Unable to cleanup excess ids");
                return;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Releasing excesss Ids from local pool");
            }
            ReleasedIdHolder releasedIds = (ReleasedIdHolder) idLocalPool.getReleasedIds();
            ReleasedIdsHolderBuilder releasedIdsParent = new ReleasedIdsHolderBuilder(releasedIdsHolder.get());
            idUtils.freeExcessAvailableIds(releasedIds, releasedIdsParent, totalAvailableIdCount - blockSize * 2);
            IdHolderSyncJob job = new IdHolderSyncJob(idLocalPool.getPoolName(), releasedIds, txRunner, idUtils);
            jobCoordinator.enqueueJob(idLocalPool.getPoolName(), job, IdUtils.RETRY_COUNT);
            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, releasedIdInstanceIdentifier, releasedIdsParent.build());
        } finally {
            idUtils.unlock(lockManager, parentPoolNameIntern);
        }
    }
}
Also used : ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) ReleasedIdHolder(org.opendaylight.genius.idmanager.ReleasedIdHolder)

Example 3 with ReleasedIdsHolder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder in project genius by opendaylight.

the class IdManagerTest method getUpdatedActualChildPool.

private IdPool getUpdatedActualChildPool() throws ReadFailedException {
    String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
    IdPool idPoolChildFromDS = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(localPoolName)).build());
    List<DelayedIdEntries> actualDelayedIdEntries = idPoolChildFromDS.getReleasedIdsHolder().getDelayedIdEntries();
    IdPool actualIdPoolChild = idPoolChildFromDS;
    if (actualDelayedIdEntries != null) {
        List<DelayedIdEntries> updatedDelayedIdEntries = actualDelayedIdEntries.stream().map(delayedIdEntry -> new DelayedIdEntriesBuilder().setId(delayedIdEntry.getId()).setReadyTimeSec(0L).build()).collect(Collectors.toList());
        ReleasedIdsHolder releasedId = new ReleasedIdsHolderBuilder(idPoolChildFromDS.getReleasedIdsHolder()).setDelayedIdEntries(updatedDelayedIdEntries).build();
        actualIdPoolChild = new IdPoolBuilder(idPoolChildFromDS).setReleasedIdsHolder(releasedId).build();
    }
    return actualIdPoolChild;
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) Arrays(java.util.Arrays) MethodRule(org.junit.rules.MethodRule) LoggerFactory(org.slf4j.LoggerFactory) JobCoordinatorTestModule(org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule) Future(java.util.concurrent.Future) GuiceRule(org.opendaylight.infrautils.inject.guice.testutils.GuiceRule) Optional(com.google.common.base.Optional) DeleteIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInputBuilder) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) Assert.fail(org.junit.Assert.fail) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) ChildPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools) AvailableIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder) JobCoordinatorEventsWaiter(org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorEventsWaiter) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Set(java.util.Set) ChildPoolsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPoolsBuilder) Collectors(java.util.stream.Collectors) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Sets(com.google.common.collect.Sets) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) LogCaptureRule(org.opendaylight.infrautils.testutils.LogCaptureRule) IdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput) DelayedIdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) AtomicReference(java.util.concurrent.atomic.AtomicReference) IdUtils(org.opendaylight.genius.idmanager.IdUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder) Comparator.comparing(java.util.Comparator.comparing) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Logger(org.slf4j.Logger) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) Assert.assertNotNull(org.junit.Assert.assertNotNull) AssertDataObjects(org.opendaylight.mdsal.binding.testutils.AssertDataObjects) Assert.assertTrue(org.junit.Assert.assertTrue) ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test) ReleaseIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder) TestableDataTreeChangeListenerModule(org.opendaylight.genius.datastoreutils.testutils.TestableDataTreeChangeListenerModule) LogRule(org.opendaylight.infrautils.testutils.LogRule) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) ExecutionException(java.util.concurrent.ExecutionException) IdPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools) DelayedIdEntriesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntriesBuilder) Rule(org.junit.Rule) AsyncEventsWaiter(org.opendaylight.genius.datastoreutils.testutils.AsyncEventsWaiter) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DeleteIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInput) ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) AvailableIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder) IdPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ComparisonFailure(org.junit.ComparisonFailure) ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) 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) IdPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder) DelayedIdEntriesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntriesBuilder) 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)

Example 4 with ReleasedIdsHolder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder 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 5 with ReleasedIdsHolder

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

Aggregations

ReleasedIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder)7 AvailableIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder)5 DelayedIdEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)5 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)3 ArrayList (java.util.ArrayList)2 DelayedIdEntry (org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry)2 IdPoolBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder)2 ReleasedIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder)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