From: Ed Warnicke Date: Sat, 30 Nov 2013 16:33:07 +0000 (+0000) Subject: Merge "Fixed PersisterAggregatorTest." X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~293 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8b5d3ec5b3a951fede6d9dd8416c64c4a5ba8bd1;hp=8ca41be0336a1a9c02fb46ee0961a66f0ab40bf8;p=controller.git Merge "Fixed PersisterAggregatorTest." --- diff --git a/opendaylight/config/config-api/pom.xml b/opendaylight/config/config-api/pom.xml index d733834b43..38fb8ed66b 100644 --- a/opendaylight/config/config-api/pom.xml +++ b/opendaylight/config/config-api/pom.xml @@ -1,4 +1,5 @@ - + + @@ -25,8 +26,11 @@ org.opendaylight.yangtools - concepts - ${opendaylight.yangtools.version} + yang-binding + + + org.opendaylight.yangtools + yang-common @@ -37,11 +41,6 @@ maven-bundle-plugin - - javax.management, - org.opendaylight.yangtools.concepts, - org.osgi.framework, - org.opendaylight.controller.config.api, org.opendaylight.controller.config.api.annotations, @@ -49,10 +48,20 @@ 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.*, + + org.opendaylight.yangtools + yang-maven-plugin + + + org.codehaus.mojo + build-helper-maven-plugin + diff --git a/opendaylight/config/config-api/src/main/resources/META-INF/yang/config.yang b/opendaylight/config/config-api/src/main/yang/config.yang similarity index 100% rename from opendaylight/config/config-api/src/main/resources/META-INF/yang/config.yang rename to opendaylight/config/config-api/src/main/yang/config.yang diff --git a/opendaylight/config/config-api/src/main/resources/META-INF/yang/rpc-context.yang b/opendaylight/config/config-api/src/main/yang/rpc-context.yang similarity index 100% rename from opendaylight/config/config-api/src/main/resources/META-INF/yang/rpc-context.yang rename to opendaylight/config/config-api/src/main/yang/rpc-context.yang diff --git a/opendaylight/config/config-manager/pom.xml b/opendaylight/config/config-manager/pom.xml index b55b5da8a2..32f14daaed 100644 --- a/opendaylight/config/config-manager/pom.xml +++ b/opendaylight/config/config-manager/pom.xml @@ -84,16 +84,6 @@ org.opendaylight.controller.config.manager.*, javax.annotation.*, - - 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, - diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java index de1a425ce6..3d0decb93d 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java @@ -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 { @@ -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 moduleFactoryServiceReference, Object o) { + public void modifiedService(ServiceReference moduleFactoryServiceReference, Object o) { blankTransaction(); } diff --git a/opendaylight/config/config-persister-api/pom.xml b/opendaylight/config/config-persister-api/pom.xml index 51f8c0b825..80016a804b 100644 --- a/opendaylight/config/config-persister-api/pom.xml +++ b/opendaylight/config/config-persister-api/pom.xml @@ -29,11 +29,6 @@ maven-bundle-plugin - - com.google.common.base, - org.w3c.dom, - org.osgi.framework, - org.opendaylight.controller.config.persist.api, org.opendaylight.controller.config.persist.api.storage, diff --git a/opendaylight/config/config-persister-file-adapter/pom.xml b/opendaylight/config/config-persister-file-adapter/pom.xml index d34dc37707..b16cb2b6f3 100644 --- a/opendaylight/config/config-persister-file-adapter/pom.xml +++ b/opendaylight/config/config-persister-file-adapter/pom.xml @@ -69,21 +69,6 @@ org.opendaylight.controller.config.persister.storage.adapter - - 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, - diff --git a/opendaylight/config/config-plugin-parent/pom.xml b/opendaylight/config/config-plugin-parent/pom.xml new file mode 100644 index 0000000000..7696ae5573 --- /dev/null +++ b/opendaylight/config/config-plugin-parent/pom.xml @@ -0,0 +1,83 @@ + + + + + org.opendaylight.controller + config-subsystem + 0.2.3-SNAPSHOT + + 4.0.0 + config-plugin-parent + ${project.artifactId} + pom + + 3.0.4 + + + + ${project.build.directory}/generated-sources/config + + + + + + + org.opendaylight.yangtools + yang-maven-plugin + + + config + + generate-sources + + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + + ${jmxGeneratorPath} + + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + ${jmxGeneratorPath} + + + + + + + + + diff --git a/opendaylight/config/logback-config/pom.xml b/opendaylight/config/logback-config/pom.xml index b63f3298c1..7d01d288ed 100644 --- a/opendaylight/config/logback-config/pom.xml +++ b/opendaylight/config/logback-config/pom.xml @@ -1,12 +1,14 @@ - + + 4.0.0 org.opendaylight.controller - config-subsystem + config-plugin-parent 0.2.3-SNAPSHOT + ../config-plugin-parent logback-config ${project.artifactId} @@ -79,27 +81,9 @@ - - 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 - org.opendaylight.controller.config.yang.logback.config, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.logback.config.rev130716.*, diff --git a/opendaylight/config/netty-config-api/pom.xml b/opendaylight/config/netty-config-api/pom.xml index 9a2fe37258..19c926a2fb 100644 --- a/opendaylight/config/netty-config-api/pom.xml +++ b/opendaylight/config/netty-config-api/pom.xml @@ -1,8 +1,11 @@ + + org.opendaylight.controller - config-subsystem - 0.2.3-SNAPSHOT + config-plugin-parent + 0.2.3-SNAPSHOT + ../config-plugin-parent 4.0.0 netty-config-api @@ -33,14 +36,9 @@ maven-bundle-plugin - - org.opendaylight.controller.config.api.*, - io.netty.channel, - io.netty.util, - io.netty.util.concurrent - - 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.*, @@ -51,4 +49,4 @@ - \ No newline at end of file + diff --git a/opendaylight/config/netty-event-executor-config/pom.xml b/opendaylight/config/netty-event-executor-config/pom.xml index 3d5384d171..2fce3596d4 100644 --- a/opendaylight/config/netty-event-executor-config/pom.xml +++ b/opendaylight/config/netty-event-executor-config/pom.xml @@ -1,9 +1,12 @@ + + org.opendaylight.controller - config-subsystem - 0.2.3-SNAPSHOT + config-plugin-parent + 0.2.3-SNAPSHOT + ../config-plugin-parent 4.0.0 netty-event-executor-config @@ -73,18 +76,8 @@ ${project.groupId}.${project.artifactId} + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.eventexecutor.rev131112.*, - - 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 - @@ -99,4 +92,4 @@ - \ No newline at end of file + diff --git a/opendaylight/config/netty-threadgroup-config/pom.xml b/opendaylight/config/netty-threadgroup-config/pom.xml index 8dc989e728..d35067af09 100644 --- a/opendaylight/config/netty-threadgroup-config/pom.xml +++ b/opendaylight/config/netty-threadgroup-config/pom.xml @@ -5,8 +5,9 @@ org.opendaylight.controller - config-subsystem + config-plugin-parent 0.2.3-SNAPSHOT + ../config-plugin-parent 4.0.0 @@ -80,19 +81,8 @@ ${project.groupId}.${project.artifactId} + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.threadgroup.rev131107.*, - - 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 - diff --git a/opendaylight/config/netty-timer-config/pom.xml b/opendaylight/config/netty-timer-config/pom.xml index 095e71fcf5..161d39278a 100644 --- a/opendaylight/config/netty-timer-config/pom.xml +++ b/opendaylight/config/netty-timer-config/pom.xml @@ -1,9 +1,12 @@ + + org.opendaylight.controller - config-subsystem - 0.2.3-SNAPSHOT + config-plugin-parent + 0.2.3-SNAPSHOT + ../config-plugin-parent 4.0.0 netty-timer-config @@ -84,20 +87,8 @@ ${project.groupId}.${project.artifactId} + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.timer.rev131119.*, - - 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 - @@ -111,4 +102,4 @@ ${basedir}/target/site/${project.artifactId} - \ No newline at end of file + diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index c1eef701da..c9ed19dacb 100644 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -1,3 +1,5 @@ + + 4.0.0 @@ -20,6 +22,7 @@ config-api config-manager + config-plugin-parent config-util config-persister-api config-persister-file-adapter @@ -63,7 +66,6 @@ 0.5.9-SNAPSHOT 0.6.0-SNAPSHOT 0.1.1-SNAPSHOT - ${project.build.directory}/generated-sources/config @@ -223,6 +225,23 @@ yang-store-api ${config.version} + + + + org.opendaylight.yangtools + yang-binding + ${opendaylight.binding.version} + + + org.opendaylight.yangtools + yang-common + ${opendaylight.yang.version} + + + org.opendaylight.yangtools + concepts + ${opendaylight.yangtools.version} + @@ -270,8 +289,6 @@ - - @@ -280,21 +297,24 @@ ${opendaylight.yang.version} + sal generate-sources + src/main/yang - org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl - ${jmxGeneratorPath} - - - urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang - - + + target/generated-sources/sal + + + + org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl + target/site true @@ -303,32 +323,13 @@ - org.opendaylight.controller - yang-jmx-generator-plugin - ${config.version} + org.opendaylight.yangtools + maven-sal-api-gen-plugin + ${opendaylight.binding.version} + jar - - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${jmxGeneratorPath} - - - - - org.apache.maven.plugins maven-jar-plugin diff --git a/opendaylight/config/threadpool-config-api/pom.xml b/opendaylight/config/threadpool-config-api/pom.xml index 5c70ac7958..49e9f0da9a 100644 --- a/opendaylight/config/threadpool-config-api/pom.xml +++ b/opendaylight/config/threadpool-config-api/pom.xml @@ -1,9 +1,12 @@ + + org.opendaylight.controller - config-subsystem - 0.2.3-SNAPSHOT + config-plugin-parent + 0.2.3-SNAPSHOT + ../config-plugin-parent 4.0.0 threadpool-config-api @@ -31,13 +34,10 @@ maven-bundle-plugin - - org.opendaylight.controller.config.api.*, - com.google.common.eventbus, - 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.*, @@ -48,4 +48,4 @@ - \ No newline at end of file + diff --git a/opendaylight/config/threadpool-config-impl/pom.xml b/opendaylight/config/threadpool-config-impl/pom.xml index cde64363cf..4cbe397693 100644 --- a/opendaylight/config/threadpool-config-impl/pom.xml +++ b/opendaylight/config/threadpool-config-impl/pom.xml @@ -1,9 +1,12 @@ + + org.opendaylight.controller - config-subsystem - 0.2.3-SNAPSHOT + config-plugin-parent + 0.2.3-SNAPSHOT + ../config-plugin-parent 4.0.0 threadpool-config-impl @@ -68,18 +71,9 @@ javax.annotation.*, org.opendaylight.controller.config.yang.threadpool.impl, - - 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.* - - 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.*, diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java index 517143e656..fe9e885b6f 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java @@ -48,4 +48,8 @@ public class Field { public String getDefinition() { return definition; } + + public boolean isArray() { + return type.endsWith("[]"); + } } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl index 7351822db9..d0646f467a 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl @@ -55,6 +55,11 @@ package ${packageName}; dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute); + 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) + + { return false; + } 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(); + } } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl index 23dce9321e..2db505e54e 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl @@ -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. } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java index 556abad7af..0d6ec3cccb 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java @@ -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()); diff --git a/opendaylight/config/yang-jmx-generator/pom.xml b/opendaylight/config/yang-jmx-generator/pom.xml index cd985714d4..c312cc8493 100644 --- a/opendaylight/config/yang-jmx-generator/pom.xml +++ b/opendaylight/config/yang-jmx-generator/pom.xml @@ -69,18 +69,6 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.util, - - org.slf4j, - com.google.common.base, - com.google.common.collect, - javax.management.*, - - 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 - org.opendaylight.controller.config.yangjmxgenerator, org.opendaylight.controller.config.yangjmxgenerator.attribute, diff --git a/opendaylight/config/yang-store-api/pom.xml b/opendaylight/config/yang-store-api/pom.xml index 382dced3e7..c97eade26c 100644 --- a/opendaylight/config/yang-store-api/pom.xml +++ b/opendaylight/config/yang-store-api/pom.xml @@ -25,10 +25,6 @@ maven-bundle-plugin - - org.opendaylight.controller.config.yangjmxgenerator, - org.opendaylight.yangtools.yang.model.api - org.opendaylight.controller.config.yang.store.api, diff --git a/opendaylight/config/yang-store-impl/pom.xml b/opendaylight/config/yang-store-impl/pom.xml index 7b79c831f8..3b0d58a32f 100644 --- a/opendaylight/config/yang-store-impl/pom.xml +++ b/opendaylight/config/yang-store-impl/pom.xml @@ -59,23 +59,6 @@ org.opendaylight.controller.config.yang.store.impl.YangStoreActivator - - 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, - - 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, - diff --git a/opendaylight/config/yang-test/pom.xml b/opendaylight/config/yang-test/pom.xml index f8d86b28bb..e3737c78f3 100644 --- a/opendaylight/config/yang-test/pom.xml +++ b/opendaylight/config/yang-test/pom.xml @@ -1,11 +1,14 @@ + + 4.0.0 org.opendaylight.controller - config-subsystem + config-plugin-parent 0.2.3-SNAPSHOT + ../config-plugin-parent yang-test diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java index 76df839665..1122c1ffa4 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java @@ -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 } }; } - } diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java index b07cf40f82..4152736768 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java @@ -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 index 0000000000..80c1e54a15 --- /dev/null +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt @@ -0,0 +1,5 @@ + return new AutoCloseable() { + @Override + public void close() throws Exception { + } + }; diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java index ae86d42d8e..7e1848dd6a 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java @@ -1,159 +1,28 @@ -/** - * 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 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 getListOfStrings() { - return Lists.newArrayList("l1", "l2"); - } - - @Override - public List 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 leafListOutput() { - return Lists.newArrayList("1", "2"); - } - }); - } - } - - return reg; - } - } diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java index e99c64dd3b..7cab528868 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java @@ -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 index 0000000000..6515412f24 --- /dev/null +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt @@ -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 index 0000000000..58943c9df2 --- /dev/null +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java @@ -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 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 getListOfStrings() { + return Lists.newArrayList("l1", "l2"); + } + + @Override + public List 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 leafListOutput() { + return Lists.newArrayList("1", "2"); + } + }); + } + } + + return reg; + } +} diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java index dfd9ebc021..52a71620bf 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java @@ -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 } }; } - } diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java index 1e86c83655..ce9aa92b64 100644 --- a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java @@ -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 index 0000000000..80c1e54a15 --- /dev/null +++ b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt @@ -0,0 +1,5 @@ + return new AutoCloseable() { + @Override + public void close() throws Exception { + } + }; diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java index 9d2a6a0b11..6aa0d5fc90 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java @@ -185,6 +185,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager { private void addFlow(InstanceIdentifier path, Flow dataObject) { AddFlowInputBuilder input = new AddFlowInputBuilder(); + List inst = (dataObject).getInstructions().getInstruction(); input.setNode((dataObject).getNode()); input.setPriority((dataObject).getPriority()); diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java index b8dac19bf3..381faa41b0 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/GroupConsumerImpl.java @@ -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"); } diff --git a/opendaylight/md-sal/model/model-flow-base/src/main/yang/group-types.yang b/opendaylight/md-sal/model/model-flow-base/src/main/yang/group-types.yang index 25e8e7aa57..244fedb3e7 100644 --- a/opendaylight/md-sal/model/model-flow-base/src/main/yang/group-types.yang +++ b/opendaylight/md-sal/model/model-flow-base/src/main/yang/group-types.yang @@ -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; diff --git a/opendaylight/md-sal/model/model-flow-base/src/main/yang/meter-types.yang b/opendaylight/md-sal/model/model-flow-base/src/main/yang/meter-types.yang index d26ca66799..fc9be63ec8 100644 --- a/opendaylight/md-sal/model/model-flow-base/src/main/yang/meter-types.yang +++ b/opendaylight/md-sal/model/model-flow-base/src/main/yang/meter-types.yang @@ -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 { diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java index 36b46a171c..9608d65e41 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonMapper.java @@ -47,26 +47,13 @@ class JsonMapper { checkNotNull(parent); checkNotNull(parentSchema); - List longestPathToElementViaChoiceCase = new ArrayList<>(); for (Node child : parent.getChildren()) { - Deque 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 resolveLongerPath(List l1, List l2) { - return l1.size() > l2.size() ? l1 : l2; - } - - private SchemaLocation findFirstSchemaForNode(Node node, Set dataSchemaNode, - Deque pathIterator) { - Map choiceSubnodes = new HashMap<>(); + private DataSchemaNode findFirstSchemaForNode(Node node, Set 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 index 24055ced67..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/SchemaLocation.java +++ /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 location = new ArrayList<>(); - final private DataSchemaNode schema; - - public SchemaLocation(DataSchemaNode schema) { - this.schema = schema; - } - - DataSchemaNode getSchema() { - return schema; - } - - List getLocation() { - return location; - } - - SchemaLocation addPathPart(String partOfPath) { - location.add(partOfPath); - return this; - } - -} diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend index 29ad7522c4..1b0fda41ca 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend @@ -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 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/CompositeNodeWrapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/CompositeNodeWrapper.java index e000c7e29e..c741c9aa19 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/CompositeNodeWrapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/CompositeNodeWrapper.java @@ -24,6 +24,7 @@ public final class CompositeNodeWrapper implements NodeWrapper, C private String localName; private URI namespace; + private QName name; private List> values = new ArrayList<>(); public CompositeNodeWrapper(String localName) { @@ -34,6 +35,12 @@ public final class CompositeNodeWrapper implements NodeWrapper, 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, C @Override public CompositeNode unwrap(CompositeNode parent) { if (compositeNode == null) { - Preconditions.checkNotNull(namespace); - compositeNode = NodeFactory.createMutableCompositeNode(new QName(namespace, localName), - parent, new ArrayList>(), ModifyAction.CREATE, null); + if (name == null) { + Preconditions.checkNotNull(namespace); + name = new QName(namespace, localName); + } + compositeNode = NodeFactory.createMutableCompositeNode(name, parent, new ArrayList>(), null, null); List> nodeValues = new ArrayList<>(); for (NodeWrapper nodeWrapper : values) { @@ -88,6 +97,7 @@ public final class CompositeNodeWrapper implements NodeWrapper, C values = null; namespace = null; localName = null; + name = null; } return compositeNode; } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index 065d01e8e9..882c73d001 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -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 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NodeWrapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NodeWrapper.java index 0a3616e494..db7770fc68 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NodeWrapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NodeWrapper.java @@ -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> { + void setQname(QName name); + T unwrap(CompositeNode parent); URI getNamespace(); diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend index b6426c65bf..b730754439 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend @@ -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> 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 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 } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java index 4600d0890b..1b103b43c2 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java @@ -18,6 +18,7 @@ public final class SimpleNodeWrapper implements NodeWrapper>, 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>, 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>, Simp @Override public SimpleNode 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; } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java index 141ffdb754..8e3ff1d2ed 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ToJsonChoiceCaseTest.java @@ -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); + } + } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/choice.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/choice.yang index 8b02a92979..a6a32df52e 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/choice.yang +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/choice.yang @@ -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 index 0000000000..b669842c22 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml @@ -0,0 +1,4 @@ + + 45 + lf2b val + \ 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.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml index 9c751949d0..97e219736f 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml @@ -2,4 +2,5 @@ lf11c val + lf2b value \ 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 index 0000000000..331c8aec08 --- /dev/null +++ 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 @@ -0,0 +1,7 @@ + + + lf11c val + + lf2b value + lf2b value + \ 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 index 0000000000..ecc0caae56 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml @@ -0,0 +1,13 @@ + + lf1aaa value + lf2b value + + 33 + + + 33 + + + 37 + + \ 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_various_path.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_various_path_err.xml similarity index 100% rename from opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_various_path.xml rename to opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/choice/xml/data_various_path_err.xml diff --git a/opendaylight/netconf/config-persister-impl/pom.xml b/opendaylight/netconf/config-persister-impl/pom.xml index 6b3dfc7173..c6caf417a1 100644 --- a/opendaylight/netconf/config-persister-impl/pom.xml +++ b/opendaylight/netconf/config-persister-impl/pom.xml @@ -95,6 +95,9 @@ org.slf4j, org.w3c.dom, org.xml.sax, + javax.xml.namespace, + javax.xml.xpath, + org.opendaylight.controller.config.api diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java index a569f90538..d83b1eaaf3 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java @@ -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.emptySet()); + logger.info("No last config provided by backend storage {}", persister); + } + registerAsJMXListener(); + } + + private void pushLastConfigWithRetries(Optional 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.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 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.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 index 0000000000..6c45c9c011 --- /dev/null +++ b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandlerTest.java @@ -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 index 0000000000..f65e0e0bc2 --- /dev/null +++ b/opendaylight/netconf/config-persister-impl/src/test/resources/conflictingVersionResponse.xml @@ -0,0 +1,13 @@ + + + application + operation-failed + error + + + + + org.opendaylight.controller.config.api.ConflictingVersionException: Optimistic lock failed. Expected parent version 21, was 18 + + +