From: Robert Varga Date: Tue, 20 Aug 2019 14:58:17 +0000 (+0200) Subject: Tie SchemaContext.NAME and NetconfUtil.NETCONF_DATA_QNAME X-Git-Tag: release/magnesium~53 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=14a6b924a2042d6fc374aedf2909edbe1c8f63e7;p=netconf.git Tie SchemaContext.NAME and NetconfUtil.NETCONF_DATA_QNAME 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 --- diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java index 217f106df2..1b267003fb 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java @@ -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();