Search in sources :

Example 1 with CDSShardAccess

use of org.opendaylight.controller.cluster.dom.api.CDSShardAccess in project controller by opendaylight.

the class DistributedShardedDOMDataTreeTest method testCDSDataTreeProducer.

@Test
public void testCDSDataTreeProducer() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
    final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
    assertTrue(producer instanceof CDSDataTreeProducer);
    final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
    CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
    assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
    shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
    assertEquals(TEST_ID, shardAccess.getShardIdentifier());
    shardAccess = cdsProducer.getShardAccess(configRoot);
    assertEquals(configRoot, shardAccess.getShardIdentifier());
    waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) CDSShardAccess(org.opendaylight.controller.cluster.dom.api.CDSShardAccess) CDSDataTreeProducer(org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 2 with CDSShardAccess

use of org.opendaylight.controller.cluster.dom.api.CDSShardAccess in project controller by opendaylight.

the class PrefixLeaderHandler method makeLeaderLocal.

public ListenableFuture<RpcResult<Void>> makeLeaderLocal(final BecomePrefixLeaderInput input) {
    final YangInstanceIdentifier yid = serializer.toYangInstanceIdentifier(input.getPrefix());
    final DOMDataTreeIdentifier prefix = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yid);
    try (CDSDataTreeProducer producer = (CDSDataTreeProducer) domDataTreeService.createProducer(Collections.singleton(prefix))) {
        final CDSShardAccess shardAccess = producer.getShardAccess(prefix);
        final CompletionStage<Void> completionStage = shardAccess.makeLeaderLocal();
        completionStage.exceptionally(throwable -> {
            LOG.error("Leader movement failed.", throwable);
            return null;
        });
    } catch (final DOMDataTreeProducerException e) {
        LOG.warn("Error while closing producer", e);
    } catch (final TimeoutException e) {
        LOG.warn("Timeout while on producer operation", e);
        Futures.immediateFuture(RpcResultBuilder.failed().withError(RpcError.ErrorType.RPC, "resource-denied-transport", "Timeout while opening producer please retry.", "clustering-it", "clustering-it", e));
    }
    return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}
Also used : DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CDSShardAccess(org.opendaylight.controller.cluster.dom.api.CDSShardAccess) CDSDataTreeProducer(org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer) TimeoutException(org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException)

Aggregations

CDSDataTreeProducer (org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer)2 CDSShardAccess (org.opendaylight.controller.cluster.dom.api.CDSShardAccess)2 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)2 Test (org.junit.Test)1 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)1 TimeoutException (org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException)1 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)1 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)1 DOMDataTreeProducerException (org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1