Search in sources :

Example 1 with MapNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.

the class EntityOwnershipShard method getCandidateNames.

private static Collection<String> getCandidateNames(final MapEntryNode entity) {
    Collection<MapEntryNode> candidates = ((MapNode) entity.getChild(CANDIDATE_NODE_ID).get()).getValue();
    Collection<String> candidateNames = new ArrayList<>(candidates.size());
    for (MapEntryNode candidate : candidates) {
        candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
    }
    return candidateNames;
}
Also used : ArrayList(java.util.ArrayList) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 2 with MapNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.

the class ShardTest method testReadyLocalTransactionWithThreePhaseCommit.

@Test
public void testReadyLocalTransactionWithThreePhaseCommit() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testReadyLocalTransactionWithThreePhaseCommit");
            waitUntilLeader(shard);
            final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
            final DataTreeModification modification = dataStore.newModification();
            final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
            final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
            new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
            final TransactionIdentifier txId = nextTransactionId();
            modification.ready();
            final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, false);
            shard.tell(readyMessage, getRef());
            expectMsgClass(ReadyTransactionReply.class);
            // Send the CanCommitTransaction message.
            shard.tell(new CanCommitTransaction(txId, CURRENT_VERSION).toSerializable(), getRef());
            final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(CanCommitTransactionReply.class));
            assertEquals("Can commit", true, canCommitReply.getCanCommit());
            // Send the CanCommitTransaction message.
            shard.tell(new CommitTransaction(txId, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(CommitTransactionReply.class);
            final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
            assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 3 with MapNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.

the class ShardTest method testReadyLocalTransactionWithImmediateCommit.

@Test
public void testReadyLocalTransactionWithImmediateCommit() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testReadyLocalTransactionWithImmediateCommit");
            waitUntilLeader(shard);
            final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
            final DataTreeModification modification = dataStore.newModification();
            final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
            final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
            new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
            final TransactionIdentifier txId = nextTransactionId();
            modification.ready();
            final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
            shard.tell(readyMessage, getRef());
            expectMsgClass(CommitTransactionReply.class);
            final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
            assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) Test(org.junit.Test)

Example 4 with MapNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testTransactionChainWithSingleShard.

@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionChainWithSingleShard() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testTransactionChainWithSingleShard", "test-1")) {
                // 1. Create a Tx chain and write-only Tx
                final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
                final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
                // 2. Write some data
                final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
                writeTx.write(TestModel.TEST_PATH, testNode);
                // 3. Ready the Tx for commit
                final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
                // 4. Commit the Tx on another thread that first waits for
                // the second read Tx.
                final CountDownLatch continueCommit1 = new CountDownLatch(1);
                final CountDownLatch commit1Done = new CountDownLatch(1);
                final AtomicReference<Exception> commit1Error = new AtomicReference<>();
                new Thread(() -> {
                    try {
                        continueCommit1.await();
                        doCommit(cohort1);
                    } catch (Exception e) {
                        commit1Error.set(e);
                    } finally {
                        commit1Done.countDown();
                    }
                }).start();
                // 5. Create a new read Tx from the chain to read and verify
                // the data from the first
                // Tx is visible after being readied.
                DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
                Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", testNode, optional.get());
                // 6. Create a new RW Tx from the chain, write more data,
                // and ready it
                final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
                final MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
                rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
                final DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
                // 7. Create a new read Tx from the chain to read the data
                // from the last RW Tx to
                // verify it is visible.
                readTx = txChain.newReadWriteTransaction();
                optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", outerNode, optional.get());
                // 8. Wait for the 2 commits to complete and close the
                // chain.
                continueCommit1.countDown();
                Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
                if (commit1Error.get() != null) {
                    throw commit1Error.get();
                }
                doCommit(cohort2);
                txChain.close();
                // 9. Create a new read Tx from the data store and verify
                // committed data.
                readTx = dataStore.newReadOnlyTransaction();
                optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", outerNode, optional.get());
            }
        }
    };
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TransactionChainClosedException(org.opendaylight.mdsal.common.api.TransactionChainClosedException) RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) IOException(java.io.IOException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 5 with MapNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapNode in project controller by opendaylight.

the class NormalizedNodePrunerTest method testInnerListNodeWithFullPathPrunedWhenSchemaMissing.

@Test
public void testInnerListNodeWithFullPathPrunedWhenSchemaMissing() throws IOException {
    YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME).node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).node(TestModel.INVALID_QNAME).build();
    NormalizedNodePruner pruner = prunerFullSchema(path);
    MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder(TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild(ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build();
    NormalizedNodeWriter.forStreamWriter(pruner).write(input);
    NormalizedNode<?, ?> actual = pruner.normalizedNode();
    assertNull(actual);
}
Also used : MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)29 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)17 Test (org.junit.Test)12 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)12 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)8 ExecutionException (java.util.concurrent.ExecutionException)6 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)5 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)5 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)3 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)3 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)3 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)3 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3