Search in sources :

Example 1 with DelayedIdEntriesBuilder

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

the class IdUtils method freeExcessAvailableIds.

/**
 * Changes made to the parameters passed are not persisted to the Datastore.
 * Method invoking should ensure that these gets persisted.
 */
public void freeExcessAvailableIds(ReleasedIdHolder releasedIdHolder, ReleasedIdsHolderBuilder releasedIdsParent, long idCountToBeFreed) {
    List<DelayedIdEntries> existingDelayedIdEntriesInParent = releasedIdsParent.getDelayedIdEntries();
    long availableIdCountChild = releasedIdHolder.getAvailableIdCount();
    if (existingDelayedIdEntriesInParent == null) {
        existingDelayedIdEntriesInParent = new LinkedList<>();
    }
    idCountToBeFreed = Math.min(idCountToBeFreed, availableIdCountChild);
    for (int index = 0; index < idCountToBeFreed; index++) {
        Optional<Long> idValueOptional = releasedIdHolder.allocateId();
        if (!idValueOptional.isPresent()) {
            break;
        }
        long idValue = idValueOptional.get();
        DelayedIdEntries delayedIdEntries = new DelayedIdEntriesBuilder().setId(idValue).setReadyTimeSec(System.currentTimeMillis() / 1000).build();
        existingDelayedIdEntriesInParent.add(delayedIdEntries);
    }
    long availableIdCountParent = releasedIdsParent.getAvailableIdCount();
    releasedIdsParent.setDelayedIdEntries(existingDelayedIdEntriesInParent).setAvailableIdCount(availableIdCountParent + idCountToBeFreed);
}
Also used : DelayedIdEntriesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntriesBuilder) DelayedIdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)

Example 2 with DelayedIdEntriesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntriesBuilder 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)

Aggregations

DelayedIdEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries)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 ArrayList (java.util.ArrayList)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 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Assert.assertEquals (org.junit.Assert.assertEquals)1