Tie SchemaContext.NAME and NetconfUtil.NETCONF_DATA_QNAME 17/83817/9
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Aug 2019 14:58:17 +0000 (16:58 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 28 Aug 2019 15:13:49 +0000 (15:13 +0000)
These are referencing the same entity, except one with revision. Tie
them together so we can document what exactly is mean by these constants.

Change-Id: Ic6e64e1231506ec3a77123165aaf9454aa836c4f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java

index 217f106df265d226478b062ce4a87d80b96d5314..1b267003fb29a524179ce6f083d15a9b2f23eef1 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.util;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.Iterator;
@@ -24,6 +25,8 @@ import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata;
 import org.opendaylight.yangtools.rfc7952.data.util.NormalizedMetadataWriter;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -43,29 +46,41 @@ import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
 public final class NetconfUtil {
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfUtil.class);
 
-    public static final QName NETCONF_QNAME =
-            QName.create("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "netconf").intern();
+    // FIXME: document what exactly this QName means, as it is not referring to a tangible node nor the ietf-module.
+    // FIXME: what is this contract saying?
+    //        - is it saying all data is going to be interpreted with this root?
+    //        - is this saying we are following a specific interface contract (i.e. do we have schema mounts?)
+    //        - is it also inferring some abilities w.r.t. RFC8342?
+    public static final QName NETCONF_QNAME = QName.create(QNameModule.create(SchemaContext.NAME.getNamespace(),
+        Revision.of("2011-06-01")), "netconf").intern();
+    // FIXME: is this the device-bound revision?
     public static final QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data").intern();
     public static final XMLOutputFactory XML_FACTORY;
 
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfUtil.class);
-
     static {
-        XML_FACTORY = XMLOutputFactory.newFactory();
-        XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+        final XMLOutputFactory f = XMLOutputFactory.newFactory();
+        // FIXME: not repairing namespaces is probably common, this should be availabe as common XML constant.
+        f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+        XML_FACTORY = f;
     }
 
-    private NetconfUtil() {}
+    private NetconfUtil() {
+        // No-op
+    }
 
     public static Document checkIsMessageOk(final Document response) throws DocumentedException {
-        XmlElement element = XmlElement.fromDomDocument(response);
-        Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
-        element = element.getOnlyChildElement();
-        if (element.getName().equals(XmlNetconfConstants.OK)) {
+        final XmlElement docElement = XmlElement.fromDomDocument(response);
+        // FIXME: we should throw DocumentedException here
+        checkState(XmlNetconfConstants.RPC_REPLY_KEY.equals(docElement.getName()));
+        final XmlElement element = docElement.getOnlyChildElement();
+        if (XmlNetconfConstants.OK.equals(element.getName())) {
             return response;
         }
+
         LOG.warn("Can not load last configuration. Operation failed.");
+        // FIXME: we should be throwing a DocumentedException here
         throw new IllegalStateException("Can not load last configuration. Operation failed: "
                 + XmlUtil.toString(response));
     }
@@ -145,6 +160,7 @@ public final class NetconfUtil {
         }
     }
 
+    // FIXME: document this interface contract. Does it support RFC8528/RFC8542? How?
     public static NormalizedNodeResult transformDOMSourceToNormalizedNode(final SchemaContext schemaContext,
             final DOMSource value) throws XMLStreamException, URISyntaxException, IOException, SAXException {
         final NormalizedNodeResult resultHolder = new NormalizedNodeResult();