X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fmapping%2Fconfig%2FInstanceConfig.java;h=ff1d719c57877c2df4710701d9d6f0bd65075b07;hb=1895c1473b803a53ad5e2a092c4dacb4ffed2ee2;hp=cf9b4c159746e15434be1096d0caf946e2417ec3;hpb=8720a3f3498bbc6fab675431f4200d26641a8ec8;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java index cf9b4c1597..ff1d719c57 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/InstanceConfig.java @@ -34,6 +34,7 @@ import org.opendaylight.controller.netconf.confignetconfconnector.operations.edi import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -43,11 +44,15 @@ public final class InstanceConfig { private static final Logger logger = LoggerFactory.getLogger(InstanceConfig.class); private final Map yangToAttrConfig; + private final String nullableDummyContainerName; private final Map jmxToAttrConfig; private final ConfigRegistryClient configRegistryClient; - public InstanceConfig(ConfigRegistryClient configRegistryClient, Map yangNamesToAttributes) { + public InstanceConfig(ConfigRegistryClient configRegistryClient, Map yangNamesToAttributes, + String nullableDummyContainerName) { + this.yangToAttrConfig = yangNamesToAttributes; + this.nullableDummyContainerName = nullableDummyContainerName; this.jmxToAttrConfig = reverseMap(yangNamesToAttributes); this.configRegistryClient = configRegistryClient; } @@ -83,20 +88,24 @@ public final class InstanceConfig { } public Element toXml(ObjectName on, String namespace, Document document, Element rootElement) { - Map strats = new ObjectXmlWriter().prepareWriting(yangToAttrConfig, document); - Map mappedConfig = getMappedConfiguration(on); - + Element parentElement; + if (nullableDummyContainerName != null) { + Element dummyElement = XmlUtil.createElement(document, nullableDummyContainerName, Optional.of(namespace)); + rootElement.appendChild(dummyElement); + parentElement = dummyElement; + } else { + parentElement = rootElement; + } for (Entry mappingEntry : mappedConfig.entrySet()) { try { - strats.get(mappingEntry.getKey()).writeElement(rootElement, namespace, mappingEntry.getValue()); + strats.get(mappingEntry.getKey()).writeElement(parentElement, namespace, mappingEntry.getValue()); } catch (Exception e) { throw new IllegalStateException("Unable to write value " + mappingEntry.getValue() + " for attribute " + mappingEntry.getValue(), e); } } - return rootElement; } @@ -132,22 +141,46 @@ public final class InstanceConfig { Map strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap); List recognisedChildren = Lists.newArrayList(); - XmlElement type; - XmlElement name; - type = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY); - name = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY); - List typeAndName = Lists.newArrayList(type, name); + XmlElement typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY); + XmlElement nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY); + List typeAndNameElements = Lists.newArrayList(typeElement, nameElement); + + // if dummy container was defined in yang, set moduleElement to its content + if (nullableDummyContainerName != null) { + int size = moduleElement.getChildElements().size(); + int expectedChildNodes = 1 + typeAndNameElements.size(); + if (size > expectedChildNodes) { + throw new NetconfDocumentedException("Error reading module " + typeElement.getTextContent() + " : " + + nameElement.getTextContent() + " - Expected " + expectedChildNodes +" child nodes, " + + "one of them with name " + nullableDummyContainerName + + ", got " + size + " elements."); + } + if (size == expectedChildNodes) { + try { + moduleElement = moduleElement.getOnlyChildElement(nullableDummyContainerName, moduleNamespace); + } catch (NetconfDocumentedException e) { + throw new NetconfDocumentedException("Error reading module " + typeElement.getTextContent() + " : " + + nameElement.getTextContent() + " - Expected child node with name " + nullableDummyContainerName + + "." + e.getMessage()); + } + } // else 2 elements, no need to descend + } for (Entry readStratEntry : strats.entrySet()) { List configNodes = getConfigNodes(moduleElement, moduleNamespace, readStratEntry.getKey(), - recognisedChildren, typeAndName); + recognisedChildren, typeAndNameElements); AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes); retVal.put(readStratEntry.getKey(), readElement); } - recognisedChildren.addAll(typeAndName); - moduleElement.checkUnrecognisedElements(recognisedChildren); - + recognisedChildren.addAll(typeAndNameElements); + try { + moduleElement.checkUnrecognisedElements(recognisedChildren); + } catch (NetconfDocumentedException e) { + throw new NetconfDocumentedException("Error reading module " + typeElement.getTextContent() + " : " + + nameElement.getTextContent() + " - " + + e.getMessage(), e.getErrorType(), e.getErrorTag(),e.getErrorSeverity(),e.getErrorInfo()); + } // TODO: add check for conflicts between global and local edit strategy String perInstanceEditStrategy = moduleElement.getAttribute(XmlNetconfConstants.OPERATION_ATTR_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);