Merge "Fixed PersisterAggregatorTest."
authorEd Warnicke <eaw@cisco.com>
Sat, 30 Nov 2013 16:33:07 +0000 (16:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 30 Nov 2013 16:33:07 +0000 (16:33 +0000)
57 files changed:
opendaylight/config/config-api/pom.xml
opendaylight/config/config-api/src/main/yang/config.yang [moved from opendaylight/config/config-api/src/main/resources/META-INF/yang/config.yang with 100% similarity]
opendaylight/config/config-api/src/main/yang/rpc-context.yang [moved from opendaylight/config/config-api/src/main/resources/META-INF/yang/rpc-context.yang with 100% similarity]
opendaylight/config/config-manager/pom.xml
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java
opendaylight/config/config-persister-api/pom.xml
opendaylight/config/config-persister-file-adapter/pom.xml
opendaylight/config/config-plugin-parent/pom.xml [new file with mode: 0644]
opendaylight/config/logback-config/pom.xml
opendaylight/config/netty-config-api/pom.xml
opendaylight/config/netty-event-executor-config/pom.xml
opendaylight/config/netty-threadgroup-config/pom.xml
opendaylight/config/netty-timer-config/pom.xml
opendaylight/config/pom.xml
opendaylight/config/threadpool-config-api/pom.xml
opendaylight/config/threadpool-config-impl/pom.xml
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java
opendaylight/config/yang-jmx-generator/pom.xml
opendaylight/config/yang-store-api/pom.xml
opendaylight/config/yang-store-impl/pom.xml
opendaylight/config/yang-test/pom.xml
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt [new file with mode: 0644]
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java
opendaylight/md-sal/model/model-flow-base/src/main/yang/group-types.yang
opendaylight/md-sal/model/model-flow-base/src/main/yang/meter-types.yang
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/SchemaLocation.java [deleted file]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/CompositeNodeWrapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NodeWrapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/choice.yang
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_various_path_err.xml [moved from opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_various_path.xml with 100% similarity]
opendaylight/netconf/config-persister-impl/pom.xml
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java
opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandlerTest.java [new file with mode: 0644]
opendaylight/netconf/config-persister-impl/src/test/resources/conflictingVersionResponse.xml [new file with mode: 0644]

index d733834b438aee738b234d93b7814999c5817d8c..38fb8ed66be0424afe14ecd57f1e3f0693e683c4 100644 (file)
@@ -1,4 +1,5 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>concepts</artifactId>
-            <version>${opendaylight.yangtools.version}</version>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
         </dependency>
     </dependencies>
 
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Import-Package>
-                            javax.management,
-                            org.opendaylight.yangtools.concepts,
-                            org.osgi.framework,
-                        </Import-Package>
                         <Export-Package>
                             org.opendaylight.controller.config.api,
                             org.opendaylight.controller.config.api.annotations,
                             org.opendaylight.controller.config.api.jmx,
                             org.opendaylight.controller.config.api.jmx.constants,
                             org.opendaylight.controller.config.api.runtime,
+                            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.rpc.context.rev130617.*,
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.*,
                         </Export-Package>
                     </instructions>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+            </plugin>
         </plugins>
     </build>
 </project>
index b55b5da8a20735364c0d647aa0955ec52775a6b4..32f14daaede35d534d758958767bcd47e05f8bc8 100644 (file)
                             org.opendaylight.controller.config.manager.*,
                             javax.annotation.*,
                         </Private-Package>
-                        <Import-Package>
-                            org.opendaylight.controller.config.api.*,
-                            org.opendaylight.controller.config.spi.*,
-                            org.slf4j,
-                            javax.management,
-                            org.osgi.framework,
-                            org.opendaylight.yangtools.concepts.*,
-                            org.apache.commons.io,
-                            org.osgi.util.tracker,
-                        </Import-Package>
                         <Export-Package>
                         </Export-Package>
                     </instructions>
index de1a425ce64813f5c783c710367cee51232e66fc..3d0decb93d3c98d5238de6bfc856906147141151 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.config.manager.impl.osgi;
 
+import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
 import org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl;
 import org.opendaylight.controller.config.spi.ModuleFactory;
@@ -19,7 +20,7 @@ import javax.management.ObjectName;
 
 /**
  * Every time factory is added or removed, blank transaction is triggered to handle
- * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory)}
+ * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory, org.osgi.framework.BundleContext)}
  * functionality.
  */
 public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<ModuleFactory, Object> {
@@ -38,14 +39,30 @@ public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<
     }
 
     private synchronized void blankTransaction() {
-        // create transaction
-        ObjectName tx = configRegistry.beginConfig();
-        CommitStatus commitStatus = configRegistry.commitConfig(tx);
-        logger.debug("Committed blank transaction with status {}", commitStatus);
+        // race condition check: config-persister might push new configuration while server is starting up.
+        ConflictingVersionException lastException = null;
+        for (int i = 0; i < 10; i++) {
+            try {
+                // create transaction
+                ObjectName tx = configRegistry.beginConfig();
+                CommitStatus commitStatus = configRegistry.commitConfig(tx);
+                logger.debug("Committed blank transaction with status {}", commitStatus);
+                return;
+            } catch (ConflictingVersionException e) {
+                lastException = e;
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException interruptedException) {
+                    Thread.currentThread().interrupt();
+                    throw new IllegalStateException(interruptedException);
+                }
+            }
+        }
+        throw lastException;
     }
 
     @Override
-    public void modifiedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {
+    public void modifiedService(ServiceReference <ModuleFactory> moduleFactoryServiceReference, Object o) {
         blankTransaction();
     }
 
index 51f8c0b8257255d73b5e6d73643a99588a90fdce..80016a804beca18cff5f3e1f9aabd45234a67d50 100644 (file)
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Import-Package>
-                            com.google.common.base,
-                            org.w3c.dom,
-                            org.osgi.framework,
-                        </Import-Package>
                         <Export-Package>
                             org.opendaylight.controller.config.persist.api,
                             org.opendaylight.controller.config.persist.api.storage,
index d34dc3770714d1141e315fdb49d8eacff04ee9d8..b16cb2b6f366070b95a12ec7b61af3e36e343714 100644 (file)
                         </Fragment-Host>
                         <Provide-Capability>org.opendaylight.controller.config.persister.storage.adapter
                         </Provide-Capability>
-                        <Import-Package>
-                            org.osgi.framework,
-                            com.google.common.base,
-                            com.google.common.collect,
-                            com.google.common.io,
-                            javax.xml.parsers,
-                            javax.xml.transform,
-                            javax.xml.transform.dom,
-                            javax.xml.transform.stream,
-                            org.apache.commons.lang3,
-                            org.opendaylight.controller.config.persist.api,
-                            org.slf4j,
-                            org.w3c.dom,
-                            org.xml.sax,
-                        </Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
diff --git a/opendaylight/config/config-plugin-parent/pom.xml b/opendaylight/config/config-plugin-parent/pom.xml
new file mode 100644 (file)
index 0000000..7696ae5
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>config-subsystem</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>config-plugin-parent</artifactId>
+    <name>${project.artifactId}</name>
+    <packaging>pom</packaging>
+    <prerequisites>
+        <maven>3.0.4</maven>
+    </prerequisites>
+
+    <properties>
+        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
+    </properties>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.opendaylight.yangtools</groupId>
+                    <artifactId>yang-maven-plugin</artifactId>
+                    <executions>
+                        <execution>
+                            <id>config</id>
+                            <goals>
+                                <goal>generate-sources</goal>
+                            </goals>
+                            <configuration>
+                                <codeGenerators>
+                                    <generator>
+                                        <codeGeneratorClass>
+                                            org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+                                        </codeGeneratorClass>
+                                        <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+                                        <additionalConfiguration>
+                                            <namespaceToPackage1>
+                                                urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
+                                            </namespaceToPackage1>
+                                        </additionalConfiguration>
+                                    </generator>
+                                </codeGenerators>
+                                <inspectDependencies>true</inspectDependencies>
+                            </configuration>
+                        </execution>
+                    </executions>
+                    <dependencies>
+                        <dependency>
+                            <groupId>org.opendaylight.controller</groupId>
+                            <artifactId>yang-jmx-generator-plugin</artifactId>
+                            <version>${config.version}</version>
+                        </dependency>
+                    </dependencies>
+                </plugin>
+
+                <!-- tell eclipse about generated source folders -->
+                <plugin>
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>build-helper-maven-plugin</artifactId>
+                    <version>1.8</version>
+                    <executions>
+                        <execution>
+                            <id>add-source</id>
+                            <phase>generate-sources</phase>
+                            <goals>
+                                <goal>add-source</goal>
+                            </goals>
+                            <configuration>
+                                <sources>
+                                    <source>${jmxGeneratorPath}</source>
+                                </sources>
+                            </configuration>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+</project>
index b63f3298c1af9602674894915664499bcb9d038f..7d01d288ed6a58b6bd1f18b31320a4ff0046ed74 100644 (file)
@@ -1,12 +1,14 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.opendaylight.controller</groupId>
-        <artifactId>config-subsystem</artifactId>
+        <artifactId>config-plugin-parent</artifactId>
         <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
     </parent>
     <artifactId>logback-config</artifactId>
     <name>${project.artifactId}</name>
                     <instructions>
                         <Private-Package>
                         </Private-Package>
-                        <Import-Package>
-                            ch.qos.logback.classic,
-                            ch.qos.logback.classic.encoder,
-                            ch.qos.logback.classic.filter,
-                            ch.qos.logback.classic.spi,
-                            ch.qos.logback.core,
-                            ch.qos.logback.core.status,
-                            ch.qos.logback.core.encoder,
-                            ch.qos.logback.core.rolling,
-                            org.opendaylight.controller.config.api,
-                            org.opendaylight.controller.config.api.runtime,
-                            org.opendaylight.controller.config.api.annotations,
-                            org.opendaylight.controller.config.spi,
-                            com.google.common.base,
-                            com.google.common.collect,
-                            org.apache.commons.lang3,
-                            org.slf4j,
-                            org.osgi.framework
-                        </Import-Package>
                         <Export-Package>
                             org.opendaylight.controller.config.yang.logback.config,
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.logback.config.rev130716.*,
                         </Export-Package>
                     </instructions>
                 </configuration>
index 9a2fe372581647169a360cc2c157b2bdfe4ad5ea..19c926a2fbc36e25c0d407144745ce8a5f22a82a 100644 (file)
@@ -1,8 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <parent>
     <groupId>org.opendaylight.controller</groupId>
-    <artifactId>config-subsystem</artifactId>
-    <version>0.2.3-SNAPSHOT</version>
+        <artifactId>config-plugin-parent</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>netty-config-api</artifactId>
             <artifactId>maven-bundle-plugin</artifactId>
             <configuration>
                <instructions>
-                  <Import-Package>
-                     org.opendaylight.controller.config.api.*,
-                     io.netty.channel,
-                     io.netty.util,
-                     io.netty.util.concurrent
-                  </Import-Package>
                   <Export-Package>
-                     org.opendaylight.controller.config.yang.netty
+                      org.opendaylight.controller.config.yang.netty,
+                      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.rev131119.*,
                   </Export-Package>
                </instructions>
             </configuration>
@@ -51,4 +49,4 @@
          </plugin>
       </plugins>
    </build>
-</project>
\ No newline at end of file
+</project>
index 3d5384d171774d053ca01ee39ca1a9e3c784401f..2fce3596d4ad6d082b94d2a04c7f6960339da23c 100644 (file)
@@ -1,9 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
       <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-subsystem</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
+        <artifactId>config-plugin-parent</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>netty-event-executor-config</artifactId>
                <instructions>
                   <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                   <Export-Package>
+                      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.eventexecutor.rev131112.*,
                   </Export-Package>
-                  <Import-Package>
-                     com.google.common.base,
-                     org.opendaylight.controller.config.yang.netty,
-                     io.netty.util.concurrent,
-                     org.opendaylight.controller.config.api,
-                     org.opendaylight.controller.config.api.annotations,
-                     org.opendaylight.controller.config.api.runtime,
-                     org.opendaylight.controller.config.spi,
-                     org.slf4j,
-                     org.osgi.framework
-                  </Import-Package>
                </instructions>
             </configuration>
          </plugin>
@@ -99,4 +92,4 @@
       </site>
    </distributionManagement>
 
-</project>
\ No newline at end of file
+</project>
index 8dc989e7283751c1a91b4e57d789046724b1f5b3..d35067af093fcba04d22ef13c831bc63e4cb300d 100644 (file)
@@ -5,8 +5,9 @@
 
     <parent>
         <groupId>org.opendaylight.controller</groupId>
-        <artifactId>config-subsystem</artifactId>
+        <artifactId>config-plugin-parent</artifactId>
         <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
     </parent>
 
     <modelVersion>4.0.0</modelVersion>
                     <instructions>
                         <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                         <Export-Package>
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.threadgroup.rev131107.*,
                         </Export-Package>
-                        <Import-Package>
-                            com.google.common.base,
-                            io.netty.channel.nio,
-                            org.opendaylight.controller.config.yang.netty,
-                            io.netty.util.concurrent,
-                            org.opendaylight.controller.config.api,
-                            org.opendaylight.controller.config.api.annotations,
-                            org.opendaylight.controller.config.api.runtime,
-                            org.opendaylight.controller.config.spi,
-                            org.slf4j,
-                            org.osgi.framework
-                        </Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
index 095e71fcf50dcd4770081ddd6feeb55a1ed8ebe8..161d39278aef9e1a112b3227499fd8b5d431424a 100644 (file)
@@ -1,9 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
       <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-subsystem</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
+        <artifactId>config-plugin-parent</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>netty-timer-config</artifactId>
                <instructions>
                   <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                   <Export-Package>
+                      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.timer.rev131119.*,
                   </Export-Package>
-                  <Import-Package>
-                     javax.management,
-                     com.google.common.base,
-                     org.opendaylight.controller.config.yang.netty,
-                     org.opendaylight.controller.config.yang.threadpool,
-                     io.netty.util,
-                     org.opendaylight.controller.config.api,
-                     org.opendaylight.controller.config.api.annotations,
-                     org.opendaylight.controller.config.api.runtime,
-                     org.opendaylight.controller.config.spi,
-                     org.slf4j,
-                     org.osgi.framework
-                  </Import-Package>
                </instructions>
             </configuration>
          </plugin>
          <url>${basedir}/target/site/${project.artifactId}</url>
       </site>
    </distributionManagement>
-</project>
\ No newline at end of file
+</project>
index c1eef701da271014a5777f098926562a54a45074..c9ed19dacb2c0256f811025e2be01409b09e5bbc 100644 (file)
@@ -1,3 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
@@ -20,6 +22,7 @@
     <modules>
         <module>config-api</module>
         <module>config-manager</module>
+        <module>config-plugin-parent</module>
         <module>config-util</module>
         <module>config-persister-api</module>
         <module>config-persister-file-adapter</module>
@@ -63,7 +66,6 @@
         <opendaylight.yang.version>0.5.9-SNAPSHOT</opendaylight.yang.version>
         <opendaylight.binding.version>0.6.0-SNAPSHOT</opendaylight.binding.version>
         <opendaylight.yangtools.version>0.1.1-SNAPSHOT</opendaylight.yangtools.version>
-        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
     </properties>
 
     <dependencies>
                 <artifactId>yang-store-api</artifactId>
                 <version>${config.version}</version>
             </dependency>
+
+            <!-- MD-SAL -->
+            <dependency>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-binding</artifactId>
+                <version>${opendaylight.binding.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-common</artifactId>
+                <version>${opendaylight.yang.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>concepts</artifactId>
+                <version>${opendaylight.yangtools.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
             </plugin>
         </plugins>
 
-
-
         <pluginManagement>
             <plugins>
                 <plugin>
                     <version>${opendaylight.yang.version}</version>
                     <executions>
                         <execution>
+                            <id>sal</id>
                             <goals>
                                 <goal>generate-sources</goal>
                             </goals>
                             <configuration>
+                                <yangFilesRootDir>src/main/yang</yangFilesRootDir>
                                 <codeGenerators>
                                     <generator>
                                         <codeGeneratorClass>
-                                            org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+                                            org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
                                         </codeGeneratorClass>
-                                        <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
-                                        <additionalConfiguration>
-                                            <namespaceToPackage1>
-                                                urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
-                                            </namespaceToPackage1>
-                                        </additionalConfiguration>
+                                        <outputBaseDir>
+                                            target/generated-sources/sal
+                                        </outputBaseDir>
+                                    </generator>
+                                    <generator>
+                                        <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                        <outputBaseDir>target/site</outputBaseDir>
                                     </generator>
                                 </codeGenerators>
                                 <inspectDependencies>true</inspectDependencies>
                     </executions>
                     <dependencies>
                         <dependency>
-                            <groupId>org.opendaylight.controller</groupId>
-                            <artifactId>yang-jmx-generator-plugin</artifactId>
-                            <version>${config.version}</version>
+                            <groupId>org.opendaylight.yangtools</groupId>
+                            <artifactId>maven-sal-api-gen-plugin</artifactId>
+                            <version>${opendaylight.binding.version}</version>
+                            <type>jar</type>
                         </dependency>
                     </dependencies>
                 </plugin>
-                <!-- tell eclipse about generated source folders -->
-                <plugin>
-                    <groupId>org.codehaus.mojo</groupId>
-                    <artifactId>build-helper-maven-plugin</artifactId>
-                    <version>1.8</version>
-                    <executions>
-                        <execution>
-                            <id>add-source</id>
-                            <phase>generate-sources</phase>
-                            <goals>
-                                <goal>add-source</goal>
-                            </goals>
-                            <configuration>
-                                <sources>
-                                    <source>${jmxGeneratorPath}</source>
-                                </sources>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-jar-plugin</artifactId>
index 5c70ac7958fdd4a9af2803879bb598c2d2bee11f..49e9f0da9ac4f2c4e3981f80a45360172b995dd3 100644 (file)
@@ -1,9 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
       <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-subsystem</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
+        <artifactId>config-plugin-parent</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>threadpool-config-api</artifactId>
             <artifactId>maven-bundle-plugin</artifactId>
             <configuration>
                <instructions>
-                  <Import-Package>
-                     org.opendaylight.controller.config.api.*,
-                     com.google.common.eventbus,
-                  </Import-Package>
                   <Export-Package>
                      org.opendaylight.controller.config.threadpool,
-                     org.opendaylight.controller.config.yang.threadpool
+                     org.opendaylight.controller.config.yang.threadpool,
+                     org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.threadpool.rev130409.*,
                   </Export-Package>
                </instructions>
             </configuration>
@@ -48,4 +48,4 @@
          </plugin>
       </plugins>
    </build>
-</project>
\ No newline at end of file
+</project>
index cde64363cfe4454c1ca6184ff6e3c81efef520e4..4cbe3976933afc070b3b0d81578bfe3f68e7033b 100644 (file)
@@ -1,9 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
       <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-subsystem</artifactId>
-      <version>0.2.3-SNAPSHOT</version>
+        <artifactId>config-plugin-parent</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>threadpool-config-impl</artifactId>
                      javax.annotation.*,
                      org.opendaylight.controller.config.yang.threadpool.impl,
                   </Private-Package>
-                  <Import-Package>
-                     org.opendaylight.controller.config.api.*,
-                     org.opendaylight.controller.config.spi.*,
-                     org.opendaylight.controller.config.threadpool,
-                     org.opendaylight.controller.config.yang.threadpool,
-                     javax.management,
-                     org.osgi.framework,
-                     org.slf4j,
-                     com.google.common.*
-                  </Import-Package>
                   <Export-Package>
-                     org.opendaylight.controller.config.threadpool.util
+                      org.opendaylight.controller.config.threadpool.util,
+                      org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.threadpool.impl.rev130405.*,
                   </Export-Package>
                </instructions>
             </configuration>
index 7351822db9d8096f46dbce588872c34a6c744448..d0646f467a50416a71bb7d5f5c0c42cdfd343abf 100644 (file)
@@ -55,6 +55,11 @@ package ${packageName};
         dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute);
         </#if>
     </#list>
+        customValidation();
+    }
+
+    protected void customValidation(){
+
     }
 
     // caches of resolved dependencies
@@ -110,7 +115,7 @@ package ${packageName};
 
     public boolean canReuseInstance(${typeDeclaration.name} oldModule){
         // allow reusing of old instance if no parameters was changed
-        return equals(oldModule);
+        return isSame(oldModule);
     }
 
     public ${instanceType} reuseInstance(${instanceType} oldInstance){
@@ -120,34 +125,50 @@ package ${packageName};
 
     public abstract ${instanceType} createInstance();
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        ${typeDeclaration.name} other = (${typeDeclaration.name}) obj;
-
-
+    public boolean isSame(${typeDeclaration.name} other) {
+        if (other == null) {
+            throw new IllegalArgumentException("Parameter 'other' is null");
+        }
         <#list moduleFields as field>
         <#if field.dependent==true>
         if (${field.name}Dependency == null) {
             if (other.${field.name}Dependency != null)
                 return false;
-        } else if (!${field.name}Dependency.equals(other.${field.name}Dependency))
+        } else if (!${field.name}Dependency.equals(other.${field.name}Dependency)) {
             return false;
+        }
         <#else>
         if (${field.name} == null) {
-            if (other.${field.name} != null)
+            if (other.${field.name} != null) {
                 return false;
-        } else if (!${field.name}.equals(other.${field.name}))
+            }
+        } else if
+            <#if field.array == false>
+                (${field.name}.equals(other.${field.name}) == false)
+            <#else>
+                (java.util.Arrays.equals(${field.name},other.${field.name}) == false)
+            </#if>
+                 {
             return false;
+        }
         </#if>
         </#list>
 
         return true;
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ${typeDeclaration.name} that = (${typeDeclaration.name}) o;
+
+        return identifier.equals(that.identifier);
+    }
+
+    @Override
+    public int hashCode() {
+        return identifier.hashCode();
+    }
 }
index 23dce9321e3e10ca8d3ba4015e0c3fc2244233b2..2db505e54effb00cc9df5381e2ad95bf5e155312 100644 (file)
@@ -2,20 +2,20 @@
 package ${packageName};
 
 <@javadocD object=javadoc/>
-<@typeDeclarationD object=typeDeclaration/>
-{
+<@typeDeclarationD object=typeDeclaration/> {
 
     public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver, ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
+    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver,
+            ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
+
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate(){
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
index 556abad7af2b9b80f4623cca42c4411f7191e974..0d6ec3cccbeedf872bbd61c8649f6c66cf743a63 100644 (file)
@@ -584,7 +584,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest {
         assertContains(reqIfc, PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX
                 + ".threads.ThreadFactoryServiceInterface");
 
-        assertEquals("Incorrenct number of generated methods", 24,
+        assertEquals("Incorrenct number of generated methods", 27,
                 visitor.methods.size());
         assertEquals("Incorrenct number of generated method descriptions", 3,
                 visitor.methodDescriptions.size());
index cd985714d46804ecf84d713a0882811d9177aa38..c312cc849351587096c871c5edefe9bd25954efd 100644 (file)
                         <Private-Package>
                             org.opendaylight.controller.config.yangjmxgenerator.plugin.util,
                         </Private-Package>
-                        <Import-Package>
-                            org.slf4j,
-                            com.google.common.base,
-                            com.google.common.collect,
-                            javax.management.*,
-                            <!-- YANGTOOLS -->
-                            org.opendaylight.yangtools.binding.generator.util,
-                            org.opendaylight.yangtools.sal.binding.generator.spi,
-                            org.opendaylight.yangtools.sal.binding.model.api,
-                            org.opendaylight.yangtools.yang.common,
-                            org.opendaylight.yangtools.yang.model.api
-                        </Import-Package>
                         <Export-Package>
                             org.opendaylight.controller.config.yangjmxgenerator,
                             org.opendaylight.controller.config.yangjmxgenerator.attribute,
index 382dced3e754b08e8f4c593b3fca2ae9bcb11eaf..c97eade26ca5d9dad3087b71252dc85cacfa213d 100644 (file)
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Import-Package>
-                            org.opendaylight.controller.config.yangjmxgenerator,
-                            org.opendaylight.yangtools.yang.model.api
-                        </Import-Package>
                         <Export-Package>
                             org.opendaylight.controller.config.yang.store.api,
                         </Export-Package>
index 7b79c831f84477253bdcf647303631ebdc8e2f13..3b0d58a32f28cb329b35e4ea33816d7624076082 100644 (file)
                 <configuration>
                     <instructions>
                         <Bundle-Activator>org.opendaylight.controller.config.yang.store.impl.YangStoreActivator</Bundle-Activator>
-                        <Import-Package>
-                            org.opendaylight.controller.config.yang.store.api,
-                            org.opendaylight.controller.config.yangjmxgenerator,
-                            com.google.common.base,
-                            com.google.common.collect,
-                            com.google.common.primitives,
-                            org.apache.commons.io,
-                            org.osgi.framework,
-                            org.osgi.util.tracker,
-                            org.slf4j,
-                            <!-- YANGTOOLS -->
-                            org.opendaylight.yangtools.sal.binding.yang.types,
-                            org.opendaylight.yangtools.yang.common,
-                            org.opendaylight.yangtools.yang.model.api,
-                            org.opendaylight.yangtools.sal.binding.generator.spi,
-                            org.opendaylight.yangtools.yang.parser.impl,
-                        </Import-Package>
                         <Export-Package>
                         </Export-Package>
                     </instructions>
index f8d86b28bb2033f25874754acbfff2fdde4080b5..e3737c78f34d584e4771dc8df99b466d1897a828 100644 (file)
@@ -1,11 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <project
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.opendaylight.controller</groupId>
-        <artifactId>config-subsystem</artifactId>
+        <artifactId>config-plugin-parent</artifactId>
         <version>0.2.3-SNAPSHOT</version>
+        <relativePath>../config-plugin-parent</relativePath>
     </parent>
 
     <artifactId>yang-test</artifactId>
index 76df839665558ebc7a937d8d59f456f7c509d138..1122c1ffa46a16078623850314bb4cee3fd4aef0 100644 (file)
@@ -1,38 +1,23 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-dep
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
-
 /**
 *
 */
-public final class DepTestImplModule
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModule {
+public final class DepTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModule
+ {
 
-    public DepTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-        super(name, dependencyResolver);
+    public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
     }
 
-    public DepTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+    public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
             DepTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-        super(name, dependencyResolver, oldModule, oldInstance);
+
+        super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate() {
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
@@ -44,5 +29,4 @@ public final class DepTestImplModule
             }
         };
     }
-
 }
index b07cf40f821a5131a6f2a70bcdbddce6f93c2451..4152736768ca9ce12d089cb1fb039a536b712c47 100644 (file)
@@ -1,19 +1,10 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-dep
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
 /**
 *
 */
-public class DepTestImplModuleFactory
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory {
+public class DepTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory
+{
+
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt
new file mode 100644 (file)
index 0000000..80c1e54
--- /dev/null
@@ -0,0 +1,5 @@
+        return new AutoCloseable() {
+            @Override
+            public void close() throws Exception {
+            }
+        };
index ae86d42d8ebd18458aa69f80d47024bbbdd4c131..7e1848dd6a7f20f6692d5dc5f5cfefd49b587190 100644 (file)
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-netconf
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
-
-import com.google.common.collect.Lists;
-
-import java.util.List;
-
 /**
 *
 */
-public final class NetconfTestImplModule
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModule {
+public final class NetconfTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModule
+ {
 
-    public NetconfTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-        super(name, dependencyResolver);
+    public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
     }
 
-    public NetconfTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+    public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
             NetconfTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-        super(name, dependencyResolver, oldModule, oldInstance);
+
+        super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate() {
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        return registerRuntimeBeans();
+        return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
     }
-
-    private NetconfTestImplRuntimeRegistration registerRuntimeBeans() {
-        NetconfTestImplRuntimeRegistration reg = getRootRuntimeBeanRegistratorWrapper().register(new NetconfTestImplRuntimeMXBean() {
-
-            @Override
-            public Long getCreatedSessions() {
-                return getSimpleLong();
-            }
-
-            @Override
-            public Asdf getAsdf() {
-                final Asdf asdf = new Asdf();
-                asdf.setSimpleString("asdf");
-                return asdf;
-            }
-
-            @Override
-            public String noArg(final String arg1) {
-                return arg1.toUpperCase();
-            }
-
-        });
-
-        for (int i = 0; i < getSimpleShort(); i++) {
-            final int finalI = i;
-
-            reg.register(new InnerRunningDataAdditionalRuntimeMXBean() {
-                @Override
-                public Integer getSimpleInt3() {
-                    return getSimpleTest();
-                }
-
-                @Override
-                public Deep4 getDeep4() {
-                    final Deep4 d = new Deep4();
-                    d.setBoool(false);
-                    return d;
-                }
-
-                @Override
-                public String getSimpleString() {
-                    return Integer.toString(finalI);
-                }
-
-                @Override
-                public void noArgInner() {
-                }
-            });
-
-            InnerRunningDataRuntimeRegistration innerReg = reg.register(new InnerRunningDataRuntimeMXBean() {
-                @Override
-                public Integer getSimpleInt3() {
-                    return finalI;
-                }
-
-                @Override
-                public Deep2 getDeep2() {
-                    return new Deep2();
-                }
-            });
-
-            for (int j = 0; j < getSimpleShort(); j++) {
-                final int finalJ = j;
-                innerReg.register(new InnerInnerRunningDataRuntimeMXBean() {
-                    @Override
-                    public List<NotStateBean> getNotStateBean() {
-                        NotStateBean b1 = new NotStateBean();
-                        b1.setElement("not state");
-                        return Lists.newArrayList(b1);
-                    }
-
-                    @Override
-                    public Integer getSimpleInt3() {
-                        return finalJ;
-                    }
-
-                    @Override
-                    public Deep3 getDeep3() {
-                        return new Deep3();
-                    }
-
-                    @Override
-                    public List<String> getListOfStrings() {
-                        return Lists.newArrayList("l1", "l2");
-                    }
-
-                    @Override
-                    public List<RetValList> listOutput() {
-                        return Lists.newArrayList(new RetValList());
-                    }
-
-                    @Override
-                    public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
-                        return aBoolean;
-                    }
-
-                    @Override
-                    public RetValContainer containerOutput() {
-                        return new RetValContainer();
-                    }
-
-                    @Override
-                    public List<String> leafListOutput() {
-                        return Lists.newArrayList("1", "2");
-                    }
-                });
-            }
-        }
-
-        return reg;
-    }
-
 }
index e99c64dd3b473674b62e619eaba59d704cf80ffa..7cab5288680b9f2cfe454d3630c1e92f3b29d3bc 100644 (file)
@@ -1,19 +1,10 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-netconf
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
 /**
 *
 */
-public class NetconfTestImplModuleFactory
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory {
+public class NetconfTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory
+{
+
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt
new file mode 100644 (file)
index 0000000..6515412
--- /dev/null
@@ -0,0 +1 @@
+return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java
new file mode 100644 (file)
index 0000000..58943c9
--- /dev/null
@@ -0,0 +1,126 @@
+/**
+ * @author Tomas Olvecky
+ *
+ * 11 2013
+ *
+ * Copyright (c) 2013 by Cisco Systems, Inc.
+ * All rights reserved.
+ */
+package org.opendaylight.controller.config.yang.test.impl;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+public class NetconfTestImplModuleUtil {
+    static NetconfTestImplRuntimeRegistration registerRuntimeBeans(final NetconfTestImplModule module) {
+        NetconfTestImplRuntimeRegistration reg = module.getRootRuntimeBeanRegistratorWrapper().register(new NetconfTestImplRuntimeMXBean() {
+
+            @Override
+            public Long getCreatedSessions() {
+                return module.getSimpleLong();
+            }
+
+            @Override
+            public Asdf getAsdf() {
+                final Asdf asdf = new Asdf();
+                asdf.setSimpleString("asdf");
+                return asdf;
+            }
+
+            @Override
+            public String noArg(final String arg1) {
+                return arg1.toUpperCase();
+            }
+
+        });
+
+        for (int i = 0; i < module.getSimpleShort(); i++) {
+            final int finalI = i;
+
+            reg.register(new InnerRunningDataAdditionalRuntimeMXBean() {
+                @Override
+                public Integer getSimpleInt3() {
+                    return module.getSimpleTest();
+                }
+
+                @Override
+                public Deep4 getDeep4() {
+                    final Deep4 d = new Deep4();
+                    d.setBoool(false);
+                    return d;
+                }
+
+                @Override
+                public String getSimpleString() {
+                    return Integer.toString(finalI);
+                }
+
+                @Override
+                public void noArgInner() {
+                }
+            });
+
+            InnerRunningDataRuntimeRegistration innerReg = reg.register(new InnerRunningDataRuntimeMXBean() {
+                @Override
+                public Integer getSimpleInt3() {
+                    return finalI;
+                }
+
+                @Override
+                public Deep2 getDeep2() {
+                    return new Deep2();
+                }
+            });
+
+            for (int j = 0; j < module.getSimpleShort(); j++) {
+                final int finalJ = j;
+                innerReg.register(new InnerInnerRunningDataRuntimeMXBean() {
+                    @Override
+                    public List<NotStateBean> getNotStateBean() {
+                        NotStateBean b1 = new NotStateBean();
+                        b1.setElement("not state");
+                        return Lists.newArrayList(b1);
+                    }
+
+                    @Override
+                    public Integer getSimpleInt3() {
+                        return finalJ;
+                    }
+
+                    @Override
+                    public Deep3 getDeep3() {
+                        return new Deep3();
+                    }
+
+                    @Override
+                    public List<String> getListOfStrings() {
+                        return Lists.newArrayList("l1", "l2");
+                    }
+
+                    @Override
+                    public List<RetValList> listOutput() {
+                        return Lists.newArrayList(new RetValList());
+                    }
+
+                    @Override
+                    public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
+                        return aBoolean;
+                    }
+
+                    @Override
+                    public RetValContainer containerOutput() {
+                        return new RetValContainer();
+                    }
+
+                    @Override
+                    public List<String> leafListOutput() {
+                        return Lists.newArrayList("1", "2");
+                    }
+                });
+            }
+        }
+
+        return reg;
+    }
+}
index dfd9ebc021bfa62fef45dc4fb28e5dfc5678b2b3..52a71620bf0062f929e2496dac32d094f66d7157 100644 (file)
@@ -1,38 +1,23 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
-
 /**
 *
 */
-public final class TestImplModule
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModule {
+public final class TestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModule
+ {
 
-    public TestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-        super(name, dependencyResolver);
+    public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
     }
 
-    public TestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+    public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
             TestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-        super(name, dependencyResolver, oldModule, oldInstance);
+
+        super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate() {
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
@@ -44,5 +29,4 @@ public final class TestImplModule
             }
         };
     }
-
 }
index 1e86c83655eda9ab864b8892f512fdf66030bb69..ce9aa92b64ea0f4c61911b0f969c71ed048bac21 100644 (file)
@@ -1,19 +1,10 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
 /**
 *
 */
-public class TestImplModuleFactory
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory {
+public class TestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory
+{
+
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt
new file mode 100644 (file)
index 0000000..80c1e54
--- /dev/null
@@ -0,0 +1,5 @@
+        return new AutoCloseable() {
+            @Override
+            public void close() throws Exception {
+            }
+        };
index 9d2a6a0b110f333be53b6640cb02c83653982e99..6aa0d5fc909508a930dfd8c1d6182964b8ba744a 100644 (file)
@@ -185,6 +185,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager {
     private void addFlow(InstanceIdentifier<?> path, Flow dataObject) {
 
         AddFlowInputBuilder input = new AddFlowInputBuilder();
+        
         List<Instruction> inst = (dataObject).getInstructions().getInstruction();
         input.setNode((dataObject).getNode());
         input.setPriority((dataObject).getPriority());
index b8dac19bf37956262e9b88a35f24b95b719edc5c..381faa41b082ea069df75ca8b5a82736d94fd642 100644 (file)
@@ -35,15 +35,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.Gro
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder;
-
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes.GroupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.config.rev131024.meters.Meter;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -239,8 +237,8 @@ public class GroupConsumerImpl implements IForwardingRulesManager {
                 return new Status(StatusCode.BADREQUEST, "Group record does not exist");
             }*/
 
-            if (!(group.getGroupType().getIntValue() >= GroupType.GroupAll.getIntValue() && group.getGroupType()
-                    .getIntValue() <= GroupType.GroupFf.getIntValue())) {
+            if (!(group.getGroupType().getIntValue() >= GroupTypes.GroupAll.getIntValue() && group.getGroupType()
+                    .getIntValue() <= GroupTypes.GroupFf.getIntValue())) {
                 logger.error("Invalid Group type %d" + group.getGroupType().getIntValue());
                 return new Status(StatusCode.BADREQUEST, "Invalid Group type");
             }
index 25e8e7aa577968ffc20fccaac459c1e958f4d586..244fedb3e7e0dc0baf4dc59455749156babe0e8a 100644 (file)
@@ -14,30 +14,30 @@ module opendaylight-group-types {
         type uint32;
     }
     
-    grouping group-types {
-        leaf group-type {
-            type enumeration {
-                enum group-all;
-                enum group-select;
-                enum group-indirect;
-                enum group-ff;
-            }
-        }
+    typedef group-types {        
+        type enumeration {
+            enum group-all;
+            enum group-select;
+            enum group-indirect;
+            enum group-ff;
+        }        
     }
     
     typedef group-capabilities { 
-               type enumeration {
-                enum select-weight;
-                enum select-liveness;
-                enum chaining;
-                enum chaining-checks;
-            }   
-        }
+        type enumeration {
+            enum select-weight;
+            enum select-liveness;
+            enum chaining;
+            enum chaining-checks;
+        }   
+    }
     
     
     grouping group {
         
-        uses group-types;
+        leaf group-type {
+            type group-types;
+        }
         
         leaf group-id {
             type group-id;
index d26ca667996f164f9ca7f8b57c6df25a7c381563..fc9be63ec89f0ec986fa386e6af0df3d1b36b607 100644 (file)
@@ -14,24 +14,25 @@ module opendaylight-meter-types {
             type uint32;
     }
     
-    grouping meter-flags {
-        leaf flags {
-            type bits {
-                bit meter-kbps;
-                bit meter-pktps;
-                bit meter-burst;
-                bit meter-stats;
-            }
-        }
+    // field types
+    identity meter-flags {
+        description "Base identity for match Fields";
     }
     
-    grouping meter-band-type {
-        leaf flags {
-            type bits {
-                bit ofpmbt-drop;
-                bit ofpmbt-dscp-remark;
-                bit ofpmbt-experimenter;               
-            }
+    typedef meter-flags {        
+        type bits {
+            bit meter-kbps;
+            bit meter-pktps;
+            bit meter-burst;
+            bit meter-stats;
+        }        
+    }
+    
+    typedef meter-band-type {
+        type bits {
+            bit ofpmbt-drop;
+            bit ofpmbt-dscp-remark;
+            bit ofpmbt-experimenter;               
         }
     }
     
@@ -79,7 +80,9 @@ module opendaylight-meter-types {
     
     grouping meter {
         
-        uses meter-flags;        
+        leaf flags {
+           type meter-flags;        
+        }
         
         leaf meter-id {
             type meter-id;
@@ -104,7 +107,9 @@ module opendaylight-meter-types {
                 }
                 
                 container meter-band-types {
-                    uses meter-band-type;
+                    leaf flags {
+                        type meter-band-type;
+                    }
                 }
             
                 leaf rate {
index 36b46a171cde4706a1b7e22d17ed4c7e00ccdc90..9608d65e41ca82a13e2dada78b5ce5dfeb0728e7 100644 (file)
@@ -47,26 +47,13 @@ class JsonMapper {
         checkNotNull(parent);
         checkNotNull(parentSchema);
 
-        List<String> longestPathToElementViaChoiceCase = new ArrayList<>();
         for (Node<?> child : parent.getChildren()) {
-            Deque<String> choiceCasePathStack = new ArrayDeque<>(longestPathToElementViaChoiceCase);
-            SchemaLocation schemaLocation = findFirstSchemaForNode(child, parentSchema.getChildNodes(),
-                    choiceCasePathStack);
-
-            if (schemaLocation == null) {
-                if (!choiceCasePathStack.isEmpty()) {
-                    throw new UnsupportedDataTypeException("On choice-case path " + choiceCasePathStack
-                            + " wasn't found data schema for " + child.getNodeType().getLocalName());
-                } else {
-                    throw new UnsupportedDataTypeException("Probably the data node \""
-                            + child.getNodeType().getLocalName() + "\" is not conform to schema");
-                }
-            }
-
-            longestPathToElementViaChoiceCase = resolveLongerPath(longestPathToElementViaChoiceCase,
-                    schemaLocation.getLocation());
+            DataSchemaNode childSchema = findFirstSchemaForNode(child, parentSchema.getChildNodes());
 
-            DataSchemaNode childSchema = schemaLocation.getSchema();
+            if (childSchema == null) {
+                throw new UnsupportedDataTypeException("Probably the data node \"" + child.getNodeType().getLocalName()
+                        + "\" is not conform to schema");
+            }
 
             if (childSchema instanceof ContainerSchemaNode) {
                 Preconditions.checkState(child instanceof CompositeNode,
@@ -97,10 +84,7 @@ class JsonMapper {
         }
 
         for (Node<?> child : parent.getChildren()) {
-            SchemaLocation schemaLocation = findFirstSchemaForNode(child, parentSchema.getChildNodes(),
-                    new ArrayDeque<>(longestPathToElementViaChoiceCase));
-
-            DataSchemaNode childSchema = schemaLocation.getSchema();
+            DataSchemaNode childSchema = findFirstSchemaForNode(child, parentSchema.getChildNodes());
             if (childSchema instanceof LeafListSchemaNode) {
                 foundLeafLists.remove((LeafListSchemaNode) childSchema);
             } else if (childSchema instanceof ListSchemaNode) {
@@ -109,45 +93,17 @@ class JsonMapper {
         }
     }
 
-    private List<String> resolveLongerPath(List<String> l1, List<String> l2) {
-        return l1.size() > l2.size() ? l1 : l2;
-    }
-
-    private SchemaLocation findFirstSchemaForNode(Node<?> node, Set<DataSchemaNode> dataSchemaNode,
-            Deque<String> pathIterator) {
-        Map<String, ChoiceNode> choiceSubnodes = new HashMap<>();
+    private DataSchemaNode findFirstSchemaForNode(Node<?> node, Set<DataSchemaNode> dataSchemaNode) {
         for (DataSchemaNode dsn : dataSchemaNode) {
-            if (dsn instanceof ChoiceNode) {
-                choiceSubnodes.put(dsn.getQName().getLocalName(), (ChoiceNode) dsn);
-            } else if (node.getNodeType().getLocalName().equals(dsn.getQName().getLocalName())) {
-                return new SchemaLocation(dsn);
-            }
-        }
-
-        for (ChoiceNode choiceSubnode : choiceSubnodes.values()) {
-            if ((!pathIterator.isEmpty() && pathIterator.peekLast().equals(choiceSubnode.getQName().getLocalName()))
-                    || pathIterator.isEmpty()) {
-                String pathPartChoice = pathIterator.pollLast();
-                for (ChoiceCaseNode concreteCase : choiceSubnode.getCases()) {
-                    if ((!pathIterator.isEmpty() && pathIterator.peekLast().equals(
-                            concreteCase.getQName().getLocalName()))
-                            || pathIterator.isEmpty()) {
-                        String pathPartCase = pathIterator.pollLast();
-                        SchemaLocation schemaLocation = findFirstSchemaForNode(node, concreteCase.getChildNodes(),
-                                pathIterator);
-                        if (schemaLocation != null) {
-                            schemaLocation.addPathPart(concreteCase.getQName().getLocalName());
-                            schemaLocation.addPathPart(choiceSubnode.getQName().getLocalName());
-                            return schemaLocation;
-                        }
-                        if (pathPartCase != null) {
-                            pathIterator.addLast(pathPartCase);
-                        }
+            if (node.getNodeType().getLocalName().equals(dsn.getQName().getLocalName())) {
+                return dsn;
+            } else if (dsn instanceof ChoiceNode) {
+                for (ChoiceCaseNode choiceCase : ((ChoiceNode) dsn).getCases()) {
+                    DataSchemaNode foundDsn = findFirstSchemaForNode(node, choiceCase.getChildNodes());
+                    if (foundDsn != null) {
+                        return foundDsn;
                     }
                 }
-                if (pathPartChoice != null) {
-                    pathIterator.addLast(pathPartChoice);
-                }
             }
         }
         return null;
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/SchemaLocation.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/SchemaLocation.java
deleted file mode 100644 (file)
index 24055ce..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.opendaylight.controller.sal.rest.impl;
-
-import java.util.*;
-
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-
-class SchemaLocation {
-    final private List<String> location = new ArrayList<>();
-    final private DataSchemaNode schema;
-
-    public SchemaLocation(DataSchemaNode schema) {
-        this.schema = schema;
-    }
-
-    DataSchemaNode getSchema() {
-        return schema;
-    }
-
-    List<String> getLocation() {
-        return location;
-    }
-
-    SchemaLocation addPathPart(String partOfPath) {
-        location.add(partOfPath);
-        return this;
-    }
-
-}
index 29ad7522c43436891ec6cb717ee6cbc713a04abd..1b0fda41ca723d67f640de2418ebd6e33e153751 100644 (file)
@@ -1,6 +1,5 @@
 package org.opendaylight.controller.sal.restconf.impl
 
-import javax.ws.rs.WebApplicationException
 import javax.ws.rs.core.Response
 import org.opendaylight.controller.md.sal.common.api.data.DataReader
 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession
index e000c7e29e21c0a39904088351940d6862e3f42d..c741c9aa19cbc1d6c27db7734aa79cb9d39b00de 100644 (file)
@@ -24,6 +24,7 @@ public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, C
 
     private String localName;
     private URI namespace;
+    private QName name;
     private List<NodeWrapper<?>> values = new ArrayList<>();
     
     public CompositeNodeWrapper(String localName) {
@@ -34,6 +35,12 @@ public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, C
         this(localName);
         this.namespace = namespace;
     }
+    
+    @Override
+    public void setQname(QName name) {
+        Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
+        this.name = name;
+    }
 
     @Override
     public String getLocalName() {
@@ -75,9 +82,11 @@ public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, C
     @Override
     public CompositeNode unwrap(CompositeNode parent) {
         if (compositeNode == null) {
-            Preconditions.checkNotNull(namespace);
-            compositeNode = NodeFactory.createMutableCompositeNode(new QName(namespace, localName), 
-                    parent, new ArrayList<Node<?>>(), ModifyAction.CREATE, null);
+            if (name == null) {
+                Preconditions.checkNotNull(namespace);
+                name = new QName(namespace, localName);
+            }
+            compositeNode = NodeFactory.createMutableCompositeNode(name, parent, new ArrayList<Node<?>>(), null, null);
             
             List<Node<?>> nodeValues = new ArrayList<>();
             for (NodeWrapper<?> nodeWrapper : values) {
@@ -88,6 +97,7 @@ public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, C
             values = null;
             namespace = null;
             localName = null;
+            name = null;
         }
         return compositeNode;
     }
index 065d01e8e9405058f563189e6f5117d30eed4857..882c73d001071dea11ee8bfb1d253887780a0875 100644 (file)
@@ -128,6 +128,25 @@ class ControllerContext implements SchemaServiceListener {
     private def dispatch CharSequence toRestconfIdentifier(PathArgument argument, DataSchemaNode node) {
         throw new IllegalArgumentException("Conversion of generic path argument is not supported");
     }
+    
+    def findModuleByNamespace(URI namespace) {
+        checkPreconditions
+        var module = uriToModuleName.get(namespace)
+        if (module === null) {
+            val moduleSchemas = schemas.findModuleByNamespace(namespace);
+            if(moduleSchemas === null) throw new IllegalArgumentException()
+            var latestModule = moduleSchemas.head
+            for (m : moduleSchemas) {
+                if (m.revision.after(latestModule.revision)) {
+                    latestModule = m
+                }
+            }
+            if(latestModule === null) throw new IllegalArgumentException()
+            uriToModuleName.put(namespace, latestModule.name)
+            module = latestModule.name;
+        }
+        return module
+    }
 
     def CharSequence toRestconfIdentifier(QName qname) {
         checkPreconditions
index 0a3616e494a22527f3d95d7294daccf733181bd4..db7770fc68797504dc969a89eaddda832aa5c1d4 100644 (file)
@@ -2,11 +2,14 @@ package org.opendaylight.controller.sal.restconf.impl;
 
 import java.net.URI;
 
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 
 public interface NodeWrapper<T extends Node<?>> {
 
+    void setQname(QName name);
+    
     T unwrap(CompositeNode parent);
     
     URI getNamespace();
index b6426c65bfdd55c8f984a8433eaddbb9ccb20dbc..b7307544397b06e4bf544a71b0fd59471cfa72fd 100644 (file)
@@ -1,10 +1,12 @@
 package org.opendaylight.controller.sal.restconf.impl
 
 import java.util.List
+import java.util.Set
 import javax.ws.rs.core.Response
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus
 import org.opendaylight.controller.sal.rest.api.RestconfService
 import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
 
@@ -77,7 +79,7 @@ class RestconfImpl implements RestconfService {
     
     override readConfigurationData(String identifier) {
         val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier
-        val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
+        val data = broker.readConfigurationData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
         return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode)
     }
     
@@ -112,16 +114,43 @@ class RestconfImpl implements RestconfService {
     }
 
     private def void addNamespaceToNodeFromSchemaRecursively(NodeWrapper<?> nodeBuilder, DataSchemaNode schema) {
-        if (nodeBuilder.namespace === null) {
-            nodeBuilder.namespace = schema.QName.namespace
+        if (schema === null) {
+            throw new ResponseException(Response.Status.BAD_REQUEST,
+                "Data has bad format\n" + nodeBuilder.localName + " does not exist in yang schema.");
+        }
+        val moduleName = controllerContext.findModuleByNamespace(schema.QName.namespace);
+        if (nodeBuilder.namespace === null || nodeBuilder.namespace == schema.QName.namespace ||
+            nodeBuilder.namespace.path == moduleName) {
+            nodeBuilder.qname = schema.QName
+        } else {
+            throw new ResponseException(Response.Status.BAD_REQUEST,
+                "Data has bad format\nIf data is in XML format then namespace for " + nodeBuilder.localName +
+                    " should be " + schema.QName.namespace + ".\n If data is in Json format then module name for " +
+                    nodeBuilder.localName + " should be " + moduleName + ".");
         }
         if (nodeBuilder instanceof CompositeNodeWrapper) {
             val List<NodeWrapper<?>> children = (nodeBuilder as CompositeNodeWrapper).getValues
             for (child : children) {
                 addNamespaceToNodeFromSchemaRecursively(child,
-                    (schema as DataNodeContainer).childNodes.findFirst[n|n.QName.localName.equals(child.localName)])
+                    findFirstSchemaByLocalName(child.localName, (schema as DataNodeContainer).childNodes))
+            }
+        }
+    }
+    
+    private def DataSchemaNode findFirstSchemaByLocalName(String localName, Set<DataSchemaNode> schemas) {
+        for (schema : schemas) {
+            if (schema instanceof ChoiceNode) {
+                for (caze : (schema as ChoiceNode).cases) {
+                    val result =  findFirstSchemaByLocalName(localName, caze.childNodes)
+                    if (result !== null) {
+                        return result
+                    }
+                }
+            } else {
+                return schemas.findFirst[n|n.QName.localName.equals(localName)]
             }
         }
+        return null
     }
 
 }
index 4600d0890bcc41f30f6f43ff0907c978156352a3..1b103b43c25219f60a482fcc7b9a459666ece55f 100644 (file)
@@ -18,6 +18,7 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
     private String localName;
     private String value;
     private URI namespace;
+    private QName name;
 
     public SimpleNodeWrapper(String localName, String value) {
         this.localName = Preconditions.checkNotNull(localName);
@@ -29,6 +30,12 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
         this.namespace = namespace;
     }
     
+    @Override
+    public void setQname(QName name) {
+        Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
+        this.name = name;
+    }
+    
     @Override
     public String getLocalName() {
         if (simpleNode != null) {
@@ -54,12 +61,16 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
     @Override
     public SimpleNode<String> unwrap(CompositeNode parent) {
         if (simpleNode == null) {
-            Preconditions.checkNotNull(namespace);
-            simpleNode = NodeFactory.createImmutableSimpleNode(new QName(namespace, localName), parent, value);
+            if (name == null) {
+                Preconditions.checkNotNull(namespace);
+                name = new QName(namespace, localName);
+            }
+            simpleNode = NodeFactory.createImmutableSimpleNode(name, parent, value);
             
             value = null;
             namespace = null;
             localName = null;
+            name = null;
         }
         return simpleNode;
     }
index 141ffdb75467f8db326c03763e83ce4cb2d27b74..8e3ff1d2ed4a998997181a897a1c8ff648099aaa 100644 (file)
@@ -25,39 +25,56 @@ public class ToJsonChoiceCaseTest {
     }
 
     /**
-     * Test when some data are in one case node and other in another. Exception
-     * expected!!
+     * Test when some data are in one case node and other in another. This isn't
+     * correct. Next Json validator should return error because nodes has to be
+     * from one case below concrete choice.
+     * 
      */
     @Test
-    public void compNodeDataOnVariousChoiceCasePathTest() {
-        boolean exceptionCatched = false;
+    public void nodeSchemasOnVariousChoiceCasePathTest() {
         try {
             TestUtils.writeCompNodeWithSchemaContextToJson(
-                    TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path.xml"),
+                    TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path_err.xml"),
                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
-        } catch (UnsupportedDataTypeException e) {
-            exceptionCatched = true;
-
         } catch (WebApplicationException | IOException e) {
             // shouldn't end here
             assertTrue(false);
         }
+    }
 
-        assertTrue(exceptionCatched);
-
+    /**
+     * Test when some data are in one case node and other in another.
+     * Additionally data are loadef from various choices. This isn't
+     * correct. Next Json validator should return error because nodes has to be
+     * from one case below concrete choice.
+     * 
+     */
+    @Test
+    public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
+        try {
+            TestUtils
+                    .writeCompNodeWithSchemaContextToJson(
+                            TestUtils
+                                    .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml"),
+                            "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
     }
 
     /**
      * Test when second level data are red first, then first and at the end
      * third level. Level represents pass through couple choice-case
      */
-    @Ignore
+
     @Test
-    public void compNodeDataWithRandomOrderAccordingLevel() {
+    public void nodeSchemasWithRandomOrderAccordingLevel() {
         try {
-            String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
+            TestUtils.writeCompNodeWithSchemaContextToJson(
                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_random_level.xml"),
                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
+
         } catch (WebApplicationException | IOException e) {
             // shouldn't end here
             assertTrue(false);
@@ -67,11 +84,10 @@ public class ToJsonChoiceCaseTest {
     /**
      * Test when element from no first case is used
      */
-    @Ignore
     @Test
-    public void compNodeDataNoFirstCase() {
+    public void nodeSchemasNotInFirstCase() {
         try {
-            String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
+            TestUtils.writeCompNodeWithSchemaContextToJson(
                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_no_first_case.xml"),
                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
         } catch (WebApplicationException | IOException e) {
@@ -83,11 +99,10 @@ public class ToJsonChoiceCaseTest {
     /**
      * Test when element in case is list
      */
-    @Ignore
     @Test
-    public void compNodeDataAsList() {
+    public void nodeSchemaAsList() {
         try {
-            String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
+            TestUtils.writeCompNodeWithSchemaContextToJson(
                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_list.xml"),
                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
         } catch (WebApplicationException | IOException e) {
@@ -99,11 +114,10 @@ public class ToJsonChoiceCaseTest {
     /**
      * Test when element in case is container
      */
-    @Ignore
     @Test
-    public void compNodeDataAsContainer() {
+    public void nodeSchemaAsContainer() {
         try {
-            String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
+            TestUtils.writeCompNodeWithSchemaContextToJson(
                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_container.xml"),
                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
         } catch (WebApplicationException | IOException e) {
@@ -113,13 +127,12 @@ public class ToJsonChoiceCaseTest {
     }
 
     /**
-     * Test when element in case is container
+     * Test when element in case is leaflist
      */
-    @Ignore
     @Test
-    public void compNodeDataAsLeafList() {
+    public void nodeSchemaAsLeafList() {
         try {
-            String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
+            TestUtils.writeCompNodeWithSchemaContextToJson(
                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_leaflist.xml"),
                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
         } catch (WebApplicationException | IOException e) {
@@ -128,4 +141,50 @@ public class ToJsonChoiceCaseTest {
         }
     }
 
+    /**
+     * 
+     */
+    @Test
+    public void nodeSchemasInMultipleChoicesTest() {
+        try {
+            TestUtils
+                    .writeCompNodeWithSchemaContextToJson(TestUtils
+                            .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml"),
+                            "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+    }
+
+    /**
+     * Test whether is possible to find data schema for node which is specified
+     * as dirrect subnode of choice (case without CASE key word)
+     */
+    @Test
+    public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
+        try {
+            TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
+                    .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml"),
+                    "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+    }
+
+    /**
+     * Test of multiple use of choices
+     */
+    @Test
+    public void nodeSchemasInThreeChoicesAtSameLevel() {
+        try {
+            TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
+                    .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml"),
+                    "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
+        } catch (WebApplicationException | IOException e) {
+            // shouldn't end here
+            assertTrue(false);
+        }
+    }
 }
index 8b02a9297991a00ed66417fbc3b57f52dd417da4..a6a32df52ee762c1a395908a86af81e6378c56a5 100644 (file)
@@ -10,7 +10,7 @@ module choice-case-test {
                        type string;
                }               
                
-               choice choi1 {
+               choice choi1 {            
                        case a1 {
                                leaf lf1a {
                                        type uint16;    
@@ -59,6 +59,9 @@ module choice-case-test {
                                        type string;
                                }
                        }
+            leaf e1 {
+                type uint32;
+            }
                }
                
                choice choi2 {
@@ -73,6 +76,31 @@ module choice-case-test {
                                }
                        }
                }
+        
+        choice choi4 {
+            case a4 {
+                list lst4a {
+                    choice choi4aa {
+                        case aa1 {
+                            leaf lf4aa {
+                                type string;
+                            }
+                        }
+                        case ab2 {
+                            leaf lf4ab {
+                                type int16;
+                            }
+                        }
+                    }
+                }
+            }
+            case b4 {
+                leaf-list lflst4b {
+                    type uint32;
+                }
+            }
+            
+        }
                
 /*              equal identifiers in various cases are illegal 7.9.2 rfc6020 */
 /*             
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml
new file mode 100644 (file)
index 0000000..b669842
--- /dev/null
@@ -0,0 +1,4 @@
+<cont>
+       <e1>45</e1>
+       <lf2b>lf2b val</lf2b>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml
new file mode 100644 (file)
index 0000000..331c8ae
--- /dev/null
@@ -0,0 +1,7 @@
+<cont>
+       <cont1c>
+               <lf11c>lf11c val</lf11c>
+       </cont1c>
+       <lf2b>lf2b value</lf2b>
+       <lf2a>lf2b value</lf2a>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml
new file mode 100644 (file)
index 0000000..ecc0caa
--- /dev/null
@@ -0,0 +1,13 @@
+<cont>
+       <lf1aaa>lf1aaa value</lf1aaa>
+       <lf2b>lf2b value</lf2b>
+       <lst4a>
+               <lf4ab>33</lf4ab>
+       </lst4a>
+       <lst4a>
+               <lf4ab>33</lf4ab>
+       </lst4a>
+       <lst4a>
+               <lf4ab>37</lf4ab>
+       </lst4a>
+</cont>
\ No newline at end of file
index 6b3dfc71735d36f94bb4dd57b99dc2e0d63c6548..c6caf417a17484aca119f7c2e5e655ce08102440 100644 (file)
@@ -95,6 +95,9 @@
                             org.slf4j,
                             org.w3c.dom,
                             org.xml.sax,
+                            javax.xml.namespace,
+                            javax.xml.xpath,
+                            org.opendaylight.controller.config.api
                         </Import-Package>
                         <Export-Package>
                         </Export-Package>
index a569f90538104048026249370a6650119007f32f..d83b1eaaf341931571ce723378f41145a3342154 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
 import org.opendaylight.controller.config.persist.api.Persister;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
@@ -21,6 +22,7 @@ import org.opendaylight.controller.netconf.api.jmx.DefaultCommitOperationMXBean;
 import org.opendaylight.controller.netconf.api.jmx.NetconfJMXNotification;
 import org.opendaylight.controller.netconf.client.NetconfClient;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
@@ -37,6 +39,8 @@ import javax.management.Notification;
 import javax.management.NotificationListener;
 import javax.management.ObjectName;
 import javax.net.ssl.SSLContext;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -66,7 +70,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
 
     private final Persister persister;
     private final MBeanServerConnection mbeanServer;
-    private Long currentSessionId;
+
 
     private final ObjectName on = DefaultCommitOperationMXBean.objectName;
 
@@ -96,26 +100,40 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
 
         if (maybeConfig.isPresent()) {
             logger.debug("Last config found {}", persister);
+            ConflictingVersionException lastException = null;
+            pushLastConfigWithRetries(maybeConfig, lastException);
+
+        } else {
+            // this ensures that netconf is initialized, this is first
+            // connection
+            // this means we can register as listener for commit
+            registerToNetconf(Collections.<String>emptySet());
 
+            logger.info("No last config provided by backend storage {}", persister);
+        }
+        registerAsJMXListener();
+    }
+
+    private void pushLastConfigWithRetries(Optional<ConfigSnapshotHolder> maybeConfig, ConflictingVersionException lastException) throws InterruptedException {
+        int maxAttempts = 30;
+        for(int i = 0 ; i < maxAttempts; i++) {
             registerToNetconf(maybeConfig.get().getCapabilities());
 
             final String configSnapshot = maybeConfig.get().getConfigSnapshot();
             logger.trace("Pushing following xml to netconf {}", configSnapshot);
             try {
                 pushLastConfig(XmlUtil.readXmlToElement(configSnapshot));
+                return;
+            } catch(ConflictingVersionException e) {
+                closeClientAndDispatcher(netconfClient, netconfClientDispatcher);
+                lastException = e;
+                Thread.sleep(1000);
             } catch (SAXException | IOException e) {
                 throw new IllegalStateException("Unable to load last config", e);
             }
-
-        } else {
-            // this ensures that netconf is initialized, this is first
-            // connection
-            // this means we can register as listener for commit
-            registerToNetconf(Collections.<String>emptySet());
-
-            logger.info("No last config provided by backend storage {}", persister);
         }
-        registerAsJMXListener();
+        throw new IllegalStateException("Failed to push configuration, maximum attempt count has been reached: "
+                + maxAttempts, lastException);
     }
 
     private synchronized long registerToNetconf(Set<String> expectedCaps) throws InterruptedException {
@@ -130,9 +148,9 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
 
         int attempt = 0;
 
-        while (true) {
+        long deadline = pollingStart + timeout;
+        while (System.currentTimeMillis() < deadline) {
             attempt++;
-
             netconfClientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
             try {
                 netconfClient = new NetconfClient(this.toString(), address, delay, netconfClientDispatcher);
@@ -146,14 +164,12 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
 
             if (isSubset(currentCapabilities, expectedCaps)) {
                 logger.debug("Hello from netconf stable with {} capabilities", currentCapabilities);
-                currentSessionId = netconfClient.getSessionId();
+                long currentSessionId = netconfClient.getSessionId();
                 logger.info("Session id received from netconf server: {}", currentSessionId);
                 return currentSessionId;
             }
 
-            if (System.currentTimeMillis() > pollingStart + timeout) {
-                break;
-            }
+
 
             logger.debug("Polling hello from netconf, attempt {}, capabilities {}", attempt, currentCapabilities);
 
@@ -197,6 +213,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
     }
 
     private void registerAsJMXListener() {
+        logger.trace("Called registerAsJMXListener");
         try {
             mbeanServer.addNotificationListener(on, this, null, null);
         } catch (InstanceNotFoundException | IOException e) {
@@ -245,7 +262,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         return maybeConfigElement;
     }
 
-    private synchronized void pushLastConfig(Element xmlToBePersisted) {
+    private synchronized void pushLastConfig(Element xmlToBePersisted) throws ConflictingVersionException {
         logger.info("Pushing last configuration to netconf");
         StringBuilder response = new StringBuilder("editConfig response = {");
 
@@ -276,19 +293,26 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         logger.trace("Detailed message {}", response);
     }
 
-    private void checkIsOk(XmlElement element, NetconfMessage responseMessage) {
+    static void checkIsOk(XmlElement element, NetconfMessage responseMessage) throws ConflictingVersionException {
         if (element.getName().equals(XmlNetconfConstants.OK)) {
             return;
-        } else {
-            if (element.getName().equals(XmlNetconfConstants.RPC_ERROR)) {
-                logger.warn("Can not load last configuration, operation failed");
-                throw new IllegalStateException("Can not load last configuration, operation failed: "
-                        + XmlUtil.toString(responseMessage.getDocument()));
+        }
+
+        if (element.getName().equals(XmlNetconfConstants.RPC_ERROR)) {
+            logger.warn("Can not load last configuration, operation failed");
+            // is it ConflictingVersionException ?
+            XPathExpression xPathExpression = XMLNetconfUtil.compileXPath("/netconf:rpc-reply/netconf:rpc-error/netconf:error-info/netconf:error");
+            String error = (String) XmlUtil.evaluateXPath(xPathExpression, element.getDomElement(), XPathConstants.STRING);
+            if (error!=null && error.contains(ConflictingVersionException.class.getCanonicalName())) {
+                throw new ConflictingVersionException(error);
             }
-            logger.warn("Can not load last configuration. Operation failed.");
-            throw new IllegalStateException("Can not load last configuration. Operation failed: "
+            throw new IllegalStateException("Can not load last configuration, operation failed: "
                     + XmlUtil.toString(responseMessage.getDocument()));
         }
+
+        logger.warn("Can not load last configuration. Operation failed.");
+        throw new IllegalStateException("Can not load last configuration. Operation failed: "
+                + XmlUtil.toString(responseMessage.getDocument()));
     }
 
     private static NetconfMessage createEditConfigMessage(Element dataElement, String editConfigResourcename) {
diff --git a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandlerTest.java b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandlerTest.java
new file mode 100644 (file)
index 0000000..6c45c9c
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.netconf.persist.impl;
+
+import org.junit.Test;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.w3c.dom.Document;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+public class ConfigPersisterNotificationHandlerTest {
+
+    @Test
+    public void testConflictingVersionDetection() throws Exception {
+        Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/conflictingVersionResponse.xml"));
+        try{
+            ConfigPersisterNotificationHandler.checkIsOk(XmlElement.fromDomDocument(document).getOnlyChildElement(), new NetconfMessage(document));
+            fail();
+        }catch(ConflictingVersionException e){
+            assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));
+        }
+    }
+
+}
diff --git a/opendaylight/netconf/config-persister-impl/src/test/resources/conflictingVersionResponse.xml b/opendaylight/netconf/config-persister-impl/src/test/resources/conflictingVersionResponse.xml
new file mode 100644 (file)
index 0000000..f65e0e0
--- /dev/null
@@ -0,0 +1,13 @@
+<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="persister_commit">
+    <rpc-error>
+        <error-type>application</error-type>
+        <error-tag>operation-failed</error-tag>
+        <error-severity>error</error-severity>
+
+
+
+        <error-info>
+            <error>org.opendaylight.controller.config.api.ConflictingVersionException: Optimistic lock failed. Expected parent version 21, was 18</error>
+        </error-info>
+    </rpc-error>
+</rpc-reply>