Search in sources :

Example 11 with AllocateIdInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.

the class IfmUtil method allocateId.

public static Integer allocateId(IdManagerService idManager, String poolName, String idKey) {
    AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
    try {
        Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
        RpcResult<AllocateIdOutput> rpcResult = result.get();
        if (rpcResult.isSuccessful()) {
            return rpcResult.getResult().getIdValue().intValue();
        } else {
            LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("Exception when getting Unique Id", e);
    }
    return INVALID_ID;
}
Also used : AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)

Example 12 with AllocateIdInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.

the class AlivenessMonitor method getUniqueId.

private int getUniqueId(final String idKey) {
    AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(AlivenessMonitorConstants.MONITOR_IDPOOL_NAME).setIdKey(idKey).build();
    Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
    try {
        RpcResult<AllocateIdOutput> rpcResult = result.get();
        if (rpcResult.isSuccessful()) {
            return rpcResult.getResult().getIdValue().intValue();
        } else {
            LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("Exception when getting Unique Id for key {}", idKey, e);
    }
    return INVALID_ID;
}
Also used : AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)

Example 13 with AllocateIdInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.

the class IdManagerTest method testMultithreadedIdAllocationForSameKeyFromReleasedIds.

@Test
// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
public void testMultithreadedIdAllocationForSameKeyFromReleasedIds() throws Throwable {
    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(Collections.emptyList())).build();
    IdPool childPool = new IdPoolBuilder().setPoolName(localPoolName).setKey(new IdPoolKey(localPoolName)).setReleasedIdsHolder(createReleaseIdHolder(Arrays.asList(1L, 2L, 3L))).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();
    requestIdsConcurrently(true);
    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 14 with AllocateIdInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.

the class IdManagerTest method testReleaseId.

@Test
public void testReleaseId() throws Exception {
    CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
    AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
    ReleaseIdInput releaseIdInput = new ReleaseIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
    idManagerService.createIdPool(createIdPoolInput);
    idManagerService.allocateId(allocateIdInput);
    assertTrue(idManagerService.releaseId(releaseIdInput).get().isSuccessful());
    coordinatorEventsWaiter.awaitEventsConsumption();
    validateIdPools(ExpectedReleaseIdObjects.idPoolParent(), ExpectedReleaseIdObjects.idPoolChild());
}
Also used : ReleaseIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder) 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) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder) Test(org.junit.Test)

Example 15 with AllocateIdInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder in project genius by opendaylight.

the class IdManagerTest method testMultithreadedIdAllocationFromReleaseIds.

@Test
// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
public void testMultithreadedIdAllocationFromReleaseIds() throws Throwable {
    CreateIdPoolInput createIdPoolInput = new CreateIdPoolInputBuilder().setHigh(ID_HIGH).setLow(ID_LOW).setPoolName(ID_POOL_NAME).build();
    AllocateIdInput allocateIdInput = new AllocateIdInputBuilder().setIdKey(TEST_KEY1).setPoolName(ID_POOL_NAME).build();
    idManagerService.createIdPool(createIdPoolInput);
    idManagerService.allocateId(allocateIdInput);
    // Should wait for all job to complete.
    coordinatorEventsWaiter.awaitEventsConsumption();
    String localPoolName = idUtils.getLocalPoolName(ID_POOL_NAME);
    IdPool parentIdPool = new IdPoolBuilder().setPoolName(ID_POOL_NAME).setKey(new IdPoolKey(ID_POOL_NAME)).setReleasedIdsHolder(createReleaseIdHolder(Collections.emptyList())).build();
    IdPool childPool = new IdPoolBuilder().setPoolName(localPoolName).setKey(new IdPoolKey(localPoolName)).setReleasedIdsHolder(createReleaseIdHolder(Arrays.asList(1L, 2L, 3L))).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();
    // Wait for the changes to be available on the caches.
    asyncEventsWaiter.awaitEventsConsumption();
    requestIdsConcurrently(false);
    coordinatorEventsWaiter.awaitEventsConsumption();
    asyncEventsWaiter.awaitEventsConsumption();
    IdPool actualIdPoolChild = getUpdatedActualChildPool();
    IdPool actualIdPoolParent = getUpdatedActualParentPool();
    // Cannot compare the idEntries since we cannot guarantee which idKey gets what value.
    // However the allocated id values uniqueness is verified in requestIdsConcurrently method.
    AssertDataObjects.assertEqualBeans(ExpectedAllocateIdMultipleRequestsFromReleaseIds.idPoolParent().getReleasedIdsHolder(), actualIdPoolParent.getReleasedIdsHolder());
    AssertDataObjects.assertEqualBeans(ExpectedAllocateIdMultipleRequestsFromReleaseIds.idPoolChild(), actualIdPoolChild);
}
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)

Aggregations

AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)30 AllocateIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput)26 ExecutionException (java.util.concurrent.ExecutionException)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)19 AllocateIdOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)18 Test (org.junit.Test)8 CreateIdPoolInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput)5 CreateIdPoolInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)3 IdPoolBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder)3 IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)3 DPNTEPsInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder)3 DPNTEPsInfoKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey)3 TunnelEndPointsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder)3 ArrayList (java.util.ArrayList)2 HwVtep (org.opendaylight.genius.itm.confighelpers.HwVtep)2 ExternalTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel)2 ExternalTunnelKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey)2 TransportZoneBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder)2