Search in sources :

Example 11 with IdPoolKey

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

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

the class IdManagerTest method testAllocateIdBlockFromReleasedIds.

@Test
public void testAllocateIdBlockFromReleasedIds() throws Exception {
    CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
    AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY2).setPoolName(ID_POOL_NAME).build();
    idManagerService.createIdPool(createIdPoolInput);
    idManagerService.allocateId(allocateIdInput);
    coordinatorEventsWaiter.awaitEventsConsumption();
    asyncEventsWaiter.awaitEventsConsumption();
    String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
    IdPool parentIdPool = new IdPoolBuilder().setPoolName(ID_POOL_NAME).setKey(new IdPoolKey(ID_POOL_NAME)).setAvailableIdsHolder(createAvailableIdHolder(ID_LOW, ID_HIGH, ID_HIGH + 1)).setReleasedIdsHolder(createReleaseIdHolder(Arrays.asList(1L, 2L, 3L))).build();
    IdPool childPool = new IdPoolBuilder().setPoolName(localPoolName).setKey(new IdPoolKey(localPoolName)).setAvailableIdsHolder(createAvailableIdHolder(0L, 9L, 10L)).build();
    WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
    tx.merge(LogicalDatastoreType.CONFIGURATION, getIdPoolIdentifier(ID_POOL_NAME), parentIdPool);
    tx.merge(LogicalDatastoreType.CONFIGURATION, getIdPoolIdentifier(localPoolName), childPool);
    tx.submit().get();
    AllocateIdInput allocateIdInput2 = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
    assertEquals(idManagerService.allocateId(allocateIdInput2).get().getResult().getIdValue().longValue(), 1L);
    coordinatorEventsWaiter.awaitEventsConsumption();
    validateIdPools(ExpectedAllocateIdFromReleasedId.idPoolParent(), ExpectedAllocateIdFromReleasedId.idPoolChild());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) 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) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) Test(org.junit.Test)

Example 13 with IdPoolKey

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

the class IdManagerTest method getIdPoolIdentifier.

private InstanceIdentifier<IdPool> getIdPoolIdentifier(String poolName) {
    InstanceIdentifier.InstanceIdentifierBuilder<IdPool> idBuilder = InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(poolName));
    InstanceIdentifier<IdPool> id = idBuilder.build();
    return id;
}
Also used : InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) 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) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)

Example 14 with IdPoolKey

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

the class IdHolderSyncJob method call.

@Override
public List<ListenableFuture<Void>> call() {
    IdPoolBuilder idPool = new IdPoolBuilder().setKey(new IdPoolKey(localPoolName));
    idHolder.refreshDataStore(idPool);
    InstanceIdentifier<IdPool> localPoolInstanceIdentifier = idUtils.getIdPoolInstance(localPoolName);
    return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        tx.merge(CONFIGURATION, localPoolInstanceIdentifier, idPool.build(), true);
        idUtils.incrementPoolUpdatedMap(localPoolName);
        if (LOG.isDebugEnabled()) {
            LOG.debug("IdHolder synced {}", idHolder);
        }
    }));
}
Also used : Logger(org.slf4j.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LoggerFactory(org.slf4j.LoggerFactory) CONFIGURATION(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION) Callable(java.util.concurrent.Callable) IdUtils(org.opendaylight.genius.idmanager.IdUtils) List(java.util.List) IdHolder(org.opendaylight.genius.idmanager.IdHolder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) 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) Collections(java.util.Collections) 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)

Example 15 with IdPoolKey

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

the class LocalPoolCreateJob method call.

@Override
public List<ListenableFuture<Void>> call() {
    String localPoolName = idLocalPool.getPoolName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Started localPoolCreateJob for {}", localPoolName);
    }
    InstanceIdentifier<IdPool> localPoolInstanceIdentifier = idUtils.getIdPoolInstance(localPoolName);
    IdPoolBuilder idPool = new IdPoolBuilder().setKey(new IdPoolKey(localPoolName)).setBlockSize(blockSize).setParentPoolName(parentPoolName).setPoolName(localPoolName);
    idLocalPool.getAvailableIds().refreshDataStore(idPool);
    idLocalPool.getReleasedIds().refreshDataStore(idPool);
    return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.put(LogicalDatastoreType.CONFIGURATION, localPoolInstanceIdentifier, idPool.build(), WriteTransaction.CREATE_MISSING_PARENTS)));
}
Also used : IdLocalPool(org.opendaylight.genius.idmanager.IdLocalPool) Logger(org.slf4j.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) IdUtils(org.opendaylight.genius.idmanager.IdUtils) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) 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) Collections(java.util.Collections) 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)

Aggregations

IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)15 IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)12 IdPoolBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder)9 IdPools (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools)8 Test (org.junit.Test)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)6 CreateIdPoolInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput)6 CreateIdPoolInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder)6 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)6 AllocateIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput)5 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)5 Collections (java.util.Collections)4 List (java.util.List)4 AvailableIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder)4 AvailableIdsHolderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder)4 ReleasedIdsHolder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder)4 Optional (com.google.common.base.Optional)3 ExecutionException (java.util.concurrent.ExecutionException)3 DeleteIdPoolInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInput)3 DeleteIdPoolInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInputBuilder)3