Search in sources :

Example 26 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier in project controller by opendaylight.

the class SingletonGetConstantService method invokeRpc.

@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull DOMRpcIdentifier rpc, @Nullable NormalizedNode<?, ?> input) {
    LOG.debug("get-singleton-constant invoked, current value: {}", constant);
    final LeafNode<Object> value = ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(CONSTANT)).withValue(constant).build();
    final ContainerNode result = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(OUTPUT)).withChild(value).build();
    return Futures.immediateCheckedFuture(new DefaultDOMRpcResult(result));
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Nonnull(javax.annotation.Nonnull)

Example 27 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier in project controller by opendaylight.

the class DistributedShardFrontendTest method createCrossShardContainer.

private static ContainerNode createCrossShardContainer() {
    final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(createInnerMapNode(1)).build();
    final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).withChild(createInnerMapNode(2)).build();
    final MapNode outerList = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry1).withChild(outerListEntry2).build();
    final ContainerNode testContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
    return testContainer;
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 28 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier in project controller by opendaylight.

the class DistributedShardFrontendTest method testClientTransaction.

@Test
public void testClientTransaction() throws Exception {
    final DistributedDataStore distributedDataStore = mock(DistributedDataStore.class);
    final ActorContext context = mock(ActorContext.class);
    doReturn(context).when(distributedDataStore).getActorContext();
    doReturn(SchemaContextHelper.full()).when(context).getSchemaContext();
    final DistributedShardFrontend rootShard = new DistributedShardFrontend(distributedDataStore, client, ROOT);
    try (DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT))) {
        shardedDOMDataTree.registerDataTreeShard(ROOT, rootShard, producer);
    }
    final DataStoreClient outerListClient = mock(DataStoreClient.class);
    final ClientTransaction outerListClientTransaction = mock(ClientTransaction.class);
    final ClientLocalHistory outerListClientHistory = mock(ClientLocalHistory.class);
    final DOMDataTreeWriteCursor outerListCursor = mock(DOMDataTreeWriteCursor.class);
    doNothing().when(outerListCursor).close();
    doNothing().when(outerListCursor).write(any(), any());
    doNothing().when(outerListCursor).merge(any(), any());
    doNothing().when(outerListCursor).delete(any());
    doReturn(outerListCursor).when(outerListClientTransaction).openCursor();
    doReturn(outerListClientTransaction).when(outerListClient).createTransaction();
    doReturn(outerListClientHistory).when(outerListClient).createLocalHistory();
    doReturn(outerListClientTransaction).when(outerListClientHistory).createTransaction();
    doReturn(commitCohort).when(outerListClientTransaction).ready();
    doNothing().when(outerListClientHistory).close();
    doNothing().when(outerListClient).close();
    final DistributedShardFrontend outerListShard = new DistributedShardFrontend(distributedDataStore, outerListClient, OUTER_LIST_ID);
    try (DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(OUTER_LIST_ID))) {
        shardedDOMDataTree.registerDataTreeShard(OUTER_LIST_ID, outerListShard, producer);
    }
    final DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT));
    final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false);
    final DOMDataTreeWriteCursor txCursor = tx.createCursor(ROOT);
    assertNotNull(txCursor);
    txCursor.write(TestModel.TEST_PATH.getLastPathArgument(), createCrossShardContainer());
    // check the lower shard got the correct modification
    verify(outerListCursor, times(2)).write(pathArgumentCaptor.capture(), nodeCaptor.capture());
    final YangInstanceIdentifier.PathArgument expectedYid = new NodeIdentifier(TestModel.ID_QNAME);
    final YangInstanceIdentifier.PathArgument actualIdYid = pathArgumentCaptor.getAllValues().get(0);
    assertEquals(expectedYid, actualIdYid);
    final YangInstanceIdentifier.PathArgument expectedInnerYid = new NodeIdentifier(TestModel.INNER_LIST_QNAME);
    final YangInstanceIdentifier.PathArgument actualInnerListYid = pathArgumentCaptor.getAllValues().get(1);
    assertEquals(expectedInnerYid, actualInnerListYid);
    final LeafNode<Integer> actualIdNode = (LeafNode<Integer>) nodeCaptor.getAllValues().get(0);
    assertEquals(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1), actualIdNode);
    final MapNode actualInnerListNode = (MapNode) nodeCaptor.getAllValues().get(1);
    assertEquals(createInnerMapNode(1), actualInnerListNode);
    txCursor.close();
    tx.submit().checkedGet();
    verify(commitCohort, times(2)).canCommit();
    verify(commitCohort, times(2)).preCommit();
    verify(commitCohort, times(2)).commit();
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) ClientTransaction(org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataStoreClient(org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientLocalHistory(org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory) DistributedDataStore(org.opendaylight.controller.cluster.datastore.DistributedDataStore) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) Test(org.junit.Test)

Example 29 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier in project controller by opendaylight.

the class DistributedShardedDOMDataTreeRemotingTest method testWriteIntoMultipleShards.

@Test
public void testWriteIntoMultipleShards() throws Exception {
    LOG.info("testWriteIntoMultipleShards starting");
    initEmptyDatastores();
    leaderTestKit.waitForMembersUp("member-2");
    LOG.debug("registering first shard");
    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()));
    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);
    LOG.debug("Got after waiting for nonleader");
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
    final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(TEST_ID);
    Assert.assertNotNull(cursor);
    final YangInstanceIdentifier nameId = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.NAME_QNAME).build();
    cursor.write(nameId.getLastPathArgument(), ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.NAME_QNAME)).withValue("Test Value").build());
    cursor.close();
    LOG.warn("Got to pre submit");
    tx.submit().checkedGet();
    shardRegistration.close().toCompletableFuture().get();
    LOG.info("testWriteIntoMultipleShards ending");
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) AddressFromURIString(akka.actor.AddressFromURIString) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 30 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier in project controller by opendaylight.

the class DistributedShardedDOMDataTreeTest method testMultipleWritesIntoSingleMapEntry.

@Test
public void testMultipleWritesIntoSingleMapEntry() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration shardRegistration = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
    LOG.warn("Got after waiting for nonleader");
    final ActorRef leaderShardManager = leaderDistributedDataStore.getActorContext().getShardManager();
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
    final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
    final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
    final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(Collections.singletonList(outerListPath));
    final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
    assertNotNull(cursor);
    MapNode innerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME)).build();
    cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
    cursor.close();
    tx.submit().checkedGet();
    final ArrayList<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
        for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
            final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
            final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
            cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
            cursor1.close();
            futures.add(tx1.submit());
        }
    }
    futures.get(futures.size() - 1).checkedGet();
    final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
    doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
    leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID), true, Collections.emptyList());
    verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
    verifyNoMoreInteractions(mockedDataTreeListener);
    final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
    final NormalizedNode<?, ?> expected = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME)).withValue(createInnerListMapEntries(1000, "run-999")).build();
    assertEquals("List values dont match the expected values from the last run", expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) ActorRef(akka.actor.ActorRef) 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) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) Matchers.anyCollection(org.mockito.Matchers.anyCollection) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Aggregations

NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)58 Test (org.junit.Test)34 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)29 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)11 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)10 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)8 ByteBuf (io.netty.buffer.ByteBuf)7 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)7 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)7 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)6 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)6 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)5 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)5 BigInteger (java.math.BigInteger)4 ClientTransaction (org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction)4 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)4 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)4