Search in sources :

Example 31 with PathArgument

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

the class AbstractDOMStoreTreeChangePublisher method lookupAndNotify.

private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate) {
    if (args.size() != offset) {
        final PathArgument arg = args.get(offset);
        final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg);
        if (exactChild != null) {
            lookupAndNotify(args, offset + 1, exactChild, candidate);
        }
        for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) {
            lookupAndNotify(args, offset + 1, c, candidate);
        }
    } else {
        notifyNode(candidate.getRootPath(), node, candidate.getRootNode());
    }
}
Also used : AbstractDOMDataTreeChangeListenerRegistration(org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 32 with PathArgument

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

the class AbstractEntityOwnershipTest method getMapEntryNodeChild.

protected MapEntryNode getMapEntryNodeChild(final DataContainerNode<? extends PathArgument> parent, final QName childMap, final QName child, final Object key, final boolean expectPresent) {
    Optional<DataContainerChild<? extends PathArgument, ?>> childNode = parent.getChild(new NodeIdentifier(childMap));
    assertEquals("Missing " + childMap.toString(), true, childNode.isPresent());
    MapNode entityTypeMapNode = (MapNode) childNode.get();
    Optional<MapEntryNode> entityTypeEntry = entityTypeMapNode.getChild(new NodeIdentifierWithPredicates(childMap, child, key));
    if (expectPresent && !entityTypeEntry.isPresent()) {
        fail("Missing " + childMap.toString() + " entry for " + key + ". Actual: " + entityTypeMapNode.getValue());
    } else if (!expectPresent && entityTypeEntry.isPresent()) {
        fail("Found unexpected " + childMap.toString() + " entry for " + key);
    }
    return entityTypeEntry.isPresent() ? entityTypeEntry.get() : null;
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 33 with PathArgument

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

the class AbstractShardTest method testRecovery.

protected void testRecovery(final Set<Integer> listEntryKeys) throws Exception {
    // Create the actor and wait for recovery complete.
    final int nListEntries = listEntryKeys.size();
    final CountDownLatch recoveryComplete = new CountDownLatch(1);
    final Creator<Shard> creator = () -> new Shard(newShardBuilder()) {

        @Override
        protected void onRecoveryComplete() {
            try {
                super.onRecoveryComplete();
            } finally {
                recoveryComplete.countDown();
            }
        }
    };
    final TestActorRef<Shard> shard = TestActorRef.create(getSystem(), Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testRecovery");
    assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS));
    // Verify data in the data store.
    final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
    assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
    assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable", outerList.getValue() instanceof Iterable);
    for (final Object entry : (Iterable<?>) outerList.getValue()) {
        assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode", entry instanceof MapEntryNode);
        final MapEntryNode mapEntry = (MapEntryNode) entry;
        final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf = mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
        assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
        final Object value = idLeaf.get().getValue();
        assertTrue("Unexpected value for leaf " + TestModel.ID_QNAME.getLocalName() + ": " + value, listEntryKeys.remove(value));
    }
    if (!listEntryKeys.isEmpty()) {
        fail("Missing " + TestModel.OUTER_LIST_QNAME.getLocalName() + " entries with keys: " + listEntryKeys);
    }
    assertEquals("Last log index", nListEntries, shard.underlyingActor().getShardMBean().getLastLogIndex());
    assertEquals("Commit index", nListEntries, shard.underlyingActor().getShardMBean().getCommitIndex());
    assertEquals("Last applied", nListEntries, shard.underlyingActor().getShardMBean().getLastApplied());
    shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 34 with PathArgument

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

the class AbstractShardTest method verifyOuterListEntry.

@SuppressWarnings("unchecked")
static void verifyOuterListEntry(final TestActorRef<Shard> shard, final Object expIDValue) throws Exception {
    final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
    assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
    assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable", outerList.getValue() instanceof Iterable);
    final Object entry = ((Iterable<Object>) outerList.getValue()).iterator().next();
    assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode", entry instanceof MapEntryNode);
    final MapEntryNode mapEntry = (MapEntryNode) entry;
    final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf = mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
    assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
    assertEquals(TestModel.ID_QNAME.getLocalName() + " value", expIDValue, idLeaf.get().getValue());
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 35 with PathArgument

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

the class NormalizedNodeStreamReaderWriterTest method testAnyXmlStreaming.

@Test
public void testAnyXmlStreaming() throws Exception {
    String xml = "<foo xmlns=\"http://www.w3.org/TR/html4/\" x=\"123\"><bar>one</bar><bar>two</bar></foo>";
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    Node xmlNode = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))).getDocumentElement();
    assertEquals("http://www.w3.org/TR/html4/", xmlNode.getNamespaceURI());
    NormalizedNode<?, ?> anyXmlContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)).withValue(new DOMSource(xmlNode)).build()).build();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
    nnout.writeNormalizedNode(anyXmlContainer);
    NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bos.toByteArray()));
    ContainerNode deserialized = (ContainerNode) nnin.readNormalizedNode();
    Optional<DataContainerChild<? extends PathArgument, ?>> child = deserialized.getChild(new NodeIdentifier(TestModel.ANY_XML_QNAME));
    assertEquals("AnyXml child present", true, child.isPresent());
    StreamResult xmlOutput = new StreamResult(new StringWriter());
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.transform(((AnyXmlNode) child.get()).getValue(), xmlOutput);
    assertEquals("XML", xml, xmlOutput.getWriter().toString());
    assertEquals("http://www.w3.org/TR/html4/", ((AnyXmlNode) child.get()).getValue().getNode().getNamespaceURI());
}
Also used : InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) AnyXmlNode(org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode) Node(org.w3c.dom.Node) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) StringWriter(java.io.StringWriter) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) StringReader(java.io.StringReader) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) Test(org.junit.Test)

Aggregations

PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)55 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)31 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)18 ArrayList (java.util.ArrayList)17 Set (java.util.Set)12 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)11 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 Test (org.junit.Test)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 DataNormalizationException (org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)3 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)3 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)3 ImmutableList (com.google.common.collect.ImmutableList)2 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)2 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)2