Updated xml generated by get netconf operation to conform to yang schema in config-api 89/3089/3
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 26 Nov 2013 09:15:54 +0000 (10:15 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Tue, 26 Nov 2013 09:41:44 +0000 (10:41 +0100)
Change-Id: I0f7526369840eb83fdd83aba2459365ccbd9fd16
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/runtime/InstanceRuntime.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/runtime/ModuleRuntime.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/runtime/Runtime.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java

index 9d348d0985518c2595445f89c73a69e74bcb93ca..70b10d00191cd04c01e83dee8be44fd0c4db0f9d 100644 (file)
@@ -12,7 +12,6 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Sets;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
-import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -83,15 +82,14 @@ public class InstanceRuntime {
         }));
     }
 
-    public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document) {
-        return toXml(rootOn, childRbeOns, document, null, null);
+    public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, Element parentElement, String namespace) {
+        return toXml(rootOn, childRbeOns, document, null, parentElement, namespace);
     }
 
     public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, String instanceIndex,
-            String keyName) {
-        Element xml = document.createElement(keyName == null ? XmlNetconfConstants.DATA_KEY : keyName);
+                         Element parentElement, String namespace) {
         // TODO namespace
-        xml = instanceMapping.toXml(rootOn, null, "namespace", document, xml);
+        Element xml = instanceMapping.toXml(rootOn, null, namespace, document, parentElement);
 
         if (instanceIndex != null) {
             xml.setAttribute(KEY_ATTRIBUTE_KEY, instanceIndex);
@@ -106,8 +104,11 @@ public class InstanceRuntime {
                 String runtimeInstanceIndex = objectName.getKeyProperty(childMappingEntry.getKey());
 
                 String elementName = jmxToYangChildRbeMapping.get(childMappingEntry.getKey());
-                xml.appendChild(childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document,
-                        runtimeInstanceIndex, elementName));
+
+                Element innerXml = document.createElement(elementName);
+                childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document,
+                        runtimeInstanceIndex, innerXml, namespace);
+                xml.appendChild(innerXml);
             }
         }
 
index 07da65ed19b548646234b11f8aa2a7cbb9c7e70d..4dbfba119f865980daf18ac49b3564bfddff996c 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
 
-import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
@@ -41,31 +40,30 @@ public class ModuleRuntime {
         throw new IllegalStateException("Root runtime bean not found among " + runtimeBeanOns);
     }
 
-    public Element toXml(String namespace, Multimap<String, ObjectName> instances, Document document) {
-        Element root = document.createElement(XmlNetconfConstants.MODULE_KEY);
-        XmlUtil.addNamespaceAttr(root, namespace);
+    public Element toXml(String namespace, String instanceName, Collection<ObjectName> runtimeBeanOns, Document document) {
+        Element moduleElement = document.createElement(XmlNetconfConstants.MODULE_KEY);
 
-        Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, moduleName);
-        root.appendChild(nameElement);
+        final String prefix = getPrefix(namespace);
+        Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlNetconfConstants.TYPE_KEY, prefix,
+                moduleName);
+        XmlUtil.addPrefixedNamespaceAttr(typeElement, prefix, namespace);
+        moduleElement.appendChild(typeElement);
 
-        for (String instanceName : instances.keySet()) {
-            Element instance = document.createElement(XmlNetconfConstants.INSTANCE_KEY);
+        Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, instanceName);
+        moduleElement.appendChild(nameElement);
 
-            Element innerNameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, instanceName);
-            instance.appendChild(innerNameElement);
+        ObjectName rootName = findRoot(runtimeBeanOns);
 
-            Collection<ObjectName> runtimeBeanOns = instances.get(instanceName);
-            ObjectName rootName = findRoot(runtimeBeanOns);
+        Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
+        childrenRuntimeBeans.remove(rootName);
 
-            Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
-            childrenRuntimeBeans.remove(rootName);
+        instanceRuntime.toXml(rootName, childrenRuntimeBeans, document, moduleElement, namespace);
 
-            instance.appendChild(instanceRuntime.toXml(rootName, childrenRuntimeBeans, document));
-
-            root.appendChild(instance);
-        }
+        return moduleElement;
+    }
 
-        return root;
+    private String getPrefix(String namespace) {
+        return XmlNetconfConstants.PREFIX;
     }
 
 }
index da281269e63275b3b11c55f3aa4d439784f83469..8af1e0ee90e94fe7c009eb93ece4b1f478b16d4f 100644 (file)
@@ -66,9 +66,12 @@ public class Runtime {
                 if (instanceToRbe == null)
                     continue;
 
-                ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
-                Element innerXml = moduleRuntime.toXml(localNamespace, instanceToRbe, document);
-                modulesElement.appendChild(innerXml);
+                for (String instanceName : instanceToRbe.keySet()) {
+                    ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
+                    Element innerXml = moduleRuntime.toXml(localNamespace, instanceName, instanceToRbe.get(instanceName), document);
+                    modulesElement.appendChild(innerXml);
+                }
+
             }
         }
 
index de0ecdbf1e2a448a82c001462b3dd9db46f2aba1..296b224fffbbc2e33fccc898dd78dcd204267d46 100644 (file)
@@ -441,7 +441,9 @@ public class NetconfMappingTest extends AbstractConfigTest {
 
         Element response = get();
 
-        assertEquals(2, getElementsSize(response, "instance"));
+        System.err.println(XmlUtil.toString(response));
+
+        assertEquals(2, getElementsSize(response, "module"));
         assertEquals(2, getElementsSize(response, "asdf"));
         assertEquals(5, getElementsSize(response, "inner-running-data"));
         assertEquals(5, getElementsSize(response, "deep2"));