Search in sources :

Example 1 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTree method createShardFrontend.

private void createShardFrontend(final DOMDataTreeIdentifier prefix) {
    LOG.debug("{}: Creating CDS shard for prefix: {}", memberName, prefix);
    final String shardName = ClusterUtils.getCleanShardName(prefix.getRootIdentifier());
    final AbstractDataStore distributedDataStore = prefix.getDatastoreType().equals(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION) ? distributedConfigDatastore : distributedOperDatastore;
    try (DOMDataTreeProducer producer = localCreateProducer(Collections.singletonList(prefix))) {
        final Entry<DataStoreClient, ActorRef> entry = createDatastoreClient(shardName, distributedDataStore.getActorContext());
        final DistributedShardFrontend shard = new DistributedShardFrontend(distributedDataStore, entry.getKey(), prefix);
        final DOMDataTreeShardRegistration<DOMDataTreeShard> reg = shardedDOMDataTree.registerDataTreeShard(prefix, shard, producer);
        synchronized (shards) {
            shards.store(prefix, reg);
        }
    } catch (final DOMDataTreeShardingConflictException e) {
        LOG.error("{}: Prefix {} is already occupied by another shard", distributedConfigDatastore.getActorContext().getClusterWrapper().getCurrentMemberName(), prefix, e);
    } catch (DOMDataTreeProducerException e) {
        LOG.error("Unable to close producer", e);
    } catch (DOMDataTreeShardCreationFailedException e) {
        LOG.error("Unable to create datastore client for shard {}", prefix, e);
    }
}
Also used : DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) ActorRef(akka.actor.ActorRef) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) DOMDataTreeShard(org.opendaylight.mdsal.dom.api.DOMDataTreeShard) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) DataStoreClient(org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)

Example 2 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTree method createProducer.

@Nonnull
@Override
public DOMDataTreeProducer createProducer(@Nonnull final Collection<DOMDataTreeIdentifier> subtrees) {
    LOG.debug("{} - Creating producer for {}", memberName, subtrees);
    final DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(subtrees);
    final Object response = distributedConfigDatastore.getActorContext().executeOperation(shardedDataTreeActor, new ProducerCreated(subtrees));
    if (response == null) {
        LOG.debug("{} - Received success from remote nodes, creating producer:{}", memberName, subtrees);
        return new ProxyProducer(producer, subtrees, shardedDataTreeActor, distributedConfigDatastore.getActorContext(), shards);
    }
    closeProducer(producer);
    if (response instanceof Throwable) {
        Throwables.throwIfUnchecked((Throwable) response);
        throw new RuntimeException((Throwable) response);
    }
    throw new RuntimeException("Unexpected response to create producer received." + response);
}
Also used : ProducerCreated(org.opendaylight.controller.cluster.sharding.messages.ProducerCreated) ForwardingObject(com.google.common.collect.ForwardingObject) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) Nonnull(javax.annotation.Nonnull)

Example 3 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTreeRemotingTest method testProducerRegistrations.

@Test
public void testProducerRegistrations() throws Exception {
    LOG.info("testProducerRegistrations starting");
    initEmptyDatastores();
    leaderTestKit.waitForMembersUp("member-2");
    // TODO refactor shard creation and verification to own method
    final DistributedShardRegistration shardRegistration = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
    final ActorRef leaderShardManager = leaderConfigDatastore.getActorContext().getShardManager();
    assertNotNull(findLocalShard(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
    assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
    final Set<String> peers = new HashSet<>();
    IntegrationTestKit.verifyShardState(leaderConfigDatastore, ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState -> peers.addAll(onDemandShardState.getPeerAddresses().values()));
    assertEquals(peers.size(), 1);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
    try {
        followerShardFactory.createProducer(Collections.singleton(TEST_ID));
        fail("Producer should be already registered on the other node");
    } catch (final IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("is attached to producer"));
    }
    producer.close();
    final DOMDataTreeProducer followerProducer = followerShardFactory.createProducer(Collections.singleton(TEST_ID));
    try {
        leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
        fail("Producer should be already registered on the other node");
    } catch (final IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("is attached to producer"));
    }
    followerProducer.close();
    // try to create a shard on an already registered prefix on follower
    try {
        waitOnAsyncTask(followerShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
        fail("This prefix already should have a shard registration that was forwarded from the other node");
    } catch (final DOMDataTreeShardingConflictException e) {
        assertTrue(e.getMessage().contains("is already occupied by another shard"));
    }
    shardRegistration.close().toCompletableFuture().get();
    LOG.info("testProducerRegistrations ending");
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) ActorRef(akka.actor.ActorRef) AddressFromURIString(akka.actor.AddressFromURIString) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 4 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTreeTest method testMultipleShardLevels.

// top level shard at TEST element, with subshards on each outer-list map entry
@Test
@Ignore
public void testMultipleShardLevels() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration testShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
    final int listSize = 5;
    for (int i = 0; i < listSize; i++) {
        final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
        final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
        registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
    }
    final DOMDataTreeIdentifier rootId = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(rootId));
    DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
    DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
    assertNotNull(cursor);
    final MapNode outerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
    final ContainerNode testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
    cursor.write(testNode.getIdentifier(), testNode);
    cursor.close();
    transaction.submit().checkedGet();
    final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
    doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
    final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build();
    transaction = producer.createTransaction(false);
    cursor = transaction.createCursor(TEST_ID);
    assertNotNull(cursor);
    cursor.write(wholeList.getIdentifier(), wholeList);
    cursor.close();
    transaction.submit().checkedGet();
    leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList());
    verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
    verifyNoMoreInteractions(mockedDataTreeListener);
    final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
    final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
    final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
    assertNotNull(actual);
    final NormalizedNode<?, ?> expected = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build()).build();
    for (final DistributedShardRegistration registration : registrations) {
        waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    }
    waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    assertEquals(expected, actual);
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) DOMDataTreeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeListener) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 5 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTreeTest method testWritesIntoDefaultShard.

@Test
public void testWritesIntoDefaultShard() throws Exception {
    initEmptyDatastores();
    final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
    final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
    Assert.assertNotNull(cursor);
    final ContainerNode test = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
    cursor.write(test.getIdentifier(), test);
    cursor.close();
    tx.submit().checkedGet();
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Aggregations

DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)12 Test (org.junit.Test)8 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)8 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)8 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)6 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)6 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)6 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)5 ActorRef (akka.actor.ActorRef)4 AddressFromURIString (akka.actor.AddressFromURIString)3 DataStoreClient (org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)3 DOMDataTreeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeListener)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Matchers.anyCollection (org.mockito.Matchers.anyCollection)2 ClientLocalHistory (org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory)2