Search in sources :

Example 31 with NormalizedNode

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

the class TxchainDomRead method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
        for (int l = 0; l < outerListElem; l++) {
            YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
            Optional<NormalizedNode<?, ?>> optionalDataObject;
            CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
            try {
                optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    txOk++;
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 32 with NormalizedNode

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

the class PruningDataTreeModificationTest method testWriteRootNode.

@Test
public void testWriteRootNode() throws Exception {
    final DataTree localDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
    DataTreeModification mod = localDataTree.takeSnapshot().newModification();
    mod.write(CarsModel.BASE_PATH, CarsModel.create());
    mod.ready();
    localDataTree.validate(mod);
    localDataTree.commit(localDataTree.prepare(mod));
    NormalizedNode<?, ?> normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get();
    pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
    dataTree.commit(getCandidate());
    Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
    assertTrue("Root present", actual.isPresent());
    assertEquals("Root node", normalizedNode, actual.get());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardDataTree(org.opendaylight.controller.cluster.datastore.ShardDataTree) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 33 with NormalizedNode

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

the class PruningDataTreeModificationTest method testWriteWithInvalidChildNodeNames.

@Test
public void testWriteWithInvalidChildNodeNames() throws DataValidationFailedException {
    ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild(ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build();
    DataContainerChild<?, ?> outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two")));
    ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build();
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    pruningDataTreeModification.write(path, normalizedNode);
    dataTree.commit(getCandidate());
    ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build();
    Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(path);
    assertTrue("After pruning present", actual.isPresent());
    assertEquals("After pruning", prunedNode, actual.get());
}
Also used : ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 34 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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 35 with NormalizedNode

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

the class NormalizedNodeAggregatorTest method testAggregate.

@Test
public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException, DataValidationFailedException {
    SchemaContext schemaContext = SchemaContextHelper.full();
    NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
    Optional<NormalizedNode<?, ?>> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY, ImmutableList.of(Optional.<NormalizedNode<?, ?>>of(getRootNode(expectedNode1, schemaContext)), Optional.<NormalizedNode<?, ?>>of(getRootNode(expectedNode2, schemaContext))), schemaContext, LogicalDatastoreType.CONFIGURATION);
    NormalizedNode<?, ?> normalizedNode = optional.get();
    assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
    @SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
    for (NormalizedNode<?, ?> node : collection) {
        assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
    }
    assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", findChildWithQName(collection, TestModel.TEST_QNAME) != null);
    assertEquals(expectedNode1, findChildWithQName(collection, TestModel.TEST_QNAME));
    assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
    assertEquals(expectedNode2, findChildWithQName(collection, CarsModel.BASE_QNAME));
}
Also used : Collection(java.util.Collection) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)94 Test (org.junit.Test)55 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)39 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 Optional (com.google.common.base.Optional)15 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 ActorRef (akka.actor.ActorRef)8 InOrder (org.mockito.InOrder)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)8 ExecutionException (java.util.concurrent.ExecutionException)7 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 Map (java.util.Map)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6