Search in sources :

Example 11 with NodeIdentifier

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

the class NormalizedNodePrunerTest method createTestContainer.

private static NormalizedNode<?, ?> createTestContainer() {
    byte[] bytes1 = { 1, 2, 3 };
    LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build();
    byte[] bytes2 = {};
    LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build();
    return TestModel.createBaseTestContainerBuilder().withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)).withChild(entry1).withChild(entry2).build()).withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[] { 1, 2, 3, 4 })).build();
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)

Example 12 with NodeIdentifier

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

the class NormalizedNodePrunerTest method testLeafSetEntryNodePrunedWhenHasParentAndSchemaMissing.

@Test
public void testLeafSetEntryNodePrunedWhenHasParentAndSchemaMissing() throws IOException {
    NormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.INVALID_QNAME));
    LeafSetEntryNode<Object> child = Builders.leafSetEntryBuilder().withValue("test").withNodeIdentifier(new NodeWithValue<>(TestModel.INVALID_QNAME, "test")).build();
    NormalizedNode<?, ?> input = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.INVALID_QNAME)).withChild(child).build();
    NormalizedNodeWriter.forStreamWriter(pruner).write(input);
    NormalizedNode<?, ?> actual = pruner.normalizedNode();
    assertNull(actual);
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) Test(org.junit.Test)

Example 13 with NodeIdentifier

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

the class ResolveDataChangeState method getListenerChildrenWildcarded.

private static Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> getListenerChildrenWildcarded(final Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> parentNodes, final PathArgument child) {
    if (parentNodes.isEmpty()) {
        return Collections.emptyList();
    }
    final List<RegistrationTreeNode<DataChangeListenerRegistration<?>>> result = new ArrayList<>();
    if (child instanceof NodeWithValue || child instanceof NodeIdentifierWithPredicates) {
        NodeIdentifier wildcardedIdentifier = new NodeIdentifier(child.getNodeType());
        addChildNodes(result, parentNodes, wildcardedIdentifier);
    }
    addChildNodes(result, parentNodes, child);
    return result;
}
Also used : RegistrationTreeNode(org.opendaylight.mdsal.dom.spi.RegistrationTreeNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ArrayList(java.util.ArrayList) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 14 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier 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 15 with NodeIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier 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

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