Updated xpath pointing to a module instance under services subtree. 05/3505/1
authorMaros Marsalek <mmarsale@cisco.com>
Thu, 5 Dec 2013 13:17:47 +0000 (14:17 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Thu, 5 Dec 2013 13:35:26 +0000 (14:35 +0100)
From /config/modules/module[name='hash-map-data-store']/instance[name='hash-map-data-store']
To   /modules/module[type=hash-map-data-store][name=hash-map-data-store']

Affected netconf operations: get-config, edit-config.
Backwards compatibility with previous xpath version is preserved.

Change-Id: Ic7c8057811001dbec34115b3745ce42bae790a45
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
15 files changed:
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig_none.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/namespaces/editConfig_differentNamespaceTO.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised2.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised3.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised4.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised5.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised6.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised7.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/unrecognised/editConfig_unrecognised8.xml

index e4fa6f5..f522668 100644 (file)
@@ -284,8 +284,13 @@ public final class Services {
         public static ServiceInstance fromString(String instanceId) {
             instanceId = instanceId.trim();
             Matcher matcher = p.matcher(instanceId);
+            if(matcher.matches() == false) {
+                matcher = pDeprecated.matcher(instanceId);
+            }
+
             Preconditions.checkArgument(matcher.matches(), "Unexpected format for provider, expected " + p.toString()
-                    + " but was " + instanceId);
+                    + " or " + pDeprecated.toString() + " but was " + instanceId);
+
             String factoryName = matcher.group(1);
             String instanceName = matcher.group(2);
             return new ServiceInstance(factoryName, instanceName);
@@ -310,16 +315,25 @@ public final class Services {
             return instanceName;
         }
 
-        private static final String blueprint = "/" + XmlNetconfConstants.CONFIG_KEY + "/"
+        private static final String blueprint = "/"
                 + XmlNetconfConstants.MODULES_KEY + "/" + XmlNetconfConstants.MODULE_KEY + "["
-                + XmlNetconfConstants.NAME_KEY + "='%s']/" + XmlNetconfConstants.INSTANCE_KEY + "["
+                + XmlNetconfConstants.TYPE_KEY + "='%s']["
                 + XmlNetconfConstants.NAME_KEY + "='%s']";
 
-        private static final String blueprintR = "/" + XmlNetconfConstants.CONFIG_KEY + "/"
+        // TODO unify with xpath in RuntimeRpc
+
+        // Previous version of xpath, needs to be supported for backwards compatibility (persisted configs by config-persister)
+        private static final String blueprintRDeprecated = "/" + XmlNetconfConstants.CONFIG_KEY + "/"
                 + XmlNetconfConstants.MODULES_KEY + "/" + XmlNetconfConstants.MODULE_KEY + "\\["
                 + XmlNetconfConstants.NAME_KEY + "='%s'\\]/" + XmlNetconfConstants.INSTANCE_KEY + "\\["
                 + XmlNetconfConstants.NAME_KEY + "='%s'\\]";
 
+        private static final String blueprintR = "/"
+                + XmlNetconfConstants.MODULES_KEY + "/" + XmlNetconfConstants.MODULE_KEY + "\\["
+                + XmlNetconfConstants.TYPE_KEY + "='%s'\\]\\["
+                + XmlNetconfConstants.NAME_KEY + "='%s'\\]";
+
+        private static final Pattern pDeprecated = Pattern.compile(String.format(blueprintRDeprecated, "(.+)", "(.+)"));
         private static final Pattern p = Pattern.compile(String.format(blueprintR, "(.+)", "(.+)"));
 
         @Override
index d91e38d..73522e9 100644 (file)
@@ -132,6 +132,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         // check after edit
         commit();
         Element response = getConfigRunning();
+        System.err.println(XmlUtil.toString(response));
 
         checkBinaryLeafEdited(response);
         checkTypeConfigAttribute(response);
index caa0094..3957f7f 100644 (file)
 
                     <testing-dep>
                         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
-                        <name>ref_dep</name>
+                        <name>ref_dep_2</name>
                     </testing-dep>
                 </module>
             </modules>
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index c825536..388aa4f 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index 82c218d..4d94d9e 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index 7c19b9f..c399c19 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index 84ae575..47b82c6 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index 2d9e9ed..0e70e13 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index 9407dd0..bc05d63 100644 (file)
@@ -27,7 +27,7 @@
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                 </service>
index 233ad23..f20d9ff 100644 (file)
@@ -28,7 +28,7 @@
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                 </service>
index 4593887..ff0bd9f 100644 (file)
@@ -29,7 +29,7 @@
 
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                 </service>
index 81c4137..906367b 100644 (file)
@@ -29,7 +29,7 @@
                     <instance>
                         <name>ref_dep</name>
                         <unknownAttribute>error</unknownAttribute>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                 </service>
index 528d5b0..b05046d 100644 (file)
@@ -26,7 +26,7 @@
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                 </service>
index a1e304b..d03bb08 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>
index 812882a..3722973 100644 (file)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:test">prefix:testing</type>
                     <instance>
                         <name>ref_dep</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep']
+                        <provider>/modules/module[type='impl-dep'][name='dep']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_dep_2</name>
-                        <provider>/config/modules/module[name='impl-dep']/instance[name='dep2']
+                        <provider>/modules/module[type='impl-dep'][name='dep2']
                         </provider>
                     </instance>
                     <instance>
                         <name>ref_test1</name>
-                        <provider>/config/modules/module[name='impl-netconf']/instance[name='test1']
+                        <provider>
+                            /modules/module[type='impl-netconf'][name='test1']
                         </provider>
                     </instance>
                 </service>