From: Tom Pantelis Date: Tue, 24 Feb 2015 00:47:19 +0000 (+0000) Subject: Merge "BUG 2676 : Use transaction-dispatcher for ShardTransaction" X-Git-Tag: release/lithium~473^2~15 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=8e8516351a527f6bafb1598d679547cfbbe029f9;hp=330c67bcbc25e7f5586b9a75bc8c65ef5f403b8a Merge "BUG 2676 : Use transaction-dispatcher for ShardTransaction" --- diff --git a/features/akka/pom.xml b/features/akka/pom.xml index f804505c64..4185972180 100644 --- a/features/akka/pom.xml +++ b/features/akka/pom.xml @@ -174,9 +174,8 @@ --> - org.opendaylight.yangtools + org.opendaylight.odlparent features-test - ${feature.test.version} test @@ -249,7 +248,7 @@ ${karaf.empty.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/config-netty/pom.xml b/features/config-netty/pom.xml index 0057fc05c7..71b28415b5 100644 --- a/features/config-netty/pom.xml +++ b/features/config-netty/pom.xml @@ -56,7 +56,7 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test @@ -114,7 +114,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/config-persister/pom.xml b/features/config-persister/pom.xml index f3b42ca143..6fae0e7641 100644 --- a/features/config-persister/pom.xml +++ b/features/config-persister/pom.xml @@ -81,7 +81,7 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test @@ -139,7 +139,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/config/pom.xml b/features/config/pom.xml index 1fa248615c..683ce3dab1 100644 --- a/features/config/pom.xml +++ b/features/config/pom.xml @@ -88,7 +88,7 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test @@ -146,7 +146,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/extras/pom.xml b/features/extras/pom.xml index 20089c726a..6ac5872f00 100644 --- a/features/extras/pom.xml +++ b/features/extras/pom.xml @@ -23,7 +23,6 @@ 1.1.0-SNAPSHOT 1.5.0-SNAPSHOT 3.0.1 - 0.7.0-SNAPSHOT 1.5.0-SNAPSHOT 2.16 @@ -34,9 +33,8 @@ ${jolokia.version} - org.opendaylight.yangtools + org.opendaylight.odlparent features-test - ${feature.test.version} test @@ -101,7 +99,7 @@ ${karaf.empty.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/flow/pom.xml b/features/flow/pom.xml index 53b45d2810..ad513e5d56 100644 --- a/features/flow/pom.xml +++ b/features/flow/pom.xml @@ -74,7 +74,7 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test @@ -132,7 +132,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/mdsal/pom.xml b/features/mdsal/pom.xml index c63b39c74d..35edb286ab 100644 --- a/features/mdsal/pom.xml +++ b/features/mdsal/pom.xml @@ -246,6 +246,15 @@ sal-inmemory-datastore + + org.opendaylight.controller + mdsal-netconf-connector + + + org.opendaylight.controller + mdsal-netconf-monitoring + + org.opendaylight.controller sal-netconf-connector @@ -354,9 +363,8 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test - 0.7.0-SNAPSHOT @@ -413,7 +421,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/mdsal/src/main/resources/features.xml b/features/mdsal/src/main/resources/features.xml index 5b9f4a674a..4b9f8c2288 100644 --- a/features/mdsal/src/main/resources/features.xml +++ b/features/mdsal/src/main/resources/features.xml @@ -24,12 +24,14 @@ - + + odl-config-all odl-netconf-all mvn:org.opendaylight.controller/netconf-ssh/${netconf.version} odl-mdsal-broker mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version} + mvn:org.opendaylight.controller/mdsal-netconf-monitoring/${netconf.version} mvn:org.opendaylight.controller/netconf-config-dispatcher/${config.version} mvn:org.opendaylight.controller/netconf-config/${netconf.version}/xml/config diff --git a/features/netconf-connector/pom.xml b/features/netconf-connector/pom.xml index 4e94996634..9cb2b1e33f 100644 --- a/features/netconf-connector/pom.xml +++ b/features/netconf-connector/pom.xml @@ -119,10 +119,6 @@ org.opendaylight.controller netconf-config-dispatcher - - org.opendaylight.controller - mdsal-netconf-connector - org.opendaylight.controller netconf-tcp @@ -168,9 +164,8 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test - ${yangtools.version} test @@ -242,7 +237,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/netconf-connector/src/main/resources/features.xml b/features/netconf-connector/src/main/resources/features.xml index 92e6507d21..7cabbb4929 100644 --- a/features/netconf-connector/src/main/resources/features.xml +++ b/features/netconf-connector/src/main/resources/features.xml @@ -105,6 +105,7 @@ odl-netconf-tcp + odl-config-netty diff --git a/features/netconf/pom.xml b/features/netconf/pom.xml index 4edd936294..b28a53b65c 100644 --- a/features/netconf/pom.xml +++ b/features/netconf/pom.xml @@ -150,9 +150,8 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test - ${yangtools.version} test @@ -218,7 +217,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/netconf/src/main/resources/features.xml b/features/netconf/src/main/resources/features.xml index a65502124b..aa8287d709 100644 --- a/features/netconf/src/main/resources/features.xml +++ b/features/netconf/src/main/resources/features.xml @@ -27,6 +27,7 @@ mvn:org.opendaylight.controller/ietf-netconf-monitoring-extension/${project.version} mvn:org.opendaylight.yangtools.model/ietf-inet-types/${ietf-inet-types.version} mvn:org.opendaylight.yangtools.model/ietf-yang-types/${ietf-yang-types.version} + mvn:org.opendaylight.yangtools.model/ietf-yang-types-20130715/2013.07.15.7-SNAPSHOT odl-netconf-api diff --git a/features/protocol-framework/pom.xml b/features/protocol-framework/pom.xml index d5387b43c3..f663c1ce3e 100644 --- a/features/protocol-framework/pom.xml +++ b/features/protocol-framework/pom.xml @@ -28,7 +28,7 @@ - org.opendaylight.yangtools + org.opendaylight.odlparent features-test @@ -86,7 +86,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/features/restconf/pom.xml b/features/restconf/pom.xml index 632b4cd592..347a19a75a 100644 --- a/features/restconf/pom.xml +++ b/features/restconf/pom.xml @@ -256,9 +256,8 @@ --> - org.opendaylight.yangtools + org.opendaylight.odlparent features-test - ${yangtools.version} test @@ -331,7 +330,7 @@ ${commons.opendaylight.version} - org.opendaylight.yangtools:features-test + org.opendaylight.odlparent:features-test diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/META-INF/maven/archetype-metadata.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/META-INF/maven/archetype-metadata.xml index 7057a86fe5..6eab884cc5 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -28,7 +28,7 @@ - __artifactId__-karaf + karaf pom.xml @@ -37,13 +37,13 @@ - __artifactId__-features + features pom.xml - __artifactId__-features/src/main/features + features/src/main/features **/*.xml @@ -52,25 +52,31 @@ - __artifactId__-impl + impl pom.xml - __artifactId__-impl/src/main/java + impl/src/main/java **/*.java - __artifactId__-impl/src/main/config + impl/src/test/java + + **/*.java + + + + impl/src/main/config **/*.xml - __artifactId__-impl/src/main/yang + impl/src/main/yang **/*.yang @@ -79,13 +85,13 @@ - __artifactId__-api + api pom.xml - __artifactId__-api/src/main/yang + api/src/main/yang **/*.yang @@ -93,7 +99,7 @@ - __artifactId__-artifacts + artifacts pom.xml diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-api/.gitignore b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/api/.gitignore similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-api/.gitignore rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/api/.gitignore diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-api/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/api/pom.xml similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-api/pom.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/api/pom.xml diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-api/src/main/yang/__artifactId__.yang b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/api/src/main/yang/__artifactId__.yang similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-api/src/main/yang/__artifactId__.yang rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/api/src/main/yang/__artifactId__.yang diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-artifacts/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/artifacts/pom.xml similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-artifacts/pom.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/artifacts/pom.xml diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/pom.xml similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/pom.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/pom.xml diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/src/main/features/features.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/src/main/features/features.xml similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/src/main/features/features.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/src/main/features/features.xml diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/pom.xml similarity index 80% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/pom.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/pom.xml index 64d6834fef..f9e77ed4b1 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/pom.xml +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/pom.xml @@ -29,6 +29,19 @@ and is available at http://www.eclipse.org/legal/epl-v10.html ${artifactId}-api ${symbol_dollar}{project.version} + + + + junit + junit + test + + + + org.mockito + mockito-all + test + diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/config/default-config.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml similarity index 96% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/config/default-config.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml index e777fd25bc..2e73bde717 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/config/default-config.xml +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml @@ -20,7 +20,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - prefix:${artifactId}-impl + prefix:${artifactId} ${artifactId}-default binding:binding-broker-osgi-registry diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/__packageInPathFormat__/__classPrefix__Provider.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/__packageInPathFormat__/__classPrefix__Provider.java similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/__packageInPathFormat__/__classPrefix__Provider.java rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/__packageInPathFormat__/__classPrefix__Provider.java diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ImplModule.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__Module.java similarity index 58% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ImplModule.java rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__Module.java index 558b018788..3290e85469 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ImplModule.java +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__Module.java @@ -12,12 +12,12 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artif import ${package}.${classPrefix}Provider; -public class ${classPrefix}ImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210.Abstract${classPrefix}ImplModule { - public ${classPrefix}ImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { +public class ${classPrefix}Module extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210.Abstract${classPrefix}Module { + public ${classPrefix}Module(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public ${classPrefix}ImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210.${classPrefix}ImplModule oldModule, java.lang.AutoCloseable oldInstance) { + public ${classPrefix}Module(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210.${classPrefix}Module oldModule, java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ImplModuleFactory.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleFactory.java similarity index 80% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ImplModuleFactory.java rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleFactory.java index a531fe076e..596549b5fe 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ImplModuleFactory.java +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleFactory.java @@ -18,6 +18,6 @@ * Do not modify this file unless it is present under src/main directory */ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210; -public class ${classPrefix}ImplModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210.Abstract${classPrefix}ImplModuleFactory { +public class ${classPrefix}ModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210.Abstract${classPrefix}ModuleFactory { } diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/yang/__artifactId__-impl.yang b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang similarity index 87% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/yang/__artifactId__-impl.yang rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang index 7b00b849a1..41a74b3f1a 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-impl/src/main/yang/__artifactId__-impl.yang +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang @@ -14,14 +14,14 @@ module ${artifactId}-impl { "Initial revision"; } - identity ${artifactId}-impl { + identity ${artifactId} { base config:module-type; - config:java-name-prefix ${classPrefix}Impl; + config:java-name-prefix ${classPrefix}; } augment "/config:modules/config:module/config:configuration" { - case ${artifactId}-impl { - when "/config:modules/config:module/config:type = '${artifactId}-impl'"; + case ${artifactId} { + when "/config:modules/config:module/config:type = '${artifactId}'"; container broker { uses config:service-ref { refine type { diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/__packageInPathFormat__/__classPrefix__ProviderTest.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/__packageInPathFormat__/__classPrefix__ProviderTest.java new file mode 100644 index 0000000000..5422c00a40 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/__packageInPathFormat__/__classPrefix__ProviderTest.java @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +#set( $provider = "${classPrefix}Provider" ) +/* + * ${copyright} 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 ${package}; + +import org.junit.Test; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; + +import static org.mockito.Mockito.mock; + +public class ${classPrefix}ProviderTest { + @Test + public void testOnSessionInitiated() { + ${provider} provider = new ${provider}(); + + // ensure no exceptions + // currently this method is empty + provider.onSessionInitiated(mock(BindingAwareBroker.ProviderContext.class)); + } + + @Test + public void testClose() throws Exception { + ${provider} provider = new ${provider}(); + + // ensure no exceptions + // currently this method is empty + provider.close(); + } +} diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleFactoryTest.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleFactoryTest.java new file mode 100644 index 0000000000..9f8991f3ec --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleFactoryTest.java @@ -0,0 +1,22 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +#set( $factory = "${classPrefix}ModuleFactory" ) +/* + * ${copyright} 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210; + +import org.junit.Test; + +public class ${classPrefix}ModuleFactoryTest { + @Test + public void testFactoryConstructor() { + // ensure no exceptions on construction + new ${factory}(); + } +} diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleTest.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleTest.java new file mode 100644 index 0000000000..0f921ee371 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/__artifactId__/impl/rev141210/__classPrefix__ModuleTest.java @@ -0,0 +1,58 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +#set( $module = "${classPrefix}Module" ) +/* + * ${copyright} 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210; + +import org.junit.Test; +import org.opendaylight.controller.config.api.DependencyResolver; +import org.opendaylight.controller.config.api.JmxAttribute; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import ${package}.${classPrefix}Provider; + +import javax.management.ObjectName; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ${classPrefix}ModuleTest { + @Test + public void testCustomValidation() { + ${module} module = new ${module}(mock(ModuleIdentifier.class), mock(DependencyResolver.class)); + + // ensure no exceptions on validation + // currently this method is empty + module.customValidation(); + } + + @Test + public void testCreateInstance() throws Exception { + // configure mocks + DependencyResolver dependencyResolver = mock(DependencyResolver.class); + BindingAwareBroker broker = mock(BindingAwareBroker.class); + when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker); + + // create instance of module with injected mocks + ${module} module = new ${module}(mock(ModuleIdentifier.class), dependencyResolver); + + // getInstance calls resolveInstance to get the broker dependency and then calls createInstance + AutoCloseable closeable = module.getInstance(); + + // verify that the module registered the returned provider with the broker + verify(broker).registerProvider((${classPrefix}Provider)closeable); + + // ensure no exceptions on close + closeable.close(); + } +} diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-karaf/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/karaf/pom.xml similarity index 100% rename from opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-karaf/pom.xml rename to opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/karaf/pom.xml diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/pom.xml index 3221efd362..067d4db4e9 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/pom.xml +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/pom.xml @@ -9,18 +9,18 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL ${groupId} ${artifactId}-aggregator ${version} - ${project.artifactId} + ${artifactId} pom 4.0.0 3.1.1 - ${artifactId}-api - ${artifactId}-impl - ${artifactId}-karaf - ${artifactId}-features - ${artifactId}-artifacts + api + impl + karaf + features + artifacts diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 9a88e61007..7a977f9545 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -15,7 +15,7 @@ - 2.3.4 + 2.3.9 0.5.0-SNAPSHOT 0.1.0-SNAPSHOT 0.6.0-SNAPSHOT @@ -81,6 +81,7 @@ 0000.0002.0038.0 1.6.0 + 1.5.0-SNAPSHOT 1.5.0-SNAPSHOT 2.4.0 0.5.0-SNAPSHOT @@ -104,7 +105,6 @@ src/main/yang-gen-config 0.1.0-SNAPSHOT 1.1.4 - 2.0.1 1.1.1 2.0 1.1.0-SNAPSHOT @@ -287,11 +287,6 @@ java-concurrent-hash-trie-map ${ctrie.version} - - com.google.code.findbugs - jsr305 - ${jsr305.api.version} - com.google.code.gson gson @@ -310,9 +305,10 @@ - com.jcabi - jcabi-maven-slf4j - 0.8 + org.apache.maven + maven-core + 3.1.1 + provided @@ -1194,6 +1190,12 @@ ${yangtools.version} test + + org.opendaylight.odlparent + features-test + ${features.test.version} + test + org.opendaylight.yangtools features-yangtools diff --git a/opendaylight/config/yang-jmx-generator-plugin/pom.xml b/opendaylight/config/yang-jmx-generator-plugin/pom.xml index 6c8a591bb8..ae190848c9 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/pom.xml +++ b/opendaylight/config/yang-jmx-generator-plugin/pom.xml @@ -21,11 +21,6 @@ guava - - com.jcabi - jcabi-maven-slf4j - - commons-io commons-io @@ -36,17 +31,6 @@ commons-lang3 - - org.codehaus.gmaven.runtime - gmaven-runtime-2.0 - - - org.sonatype.gossip - gossip - - - - org.opendaylight.controller yang-jmx-generator @@ -66,6 +50,10 @@ org.opendaylight.yangtools yang-maven-plugin-spi + + org.apache.maven + maven-core + org.slf4j diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java index 9ad8d2826f..1f1776f0a5 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java @@ -23,7 +23,6 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; @@ -35,42 +34,54 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang2sources.spi.CodeGenerator; +import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator; +import org.opendaylight.yangtools.yang2sources.spi.MavenProjectAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.StaticLoggerBinder; /** * This class interfaces with yang-maven-plugin. Gets parsed yang modules in * {@link SchemaContext}, and parameters form the plugin configuration, and * writes service interfaces and/or modules. */ -public class JMXGenerator implements CodeGenerator { +public class JMXGenerator implements BasicCodeGenerator, MavenProjectAware { + private static final class NamespaceMapping { + private final String namespace, packageName; + public NamespaceMapping(final String namespace, final String packagename) { + this.namespace = namespace; + this.packageName = packagename; + } + } + + @VisibleForTesting static final String NAMESPACE_TO_PACKAGE_DIVIDER = "=="; + @VisibleForTesting static final String NAMESPACE_TO_PACKAGE_PREFIX = "namespaceToPackage"; + @VisibleForTesting static final String MODULE_FACTORY_FILE_BOOLEAN = "moduleFactoryFile"; + private static final Logger LOG = LoggerFactory.getLogger(JMXGenerator.class); + private static final Pattern NAMESPACE_MAPPING_PATTERN = Pattern.compile("(.+)" + NAMESPACE_TO_PACKAGE_DIVIDER + "(.+)"); + private PackageTranslator packageTranslator; private final CodeWriter codeWriter; - private static final Logger LOG = LoggerFactory - .getLogger(JMXGenerator.class); private Map namespaceToPackageMapping; private File resourceBaseDir; private File projectBaseDir; private boolean generateModuleFactoryFile = true; public JMXGenerator() { - this.codeWriter = new CodeWriter(); + this(new CodeWriter()); } - public JMXGenerator(CodeWriter codeWriter) { + public JMXGenerator(final CodeWriter codeWriter) { this.codeWriter = codeWriter; } @Override - public Collection generateSources(SchemaContext context, - File outputBaseDir, Set yangModulesInCurrentMavenModule) { + public Collection generateSources(final SchemaContext context, + final File outputBaseDir, final Set yangModulesInCurrentMavenModule) { Preconditions.checkArgument(context != null, "Null context received"); Preconditions.checkArgument(outputBaseDir != null, @@ -173,7 +184,8 @@ public class JMXGenerator implements CodeGenerator { return generatedFiles.getFiles(); } - static File concatFolders(File projectBaseDir, String... folderNames) { + @VisibleForTesting + static File concatFolders(final File projectBaseDir, final String... folderNames) { StringBuilder b = new StringBuilder(); for (String folder : folderNames) { b.append(folder); @@ -183,18 +195,14 @@ public class JMXGenerator implements CodeGenerator { } @Override - public void setAdditionalConfig(Map additionalCfg) { - if (LOG != null) { - LOG.debug(getClass().getCanonicalName(), - ": Additional configuration received: ", - additionalCfg.toString()); - } + public void setAdditionalConfig(final Map additionalCfg) { + LOG.debug("{}: Additional configuration received: {}", getClass().getCanonicalName(), additionalCfg); this.namespaceToPackageMapping = extractNamespaceMapping(additionalCfg); this.generateModuleFactoryFile = extractModuleFactoryBoolean(additionalCfg); } private boolean extractModuleFactoryBoolean( - Map additionalCfg) { + final Map additionalCfg) { String bool = additionalCfg.get(MODULE_FACTORY_FILE_BOOLEAN); if (bool == null) { return true; @@ -205,13 +213,8 @@ public class JMXGenerator implements CodeGenerator { return true; } - @Override - public void setLog(Log log) { - StaticLoggerBinder.getSingleton().setMavenLog(log); - } - private static Map extractNamespaceMapping( - Map additionalCfg) { + final Map additionalCfg) { Map namespaceToPackage = Maps.newHashMap(); for (String key : additionalCfg.keySet()) { if (key.startsWith(NAMESPACE_TO_PACKAGE_PREFIX)) { @@ -224,46 +227,30 @@ public class JMXGenerator implements CodeGenerator { return namespaceToPackage; } - static Pattern namespaceMappingPattern = Pattern.compile("(.+)" - + NAMESPACE_TO_PACKAGE_DIVIDER + "(.+)"); - - private static NamespaceMapping extractNamespaceMapping(String mapping) { - Matcher matcher = namespaceMappingPattern.matcher(mapping); - Preconditions - .checkArgument(matcher.matches(), String.format("Namespace to package mapping:%s is in invalid " + - "format, requested format is: %s", mapping, namespaceMappingPattern)); + private static NamespaceMapping extractNamespaceMapping(final String mapping) { + Matcher matcher = NAMESPACE_MAPPING_PATTERN.matcher(mapping); + Preconditions.checkArgument(matcher.matches(), + "Namespace to package mapping:%s is in invalid format, requested format is: %s", + mapping, NAMESPACE_MAPPING_PATTERN); return new NamespaceMapping(matcher.group(1), matcher.group(2)); } - private static class NamespaceMapping { - public NamespaceMapping(String namespace, String packagename) { - this.namespace = namespace; - this.packageName = packagename; - } - - private final String namespace, packageName; - } - @Override - public void setResourceBaseDir(File resourceDir) { + public void setResourceBaseDir(final File resourceDir) { this.resourceBaseDir = resourceDir; } @Override - public void setMavenProject(MavenProject project) { + public void setMavenProject(final MavenProject project) { this.projectBaseDir = project.getBasedir(); - - if (LOG != null) { - LOG.debug(getClass().getCanonicalName(), " project base dir: ", - projectBaseDir); - } + LOG.debug("{}: project base dir: {}", getClass().getCanonicalName(), projectBaseDir); } @VisibleForTesting static class GeneratedFilesTracker { private final Set files = Sets.newHashSet(); - void addFile(File file) { + void addFile(final File file) { if (files.contains(file)) { List undeletedFiles = Lists.newArrayList(); for (File presentFile : files) { @@ -283,7 +270,7 @@ public class JMXGenerator implements CodeGenerator { files.add(file); } - void addFile(Collection files) { + void addFile(final Collection files) { for (File file : files) { addFile(file); } diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java index 19e875f9b1..00454d8acf 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java @@ -48,9 +48,9 @@ import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Meth import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition; import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField; import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper; -import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.binding.BindingMapping; public class TemplateFactory { @@ -59,7 +59,7 @@ public class TemplateFactory { * bean as value that should be persisted from this instance. */ public static Map getTOAndMXInterfaceFtlFiles( - RuntimeBeanEntry entry) { + final RuntimeBeanEntry entry) { Map result = new HashMap<>(); { // create GeneralInterfaceFtlFile for runtime MXBean. Attributes will // be transformed to getter methods @@ -109,7 +109,7 @@ public class TemplateFactory { } // FIXME: put into Type.toString - static String serializeType(Type type, boolean addWildcards) { + static String serializeType(final Type type, final boolean addWildcards) { if (type instanceof ParameterizedType){ ParameterizedType parameterizedType = (ParameterizedType) type; StringBuilder sb = new StringBuilder(); @@ -131,11 +131,11 @@ public class TemplateFactory { } } - static String serializeType(Type type) { + static String serializeType(final Type type) { return serializeType(type, false); } - private static String getReturnType(AttributeIfc attributeIfc) { + private static String getReturnType(final AttributeIfc attributeIfc) { String returnType; if (attributeIfc instanceof TypedAttribute) { Type type = ((TypedAttribute) attributeIfc).getType(); @@ -151,7 +151,7 @@ public class TemplateFactory { } public static GeneralInterfaceTemplate serviceInterfaceFromSie( - ServiceInterfaceEntry sie) { + final ServiceInterfaceEntry sie) { List extendedInterfaces = Lists .newArrayList(AbstractServiceInterface.class.getCanonicalName()); @@ -177,7 +177,7 @@ public class TemplateFactory { } public static AbstractFactoryTemplate abstractFactoryTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { AbstractFactoryAttributesProcessor attrProcessor = new AbstractFactoryAttributesProcessor(); attrProcessor.processAttributes(mbe.getAttributes(), mbe.getPackageName()); @@ -191,7 +191,7 @@ public class TemplateFactory { } public static AbstractModuleTemplate abstractModuleTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { AbstractModuleAttributesProcessor attrProcessor = new AbstractModuleAttributesProcessor(mbe.getAttributes()); List moduleFields = attrProcessor.getModuleFields(); @@ -234,7 +234,7 @@ public class TemplateFactory { } public static StubFactoryTemplate stubFactoryTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { return new StubFactoryTemplate(getHeaderFromEntry(mbe), mbe.getPackageName(), mbe.getStubFactoryName(), mbe.getFullyQualifiedName(mbe.getAbstractFactoryName()) @@ -242,7 +242,7 @@ public class TemplateFactory { } public static GeneralInterfaceTemplate mXBeanInterfaceTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { MXBeanInterfaceAttributesProcessor attrProcessor = new MXBeanInterfaceAttributesProcessor(); attrProcessor.processAttributes(mbe.getAttributes()); GeneralInterfaceTemplate ifcTemplate = new GeneralInterfaceTemplate( @@ -254,7 +254,7 @@ public class TemplateFactory { } public static Map tOsFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { Map retVal = Maps.newHashMap(); TOAttributesProcessor processor = new TOAttributesProcessor(); processor.processAttributes(mbe.getAttributes()); @@ -275,7 +275,7 @@ public class TemplateFactory { } public static Map tOsFromRbe( - RuntimeBeanEntry rbe) { + final RuntimeBeanEntry rbe) { Map retVal = Maps.newHashMap(); TOAttributesProcessor processor = new TOAttributesProcessor(); Map yangPropertiesToTypesMap = Maps.newHashMap(rbe.getYangPropertiesToTypesMap()); @@ -316,7 +316,7 @@ public class TemplateFactory { return retVal; } - private static Header getHeaderFromEntry(AbstractEntry mbe) { + private static Header getHeaderFromEntry(final AbstractEntry mbe) { return new Header(mbe.getYangModuleName(), mbe.getYangModuleLocalname()); } @@ -326,7 +326,7 @@ public class TemplateFactory { private final List tos = Lists.newArrayList(); - void processAttributes(Map attributes) { + void processAttributes(final Map attributes) { for (Entry attrEntry : attributes.entrySet()) { AttributeIfc attributeIfc = attrEntry.getValue(); if (attributeIfc instanceof TOAttribute) { @@ -342,7 +342,7 @@ public class TemplateFactory { } } - private void createTOInternal(TOAttribute toAttribute) { + private void createTOInternal(final TOAttribute toAttribute) { Map attrs = toAttribute.getCapitalizedPropertiesToTypesMap(); // recursive processing of TO's attributes @@ -360,12 +360,12 @@ public class TemplateFactory { private List fields; private List methods; - public TOInternal(Type type, Map attrs) { + public TOInternal(final Type type, final Map attrs) { this(type.getFullyQualifiedName(), type.getName(), attrs, type.getPackageName()); } - public TOInternal(String fullyQualifiedName, String name, - Map attrs, String packageName) { + public TOInternal(final String fullyQualifiedName, final String name, + final Map attrs, final String packageName) { this.fullyQualifiedName = fullyQualifiedName; this.name = name; processAttrs(attrs, packageName); @@ -374,7 +374,7 @@ public class TemplateFactory { private final static String dependencyResolverVarName = "dependencyResolver"; private final static String dependencyResolverInjectMethodName = "injectDependencyResolver"; - private void processAttrs(Map attrs, String packageName) { + private void processAttrs(final Map attrs, final String packageName) { fields = Lists.newArrayList(); methods = Lists.newArrayList(); @@ -386,8 +386,7 @@ public class TemplateFactory { for (Entry attrEntry : attrs.entrySet()) { String innerName = attrEntry.getKey(); - String varName = BindingGeneratorUtil - .parseToValidParamName(attrEntry.getKey()); + String varName = BindingMapping.getPropertyName(attrEntry.getKey()); String fullyQualifiedName, nullableDefault = null; if (attrEntry.getValue() instanceof TypedAttribute) { @@ -449,7 +448,7 @@ public class TemplateFactory { private static class MXBeanInterfaceAttributesProcessor { private final List methods = Lists.newArrayList(); - void processAttributes(Map attributes) { + void processAttributes(final Map attributes) { for (Entry attrEntry : attributes.entrySet()) { String returnType; AttributeIfc attributeIfc = attrEntry.getValue(); @@ -473,8 +472,7 @@ public class TemplateFactory { MethodDeclaration getter = new MethodDeclaration(returnType, getterName, Collections. emptyList()); - String varName = BindingGeneratorUtil - .parseToValidParamName(attrEntry.getKey()); + String varName = BindingMapping.getPropertyName(attrEntry.getKey()); String setterName = "set" + attributeIfc.getUpperCaseCammelCase(); MethodDeclaration setter = new MethodDeclaration("void", @@ -519,8 +517,8 @@ public class TemplateFactory { private final List fields = Lists.newArrayList(); - void processAttributes(Map attributes, - String packageName) { + void processAttributes(final Map attributes, + final String packageName) { for (Entry attrEntry : attributes.entrySet()) { String type; String nullableDefaultWrapped = null; @@ -550,7 +548,7 @@ public class TemplateFactory { private final List moduleFields; private final List methods; - private Holder(List moduleFields, List methods) { + private Holder(final List moduleFields, final List methods) { this.moduleFields = Collections.unmodifiableList(moduleFields); this.methods = Collections.unmodifiableList(methods); } @@ -559,11 +557,11 @@ public class TemplateFactory { private final Holder holder; - private AbstractModuleAttributesProcessor(Map attributes) { + private AbstractModuleAttributesProcessor(final Map attributes) { this.holder = processAttributes(attributes); } - private static Holder processAttributes(Map attributes) { + private static Holder processAttributes(final Map attributes) { List moduleFields = new ArrayList<>(); List methods = new ArrayList<>(); for (Entry attrEntry : attributes.entrySet()) { @@ -607,8 +605,7 @@ public class TemplateFactory { } } - String varName = BindingGeneratorUtil - .parseToValidParamName(attrEntry.getKey()); + String varName = BindingMapping.getPropertyName(attrEntry.getKey()); ModuleField field; if (isIdentity) { @@ -689,7 +686,7 @@ public class TemplateFactory { } - private static boolean needsDepResolver(AttributeIfc value) { + private static boolean needsDepResolver(final AttributeIfc value) { if(value instanceof TOAttribute) { return true; } @@ -701,7 +698,7 @@ public class TemplateFactory { return false; } - private static String getInnerTypeFromIdentity(Type type) { + private static String getInnerTypeFromIdentity(final Type type) { Preconditions.checkArgument(type instanceof ParameterizedType); Type[] args = ((ParameterizedType) type).getActualTypeArguments(); Preconditions.checkArgument(args.length ==1); 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 a6cfc58c34..3dae004161 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 @@ -16,11 +16,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; - import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; @@ -42,7 +39,6 @@ import java.util.Set; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.IProblem; @@ -124,13 +120,6 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { File targetDir = new File(generatorOutputPath, "target"); generatedResourcesDir = new File(targetDir, "generated-resources"); jmxGenerator.setResourceBaseDir(generatedResourcesDir); - Log mockedLog = mock(Log.class); - doReturn(false).when(mockedLog).isDebugEnabled(); - doNothing().when(mockedLog).debug(any(CharSequence.class)); - doNothing().when(mockedLog).info(any(CharSequence.class)); - doNothing().when(mockedLog).error(any(CharSequence.class), - any(Throwable.class)); - jmxGenerator.setLog(mockedLog); MavenProject project = mock(MavenProject.class); doReturn(generatorOutputPath).when(project).getBasedir(); jmxGenerator.setMavenProject(project); @@ -158,18 +147,19 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { verifyModuleFactoryFile(false); } - private void verifyModuleFactoryFile(boolean shouldBePresent) { + private void verifyModuleFactoryFile(final boolean shouldBePresent) { File factoryFile = new File(generatedResourcesDir, "META-INF" + File.separator + "services" + File.separator + ModuleFactory.class.getName()); - if (!shouldBePresent) + if (!shouldBePresent) { assertFalse("Factory file should not be generated", factoryFile.exists()); - else + } else { assertTrue("Factory file should be generated", factoryFile.exists()); + } } - public static List toFileNames(Collection files) { + public static List toFileNames(final Collection files) { List result = new ArrayList<>(); for (File f : files) { result.add(f.getName()); @@ -279,7 +269,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { new Predicate() { @Override - public boolean apply(File input) { + public boolean apply(final File input) { return input.getName().endsWith("xml"); } }); @@ -288,7 +278,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { new Predicate() { @Override - public boolean apply(File input) { + public boolean apply(final File input) { return input.getName().endsWith("java"); } }); @@ -303,16 +293,21 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { String name = file.getName(); MbeASTVisitor visitor = new MbeASTVisitor(); verifiers.put(name, visitor); - if (name.equals("AbstractDynamicThreadPoolModule.java")) + if (name.equals("AbstractDynamicThreadPoolModule.java")) { abstractDynamicThreadPoolModuleVisitor = visitor; - if (name.equals("AsyncEventBusModuleMXBean.java")) + } + if (name.equals("AsyncEventBusModuleMXBean.java")) { asyncEventBusModuleMXBeanVisitor = visitor; - if (name.equals("AbstractNamingThreadFactoryModuleFactory.java")) + } + if (name.equals("AbstractNamingThreadFactoryModuleFactory.java")) { abstractNamingThreadFactoryModuleFactoryVisitor = visitor; - if (name.equals("AsyncEventBusModule.java")) + } + if (name.equals("AsyncEventBusModule.java")) { asyncEventBusModuleVisitor = visitor; - if (name.equals("EventBusModuleFactory.java")) + } + if (name.equals("EventBusModuleFactory.java")) { eventBusModuleFactoryVisitor = visitor; + } } processGeneratedCode(javaFiles, verifiers); @@ -348,25 +343,25 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } - private void verifyXmlFiles(Collection xmlFiles) throws Exception { + private void verifyXmlFiles(final Collection xmlFiles) throws Exception { ErrorHandler errorHandler = new ErrorHandler() { @Override - public void warning(SAXParseException exception) + public void warning(final SAXParseException exception) throws SAXException { fail("Generated blueprint xml is not well formed " + exception.getMessage()); } @Override - public void fatalError(SAXParseException exception) + public void fatalError(final SAXParseException exception) throws SAXException { fail("Generated blueprint xml is not well formed " + exception.getMessage()); } @Override - public void error(SAXParseException exception) throws SAXException { + public void error(final SAXParseException exception) throws SAXException { fail("Generated blueprint xml is not well formed " + exception.getMessage()); } @@ -386,7 +381,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } - private void assertEventBusModuleFactory(MbeASTVisitor visitor) { + private void assertEventBusModuleFactory(final MbeASTVisitor visitor) { assertEquals(PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX + ".threads.java", visitor.packageName); assertEquals("EventBusModuleFactory", visitor.type); @@ -406,7 +401,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { visitor.methodJavadoc.size()); } - private void assertAsyncEventBusModule(MbeASTVisitor visitor) { + private void assertAsyncEventBusModule(final MbeASTVisitor visitor) { assertEquals(PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX + ".threads.java", visitor.packageName); assertEquals("AsyncEventBusModule", visitor.type); @@ -427,7 +422,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } private void assertAbstractNamingThreadFactoryModuleFactory( - MbeASTVisitor visitor) { + final MbeASTVisitor visitor) { assertEquals(PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX + ".threads.java", visitor.packageName); assertEquals("AbstractNamingThreadFactoryModuleFactory", visitor.type); @@ -450,7 +445,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } - private void assertFactoryMethods(Set methods, int expectedSize) { + private void assertFactoryMethods(final Set methods, final int expectedSize) { List args = Lists.newArrayList(); ArgumentAssertion oldInstanceArg = new ArgumentAssertion(DynamicMBeanWithInstance.class.getCanonicalName(), "old"); @@ -496,12 +491,12 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } - private void assertMethodPresent(Set methods, MethodAssertion methodAssertion) { + private void assertMethodPresent(final Set methods, final MethodAssertion methodAssertion) { assertTrue(String.format("Generated methods did not contain %s, generated methods: %s", methodAssertion.toString(), methods), methods.contains(methodAssertion.toString())); } - private void assertAsyncEventBusModuleMXBean(MbeASTVisitor visitor) { + private void assertAsyncEventBusModuleMXBean(final MbeASTVisitor visitor) { assertEquals(PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX + ".threads.java", visitor.packageName); assertEquals("AsyncEventBusModuleMXBean", visitor.type); @@ -511,7 +506,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } - private void assertAbstractDynamicThreadPoolModule(MbeASTVisitor visitor) { + private void assertAbstractDynamicThreadPoolModule(final MbeASTVisitor visitor) { assertEquals(PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX + ".threads.java", visitor.packageName); assertNotNull(visitor.javadoc); @@ -557,8 +552,8 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { visitor.methodJavadoc.get("void setMaximumSize(java.lang.Long maximumSize)")); } - private void assertDeclaredField(Set fieldDeclarations, - String declaration) { + private void assertDeclaredField(final Set fieldDeclarations, + final String declaration) { assertTrue("Missing field " + declaration + ", got: " + fieldDeclarations, fieldDeclarations.contains(declaration + ";\n")); @@ -570,13 +565,13 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { protected Map methodDescriptions = Maps.newHashMap(); @Override - public boolean visit(PackageDeclaration node) { + public boolean visit(final PackageDeclaration node) { packageName = node.getName().toString(); return super.visit(node); } @Override - public boolean visit(NormalAnnotation node) { + public boolean visit(final NormalAnnotation node) { if (node.getTypeName().toString() .equals(Description.class.getCanonicalName())) { if (node.getParent() instanceof TypeDeclaration) { @@ -604,7 +599,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } @Override - public boolean visit(TypeDeclaration node) { + public boolean visit(final TypeDeclaration node) { javadoc = node.getJavadoc() == null ? null : node.getJavadoc() .toString(); type = node.getName().toString(); @@ -624,7 +619,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { private final Map methodJavadoc = Maps.newHashMap(); @Override - public boolean visit(NormalAnnotation node) { + public boolean visit(final NormalAnnotation node) { boolean result = super.visit(node); if (node.getTypeName().toString() .equals(RequireInterface.class.getCanonicalName()) @@ -638,16 +633,16 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } @Override - public boolean visit(FieldDeclaration node) { + public boolean visit(final FieldDeclaration node) { fieldDeclarations.add(node.toString()); return super.visit(node); } @Override - public boolean visit(MethodDeclaration node) { - if (node.isConstructor()) + public boolean visit(final MethodDeclaration node) { + if (node.isConstructor()) { constructors.add(node.toString()); - else { + } else { String methodSignature = node.getReturnType2() + " " + node.getName() + "("; boolean first = true; for (Object o : node.parameters()) { @@ -668,7 +663,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } @Override - public boolean visit(TypeDeclaration node) { + public boolean visit(final TypeDeclaration node) { boolean visit = super.visit(node); List superIfcs = node.superInterfaceTypes(); implmts = superIfcs != null && !superIfcs.isEmpty() ? superIfcs @@ -680,14 +675,14 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { } - private void assertContains(String source, String... contained) { + private void assertContains(final String source, final String... contained) { for (String string : contained) { assertThat(source, containsString(string)); } } - private void processGeneratedCode(Collection files, - Map verifiers) throws IOException { + private void processGeneratedCode(final Collection files, + final Map verifiers) throws IOException { ASTParser parser = ASTParser.newParser(AST.JLS3); Map options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options); @@ -705,27 +700,31 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { for (IProblem c : cu.getProblems()) { // 1610613332 = Syntax error, annotations are only available if // source level is 5.0 - if (c.getID() == 1610613332) + if (c.getID() == 1610613332) { continue; + } // 1610613332 = Syntax error, parameterized types are only // available if source level is 5.0 - if (c.getID() == 1610613329) + if (c.getID() == 1610613329) { continue; - if (c.getID() == 1610613328) // 'for each' statements are only available if source level is 5.0 + } + if (c.getID() == 1610613328) { continue; + } fail("Error in generated source code " + file + ":" + c.getSourceLineNumber() + " id: " + c.getID() + " message:" + c.toString()); } ASTVisitor visitor = verifiers.get(file.getName()); - if (visitor == null) + if (visitor == null) { fail("Unknown generated file " + file.getName()); + } cu.accept(visitor); } } - public static char[] readFileAsChars(File file) throws IOException { + public static char[] readFileAsChars(final File file) throws IOException { List readLines = Files .readLines(file, Charset.forName("utf-8")); char[] retVal = new char[0]; @@ -741,15 +740,15 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { private static class MethodAssertion extends ArgumentAssertion{ - private List arguments; + private final List arguments; - MethodAssertion(String type, String name, List arguments) { + MethodAssertion(final String type, final String name, final List arguments) { super(type, name); this.arguments = arguments; } - MethodAssertion(String type, String name) { + MethodAssertion(final String type, final String name) { this(type, name, Collections.emptyList()); } @@ -763,8 +762,9 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { for (ArgumentAssertion argument : arguments) { sb.append(argument.type).append(' '); sb.append(argument.name); - if(++i != arguments.size()) + if(++i != arguments.size()) { sb.append(','); + } } sb.append(')'); return sb.toString(); @@ -775,7 +775,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest { protected final String type, name; - private ArgumentAssertion(String type, String name) { + private ArgumentAssertion(final String type, final String name) { this.type = type; this.name = name; } diff --git a/opendaylight/md-sal/messagebus-impl/pom.xml b/opendaylight/md-sal/messagebus-impl/pom.xml index 8e088ba578..ccb72191c4 100644 --- a/opendaylight/md-sal/messagebus-impl/pom.xml +++ b/opendaylight/md-sal/messagebus-impl/pom.xml @@ -19,7 +19,6 @@ org.opendaylight.controller ietf-netconf-notifications - 0.3.0-SNAPSHOT org.opendaylight.controller @@ -95,7 +94,6 @@ org.codehaus.mojo build-helper-maven-plugin - 1.8 add-source diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/Topic.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/Topic.java index aebde0c043..a32413064e 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/Topic.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/Topic.java @@ -63,10 +63,7 @@ public class Topic implements DataChangeListener { public void notifyNode(final NodeId nodeId) { JoinTopicInput jti = getJoinTopicInputArgument(nodeId); EventSourceService ess = mdSal.getRpcService(EventSourceService.class); - - if (ess == null) { - throw new IllegalStateException("EventSourceService is not registered."); - } + Preconditions.checkState(ess != null, "EventSourceService is not registered"); ess.joinTopic(jti); } diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java index e2aa16918e..1aecc89eea 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.cluster.raft; +import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -187,9 +188,14 @@ public abstract class AbstractReplicatedLogImpl implements ReplicatedLog { @Override public void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm) { + Preconditions.checkArgument(snapshotCapturedIndex >= snapshotIndex, + "snapshotCapturedIndex must be greater than or equal to snapshotIndex"); + snapshottedJournal = new ArrayList<>(journal.size()); - snapshottedJournal.addAll(journal.subList(0, (int)(snapshotCapturedIndex - snapshotIndex))); + List snapshotJournalEntries = journal.subList(0, (int) (snapshotCapturedIndex - snapshotIndex)); + + snapshottedJournal.addAll(snapshotJournalEntries); clear(0, (int) (snapshotCapturedIndex - snapshotIndex)); previousSnapshotIndex = snapshotIndex; diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java index 3ec8cc5c58..285be39c0b 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java @@ -677,12 +677,22 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor { context.getReplicatedLog().snapshotPreCommit(captureSnapshot.getLastAppliedIndex(), captureSnapshot.getLastAppliedTerm()); - } else { + getCurrentBehavior().setReplicatedToAllIndex(captureSnapshot.getReplicatedToAllIndex()); + } else if(captureSnapshot.getReplicatedToAllIndex() != -1){ // clear the log based on replicatedToAllIndex context.getReplicatedLog().snapshotPreCommit(captureSnapshot.getReplicatedToAllIndex(), captureSnapshot.getReplicatedToAllTerm()); + + getCurrentBehavior().setReplicatedToAllIndex(captureSnapshot.getReplicatedToAllIndex()); + } else { + // The replicatedToAllIndex was not found in the log + // This means that replicatedToAllIndex never moved beyond -1 or that it is already in the snapshot. + // In this scenario we may need to save the snapshot to the akka persistence + // snapshot for recovery but we do not need to do the replicated log trimming. + context.getReplicatedLog().snapshotPreCommit(replicatedLog.getSnapshotIndex(), + replicatedLog.getSnapshotTerm()); } - getCurrentBehavior().setReplicatedToAllIndex(captureSnapshot.getReplicatedToAllIndex()); + LOG.info("{}: Removed in-memory snapshotted entries, adjusted snaphsotIndex:{} " + "and term:{}", persistenceId(), captureSnapshot.getLastAppliedIndex(), diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java index 1552096ef1..be51ba069c 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java @@ -126,6 +126,9 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior { // (heartbeat) to each server; repeat during idle periods to // prevent election timeouts (§5.2) sendAppendEntries(0, false); + + // It is important to schedule this heartbeat here + scheduleHeartBeat(context.getConfigParams().getHeartBeatInterval()); } /** @@ -304,28 +307,26 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior { } } - try { - if (message instanceof SendHeartBeat) { - beforeSendHeartbeat(); - sendHeartBeat(); - return this; + if (message instanceof SendHeartBeat) { + beforeSendHeartbeat(); + sendHeartBeat(); + scheduleHeartBeat(context.getConfigParams().getHeartBeatInterval()); + return this; - } else if(message instanceof SendInstallSnapshot) { - // received from RaftActor - setSnapshot(Optional.of(((SendInstallSnapshot) message).getSnapshot())); - sendInstallSnapshot(); + } else if(message instanceof SendInstallSnapshot) { + // received from RaftActor + setSnapshot(Optional.of(((SendInstallSnapshot) message).getSnapshot())); + sendInstallSnapshot(); - } else if (message instanceof Replicate) { - replicate((Replicate) message); + } else if (message instanceof Replicate) { + replicate((Replicate) message); - } else if (message instanceof InstallSnapshotReply){ - handleInstallSnapshotReply((InstallSnapshotReply) message); + } else if (message instanceof InstallSnapshotReply){ + handleInstallSnapshotReply((InstallSnapshotReply) message); - } - } finally { - scheduleHeartBeat(context.getConfigParams().getHeartBeatInterval()); } + return super.handleMessage(sender, message); } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java index 24581d6d2a..297d781251 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java @@ -134,6 +134,16 @@ public class MockRaftActorContext implements RaftActorContext { } @Override + // FIXME : A lot of tests try to manipulate the replicated log by setting it using this method + // This is OK to do if the underlyingActor is not RafActor or a derived class. If not then you should not + // used this way to manipulate the log because the RaftActor actually has a field replicatedLog + // which it creates internally and sets on the RaftActorContext + // The only right way to manipulate the replicated log therefore is to get it from either the RaftActor + // or the RaftActorContext and modify the entries in there instead of trying to replace it by using this setter + // Simple assertion that will fail if you do so + // ReplicatedLog log = new ReplicatedLogImpl(); + // raftActor.underlyingActor().getRaftActorContext().setReplicatedLog(log); + // assertEquals(log, raftActor.underlyingActor().getReplicatedLog()) public void setReplicatedLog(ReplicatedLog replicatedLog) { this.replicatedLog = replicatedLog; } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java index ba8f49d8f6..56bfc21f23 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java @@ -552,7 +552,6 @@ public class RaftActorTest extends AbstractActorTest { assertNotEquals("voted for", "foobar", mockRaftActor.getRaftActorContext().getTermInformation().getVotedFor()); mockRaftActor.onReceiveRecover(mock(RecoveryCompleted.class)); - }}; } @@ -576,12 +575,12 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + mockRaftActor.getRaftActorContext().getTermInformation().updateAndPersist(10, "foobar"); assertEquals("Persist called", true, persistLatch.await(5, TimeUnit.SECONDS)); - } - }; } @@ -602,14 +601,14 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + MockRaftActorContext.MockReplicatedLogEntry logEntry = new MockRaftActorContext.MockReplicatedLogEntry(10, 10, mock(Payload.class)); mockRaftActor.getRaftActorContext().getReplicatedLog().appendAndPersist(logEntry); verify(dataPersistenceProvider).persist(eq(logEntry), any(Procedure.class)); - } - }; } @@ -630,14 +629,14 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + mockRaftActor.getReplicatedLog().appendAndPersist(new MockRaftActorContext.MockReplicatedLogEntry(1, 0, mock(Payload.class))); mockRaftActor.getRaftActorContext().getReplicatedLog().removeFromAndPersist(0); verify(dataPersistenceProvider, times(2)).persist(anyObject(), any(Procedure.class)); - } - }; } @@ -658,6 +657,8 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + mockRaftActor.onReceiveCommand(new ApplyLogEntries(10)); verify(dataPersistenceProvider, times(1)).persist(anyObject(), any(Procedure.class)); @@ -685,6 +686,8 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + ByteString snapshotBytes = fromObject(Arrays.asList( new MockRaftActorContext.MockPayload("A"), new MockRaftActorContext.MockPayload("B"), @@ -722,6 +725,8 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + mockRaftActor.getReplicatedLog().append(new MockRaftActorContext.MockReplicatedLogEntry(1, 0, mock(Payload.class))); mockRaftActor.getReplicatedLog().append(new MockRaftActorContext.MockReplicatedLogEntry(1, 1, mock(Payload.class))); mockRaftActor.getReplicatedLog().append(new MockRaftActorContext.MockReplicatedLogEntry(1, 2, mock(Payload.class))); @@ -783,6 +788,8 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + ReplicatedLogEntry entry = new MockRaftActorContext.MockReplicatedLogEntry(1, 5, new MockRaftActorContext.MockPayload("F")); @@ -811,6 +818,8 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + ReplicatedLog oldReplicatedLog = mockRaftActor.getReplicatedLog(); oldReplicatedLog.append(new MockRaftActorContext.MockReplicatedLogEntry(1, 0, mock(Payload.class))); @@ -864,6 +873,8 @@ public class RaftActorTest extends AbstractActorTest { MockRaftActor mockRaftActor = mockActorRef.underlyingActor(); + mockRaftActor.waitForInitializeBehaviorComplete(); + ByteString snapshotBytes = fromObject(Arrays.asList( new MockRaftActorContext.MockPayload("A"), new MockRaftActorContext.MockPayload("B"), @@ -892,17 +903,28 @@ public class RaftActorTest extends AbstractActorTest { public void testRaftRoleChangeNotifier() throws Exception { new JavaTestKit(getSystem()) {{ ActorRef notifierActor = factory.createActor(Props.create(MessageCollectorActor.class)); + MessageCollectorActor.waitUntilReady(notifierActor); + DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); + long heartBeatInterval = 100; + config.setHeartBeatInterval(FiniteDuration.create(heartBeatInterval, TimeUnit.MILLISECONDS)); + config.setElectionTimeoutFactor(1); + String persistenceId = factory.generateActorId("notifier-"); factory.createTestActor(MockRaftActor.props(persistenceId, Collections.emptyMap(), Optional.of(config), notifierActor), persistenceId); - // sleeping for a minimum of 2 seconds, if it spans more its fine. - Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS); + List matches = null; + for(int i = 0; i < 5000 / heartBeatInterval; i++) { + matches = MessageCollectorActor.getAllMatching(notifierActor, RoleChanged.class); + assertNotNull(matches); + if(matches.size() == 3) { + break; + } + Uninterruptibles.sleepUninterruptibly(heartBeatInterval, TimeUnit.MILLISECONDS); + } - List matches = MessageCollectorActor.getAllMatching(notifierActor, RoleChanged.class); - assertNotNull(matches); assertEquals(3, matches.size()); // check if the notifier got a role change from null to Follower @@ -944,11 +966,12 @@ public class RaftActorTest extends AbstractActorTest { Map peerAddresses = new HashMap<>(); peerAddresses.put(follower1Id, followerActor1.path().toString()); - TestActorRef mockActorRef = TestActorRef.create(getSystem(), + TestActorRef mockActorRef = factory.createTestActor( MockRaftActor.props(persistenceId, peerAddresses, Optional.of(config), dataPersistenceProvider), persistenceId); MockRaftActor leaderActor = mockActorRef.underlyingActor(); + leaderActor.getRaftActorContext().setCommitIndex(4); leaderActor.getRaftActorContext().setLastApplied(4); leaderActor.getRaftActorContext().getTermInformation().update(1, persistenceId); @@ -1034,7 +1057,7 @@ public class RaftActorTest extends AbstractActorTest { Map peerAddresses = new HashMap<>(); peerAddresses.put(leaderId, leaderActor1.path().toString()); - TestActorRef mockActorRef = TestActorRef.create(getSystem(), + TestActorRef mockActorRef = factory.createTestActor( MockRaftActor.props(persistenceId, peerAddresses, Optional.of(config), dataPersistenceProvider), persistenceId); @@ -1204,6 +1227,128 @@ public class RaftActorTest extends AbstractActorTest { }; } + + private static class NonPersistentProvider implements DataPersistenceProvider { + @Override + public boolean isRecoveryApplicable() { + return false; + } + + @Override + public void persist(T o, Procedure procedure) { + try { + procedure.apply(o); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void saveSnapshot(Object o) { + + } + + @Override + public void deleteSnapshots(SnapshotSelectionCriteria criteria) { + + } + + @Override + public void deleteMessages(long sequenceNumber) { + + } + } + + @Test + public void testRealSnapshotWhenReplicatedToAllIndexMinusOne() throws Exception { + new JavaTestKit(getSystem()) {{ + String persistenceId = factory.generateActorId("leader-"); + DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); + config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); + config.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS)); + config.setSnapshotBatchCount(5); + + DataPersistenceProvider dataPersistenceProvider = new NonPersistentProvider(); + + Map peerAddresses = new HashMap<>(); + + TestActorRef mockActorRef = factory.createTestActor( + MockRaftActor.props(persistenceId, peerAddresses, + Optional.of(config), dataPersistenceProvider), persistenceId); + + MockRaftActor leaderActor = mockActorRef.underlyingActor(); + leaderActor.getRaftActorContext().setCommitIndex(3); + leaderActor.getRaftActorContext().setLastApplied(3); + leaderActor.getRaftActorContext().getTermInformation().update(1, persistenceId); + + leaderActor.waitForInitializeBehaviorComplete(); + for(int i=0;i< 4;i++) { + leaderActor.getReplicatedLog() + .append(new MockRaftActorContext.MockReplicatedLogEntry(1, i, + new MockRaftActorContext.MockPayload("A"))); + } + + Leader leader = new Leader(leaderActor.getRaftActorContext()); + leaderActor.setCurrentBehavior(leader); + assertEquals(RaftState.Leader, leaderActor.getCurrentBehavior().state()); + + // Persist another entry (this will cause a CaptureSnapshot to be triggered + leaderActor.persistData(mockActorRef, "x", new MockRaftActorContext.MockPayload("duh")); + + // Now send a CaptureSnapshotReply + mockActorRef.tell(new CaptureSnapshotReply(fromObject("foo").toByteArray()), mockActorRef); + + // Trimming log in this scenario is a no-op + assertEquals(-1, leaderActor.getReplicatedLog().getSnapshotIndex()); + assertFalse(leaderActor.getRaftActorContext().isSnapshotCaptureInitiated()); + assertEquals(-1, leader.getReplicatedToAllIndex()); + + }}; + } + + @Test + public void testRealSnapshotWhenReplicatedToAllIndexNotInReplicatedLog() throws Exception { + new JavaTestKit(getSystem()) {{ + String persistenceId = factory.generateActorId("leader-"); + DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); + config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); + config.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS)); + config.setSnapshotBatchCount(5); + + DataPersistenceProvider dataPersistenceProvider = new NonPersistentProvider(); + + Map peerAddresses = new HashMap<>(); + + TestActorRef mockActorRef = factory.createTestActor( + MockRaftActor.props(persistenceId, peerAddresses, + Optional.of(config), dataPersistenceProvider), persistenceId); + + MockRaftActor leaderActor = mockActorRef.underlyingActor(); + leaderActor.getRaftActorContext().setCommitIndex(3); + leaderActor.getRaftActorContext().setLastApplied(3); + leaderActor.getRaftActorContext().getTermInformation().update(1, persistenceId); + leaderActor.getReplicatedLog().setSnapshotIndex(3); + + leaderActor.waitForInitializeBehaviorComplete(); + Leader leader = new Leader(leaderActor.getRaftActorContext()); + leaderActor.setCurrentBehavior(leader); + leader.setReplicatedToAllIndex(3); + assertEquals(RaftState.Leader, leaderActor.getCurrentBehavior().state()); + + // Persist another entry (this will cause a CaptureSnapshot to be triggered + leaderActor.persistData(mockActorRef, "x", new MockRaftActorContext.MockPayload("duh")); + + // Now send a CaptureSnapshotReply + mockActorRef.tell(new CaptureSnapshotReply(fromObject("foo").toByteArray()), mockActorRef); + + // Trimming log in this scenario is a no-op + assertEquals(3, leaderActor.getReplicatedLog().getSnapshotIndex()); + assertFalse(leaderActor.getRaftActorContext().isSnapshotCaptureInitiated()); + assertEquals(3, leader.getReplicatedToAllIndex()); + + }}; + } + private ByteString fromObject(Object snapshot) throws Exception { ByteArrayOutputStream b = null; ObjectOutputStream o = null; diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderTest.java new file mode 100644 index 0000000000..dd3ed2347c --- /dev/null +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015 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.cluster.raft.behaviors; + +import static org.junit.Assert.assertTrue; +import akka.actor.ActorRef; +import akka.testkit.JavaTestKit; +import akka.testkit.TestActorRef; +import com.google.common.util.concurrent.Uninterruptibles; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.junit.Test; +import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl; +import org.opendaylight.controller.cluster.raft.MockRaftActorContext; +import org.opendaylight.controller.cluster.raft.base.messages.SendHeartBeat; +import org.opendaylight.controller.cluster.raft.utils.ForwardMessageToBehaviorActor; +import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; +import scala.concurrent.duration.FiniteDuration; + +public abstract class AbstractLeaderTest extends AbstractRaftActorBehaviorTest{ + + /** + * When we removed scheduling of heartbeat in the AbstractLeader constructor we ended up with a situation where + * if no follower responded to an initial AppendEntries heartbeats would not be sent to it. This test verifies + * that regardless of whether followers respond or not we schedule heartbeats. + * + * @throws Exception + */ + @Test + public void testLeaderSchedulesHeartbeatsEvenWhenNoFollowersRespondToInitialAppendEntries() throws Exception { + logStart("testLeaderSchedulesHeartbeatsEvenWhenNoFollowersRespondToInitialAppendEntries"); + new JavaTestKit(getSystem()) {{ + String leaderActorId = actorFactory.generateActorId("leader"); + String follower1ActorId = actorFactory.generateActorId("follower"); + String follower2ActorId = actorFactory.generateActorId("follower"); + + TestActorRef leaderActor = + actorFactory.createTestActor(ForwardMessageToBehaviorActor.props(), leaderActorId); + ActorRef follower1Actor = actorFactory.createActor(MessageCollectorActor.props(), follower1ActorId); + ActorRef follower2Actor = actorFactory.createActor(MessageCollectorActor.props(), follower2ActorId); + + MockRaftActorContext leaderActorContext = + new MockRaftActorContext(leaderActorId, getSystem(), leaderActor); + + DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); + configParams.setHeartBeatInterval(new FiniteDuration(200, TimeUnit.MILLISECONDS)); + configParams.setIsolatedLeaderCheckInterval(new FiniteDuration(10, TimeUnit.SECONDS)); + + leaderActorContext.setConfigParams(configParams); + + leaderActorContext.setReplicatedLog( + new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(1,5,1).build()); + + Map peerAddresses = new HashMap<>(); + peerAddresses.put(follower1ActorId, + follower1Actor.path().toString()); + peerAddresses.put(follower2ActorId, + follower2Actor.path().toString()); + + + leaderActorContext.setPeerAddresses(peerAddresses); + + RaftActorBehavior leader = createBehavior(leaderActorContext); + + leaderActor.underlyingActor().setBehavior(leader); + + Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); + + List allMessages = MessageCollectorActor.getAllMatching(leaderActor, SendHeartBeat.class); + + // Need more than 1 heartbeat to be delivered because we waited for 1 second with heartbeat interval 200ms + assertTrue(String.format("%s messages is less than expected", allMessages.size()), + allMessages.size() > 1); + + }}; + } + +} diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java index b37ace9560..e16d765cde 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java @@ -22,7 +22,7 @@ import org.opendaylight.controller.cluster.raft.RaftState; import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply; import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; -public class IsolatedLeaderTest extends AbstractRaftActorBehaviorTest { +public class IsolatedLeaderTest extends AbstractLeaderTest { private final TestActorRef leaderActor = actorFactory.createTestActor( Props.create(MessageCollectorActor.class), actorFactory.generateActorId("leader")); @@ -44,7 +44,7 @@ public class IsolatedLeaderTest extends AbstractRaftActorBehaviorTest { @Override protected RaftActorBehavior createBehavior(RaftActorContext actorContext) { - return new Leader(actorContext); + return new IsolatedLeader(actorContext); } @Override diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java index 34e1ed9b3b..c57fce1cd5 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java @@ -41,11 +41,12 @@ import org.opendaylight.controller.cluster.raft.messages.InstallSnapshot; import org.opendaylight.controller.cluster.raft.messages.InstallSnapshotReply; import org.opendaylight.controller.cluster.raft.messages.RaftRPC; import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply; +import org.opendaylight.controller.cluster.raft.utils.ForwardMessageToBehaviorActor; import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; import org.opendaylight.controller.protobuff.messages.cluster.raft.InstallSnapshotMessages; import scala.concurrent.duration.FiniteDuration; -public class LeaderTest extends AbstractRaftActorBehaviorTest { +public class LeaderTest extends AbstractLeaderTest { static final String FOLLOWER_ID = "follower"; @@ -742,7 +743,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { private MockRaftActorContext createActorContextWithFollower() { MockRaftActorContext actorContext = createActorContext(); - actorContext.setPeerAddresses(ImmutableMap.builder().put(FOLLOWER_ID, + actorContext.setPeerAddresses(ImmutableMap.builder().put(FOLLOWER_ID, followerActor.path().toString()).build()); return actorContext; } @@ -756,22 +757,6 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { return context; } - public static class ForwardMessageToBehaviorActor extends MessageCollectorActor { - AbstractRaftActorBehavior behavior; - - @Override public void onReceive(Object message) throws Exception { - if(behavior != null) { - behavior.handleMessage(sender(), message); - } - - super.onReceive(message); - } - - public static Props props() { - return Props.create(ForwardMessageToBehaviorActor.class); - } - } - @Test public void testLeaderCreatedWithCommitIndexLessThanLastIndex() throws Exception { logStart("testLeaderCreatedWithCommitIndexLessThanLastIndex"); @@ -781,7 +766,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { MockRaftActorContext followerActorContext = createActorContext(FOLLOWER_ID, followerActor); Follower follower = new Follower(followerActorContext); - followerActor.underlyingActor().behavior = follower; + followerActor.underlyingActor().setBehavior(follower); Map peerAddresses = new HashMap<>(); peerAddresses.put(FOLLOWER_ID, followerActor.path().toString()); @@ -834,7 +819,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { MockRaftActorContext followerActorContext = createActorContext(FOLLOWER_ID, followerActor); Follower follower = new Follower(followerActorContext); - followerActor.underlyingActor().behavior = follower; + followerActor.underlyingActor().setBehavior(follower); Map peerAddresses = new HashMap<>(); peerAddresses.put(FOLLOWER_ID, followerActor.path().toString()); @@ -871,7 +856,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { assertEquals(2, appendEntriesReply.getLogLastIndex()); assertEquals(1, appendEntriesReply.getLogLastTerm()); - leaderActor.underlyingActor().behavior = leader; + leaderActor.underlyingActor().setBehavior(follower); leader.handleMessage(followerActor, appendEntriesReply); leaderActor.underlyingActor().clear(); @@ -1076,7 +1061,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { followerActorContext.setConfigParams(configParams); Follower follower = new Follower(followerActorContext); - followerActor.underlyingActor().behavior = follower; + followerActor.underlyingActor().setBehavior(follower); leaderActorContext.getReplicatedLog().removeFrom(0); leaderActorContext.setCommitIndex(-1); @@ -1134,6 +1119,66 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest { follower.close(); } + @Test + public void testLaggingFollowerStarvation() throws Exception { + logStart("testLaggingFollowerStarvation"); + new JavaTestKit(getSystem()) {{ + String leaderActorId = actorFactory.generateActorId("leader"); + String follower1ActorId = actorFactory.generateActorId("follower"); + String follower2ActorId = actorFactory.generateActorId("follower"); + + TestActorRef leaderActor = + actorFactory.createTestActor(ForwardMessageToBehaviorActor.props(), leaderActorId); + ActorRef follower1Actor = actorFactory.createActor(MessageCollectorActor.props(), follower1ActorId); + ActorRef follower2Actor = actorFactory.createActor(MessageCollectorActor.props(), follower2ActorId); + + MockRaftActorContext leaderActorContext = + new MockRaftActorContext(leaderActorId, getSystem(), leaderActor); + + DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); + configParams.setHeartBeatInterval(new FiniteDuration(200, TimeUnit.MILLISECONDS)); + configParams.setIsolatedLeaderCheckInterval(new FiniteDuration(10, TimeUnit.SECONDS)); + + leaderActorContext.setConfigParams(configParams); + + leaderActorContext.setReplicatedLog( + new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(1,5,1).build()); + + Map peerAddresses = new HashMap<>(); + peerAddresses.put(follower1ActorId, + follower1Actor.path().toString()); + peerAddresses.put(follower2ActorId, + follower2Actor.path().toString()); + + leaderActorContext.setPeerAddresses(peerAddresses); + leaderActorContext.getTermInformation().update(1, leaderActorId); + + RaftActorBehavior leader = createBehavior(leaderActorContext); + + leaderActor.underlyingActor().setBehavior(leader); + + for(int i=1;i<6;i++) { + // Each AppendEntriesReply could end up rescheduling the heartbeat (without the fix for bug 2733) + RaftActorBehavior newBehavior = leader.handleMessage(follower1Actor, new AppendEntriesReply(follower1ActorId, 1, true, i, 1)); + assertTrue(newBehavior == leader); + Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); + } + + // Check if the leader has been receiving SendHeartbeat messages despite getting AppendEntriesReply + List heartbeats = MessageCollectorActor.getAllMatching(leaderActor, SendHeartBeat.class); + + assertTrue(String.format("%s heartbeat(s) is less than expected", heartbeats.size()), + heartbeats.size() > 1); + + // Check if follower-2 got AppendEntries during this time and was not starved + List appendEntries = MessageCollectorActor.getAllMatching(follower2Actor, AppendEntries.class); + + assertTrue(String.format("%s append entries is less than expected", appendEntries.size()), + appendEntries.size() > 1); + + }}; + } + @Override protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(RaftActorContext actorContext, ActorRef actorRef, RaftRPC rpc) throws Exception { diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java new file mode 100644 index 0000000000..9bcfcd9091 --- /dev/null +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 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.cluster.raft.utils; + +import akka.actor.Props; +import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior; + +public class ForwardMessageToBehaviorActor extends MessageCollectorActor { + private RaftActorBehavior behavior; + + @Override + public void onReceive(Object message) throws Exception { + if(behavior != null) { + behavior.handleMessage(sender(), message); + } + + super.onReceive(message); + } + + public static Props props() { + return Props.create(ForwardMessageToBehaviorActor.class); + } + + public void setBehavior(RaftActorBehavior behavior){ + this.behavior = behavior; + } +} + diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java index 662c12180d..62f163fb7d 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.raft.utils; import akka.actor.ActorRef; +import akka.actor.Props; import akka.actor.UntypedActor; import akka.pattern.Patterns; import akka.util.Timeout; @@ -123,4 +124,8 @@ public class MessageCollectorActor extends UntypedActor { throw new TimeoutException("Actor not ready in time."); } + + public static Props props() { + return Props.create(MessageCollectorActor.class); + } } diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java new file mode 100644 index 0000000000..2eee0e8099 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataObjectModification.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 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.md.sal.binding.api; + +import java.util.Collection; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yangtools.concepts.Identifiable; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; + +/** + * Modified Data Object. + * + * Represents modification of Data Object. + * + */ +public interface DataObjectModification extends Identifiable { + + enum ModificationType { + /** + * + * Child node (direct or indirect) was modified. + * + */ + SUBTREE_MODIFIED, + /** + * + * Node was explicitly created / overwritten. + * + */ + WRITE, + /** + * + * Node was deleted. + * + */ + DELETE + } + + @Override + PathArgument getIdentifier(); + + /** + * Returns type of modified object. + * + * @return type of modified object. + */ + @Nonnull Class getDataType(); + + /** + * + * Returns type of modification + * + * @return type Type of performed modification. + */ + @Nonnull ModificationType getModificationType(); + + /** + * Returns after state of top level container. + * + * @param root Class representing data container + * @return State of object after modification. Null if subtree is not present. + */ + @Nullable T getDataAfter(); + + /** + * Returns unmodifiable collection of modified direct children. + * + * @return unmodifiable collection of modified direct children. + */ + @Nonnull Collection> getModifiedChildren(); + + +} diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeChangeListener.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeChangeListener.java new file mode 100644 index 0000000000..6b1df719ac --- /dev/null +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeChangeListener.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015 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.md.sal.binding.api; + +import java.util.Collection; +import java.util.EventListener; +import javax.annotation.Nonnull; + +/** + * Interface implemented by classes interested in receiving notifications about + * data tree changes. This interface differs from {@link DataChangeListener} + * in that it provides a cursor-based view of the change, which has potentially + * lower overhead and allow more flexible consumption of change event. + */ +public interface DataTreeChangeListener extends EventListener { + /** + * Invoked when there was data change for the supplied path, which was used + * to register this listener. + * + *

+ * This method may be also invoked during registration of the listener if + * there is any pre-existing data in the conceptual data tree for supplied + * path. This initial event will contain all pre-existing data as created. + * + *

+ * A data change event may be triggered spuriously, e.g. such that data before + * and after compare as equal. Implementations of this interface are expected + * to recover from such events. Event producers are expected to exert reasonable + * effort to suppress such events. + * + * In other words, it is completely acceptable to observe + * a {@link DataObjectModification}, while the state observed before and + * after- data items compare as equal. + * + * @param changes Collection of change events, may not be null or empty. + */ + void onDataTreeChanged(@Nonnull Collection changes); +} diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeChangeService.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeChangeService.java new file mode 100644 index 0000000000..ae4e36f14a --- /dev/null +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeChangeService.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 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.md.sal.binding.api; + +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.concepts.ListenerRegistration; + +/** + * A {@link DOMService} which allows users to register for changes to a + * subtree. + */ +public interface DataTreeChangeService extends BindingService { + /** + * Registers a {@link DataTreeChangeListener} to receive + * notifications when data changes under a given path in the conceptual data + * tree. + *

+ * You are able to register for notifications for any node or subtree + * which can be represented using {@link DataTreeIdentifier}. + *

+ * + * You are able to register for data change notifications for a subtree or leaf + * even if it does not exist. You will receive notification once that node is + * created. + *

+ * If there is any pre-existing data in the data tree for the path for which you are + * registering, you will receive an initial data change event, which will + * contain all pre-existing data, marked as created. + * + *

+ * This method returns a {@link ListenerRegistration} object. To + * "unregister" your listener for changes call the {@link ListenerRegistration#close()} + * method on the returned object. + *

+ * You MUST explicitly unregister your listener when you no longer want to receive + * notifications. This is especially true in OSGi environments, where failure to + * do so during bundle shutdown can lead to stale listeners being still registered. + * + * @param treeId + * Data tree identifier of the subtree which should be watched for + * changes. + * @param listener + * Listener instance which is being registered + * @return Listener registration object, which may be used to unregister + * your listener using {@link ListenerRegistration#close()} to stop + * delivery of change events. + */ + @Nonnull ListenerRegistration registerDataTreeChangeListener(@Nonnull DataTreeIdentifier treeId, @Nonnull L listener); +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeIdentifier.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeIdentifier.java new file mode 100644 index 0000000000..428957e988 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeIdentifier.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 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.md.sal.binding.api; + +import com.google.common.base.Preconditions; +import java.io.Serializable; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yangtools.concepts.Immutable; +import org.opendaylight.yangtools.concepts.Path; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * A unique identifier for a particular subtree. It is composed of the logical + * data store type and the instance identifier of the root node. + */ +public final class DataTreeIdentifier implements Immutable, Path, Serializable { + private static final long serialVersionUID = 1L; + private final InstanceIdentifier rootIdentifier; + private final LogicalDatastoreType datastoreType; + + public DataTreeIdentifier(final LogicalDatastoreType datastoreType, final InstanceIdentifier rootIdentifier) { + this.datastoreType = Preconditions.checkNotNull(datastoreType); + this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier); + } + + /** + * Return the logical data store type. + * + * @return Logical data store type. Guaranteed to be non-null. + */ + public @Nonnull LogicalDatastoreType getDatastoreType() { + return datastoreType; + } + + /** + * Return the {@link YangInstanceIdentifier} of the root node. + * + * @return Instance identifier corresponding to the root node. + */ + public @Nonnull InstanceIdentifier getRootIdentifier() { + return rootIdentifier; + } + + @Override + public boolean contains(final DataTreeIdentifier other) { + return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + datastoreType.hashCode(); + result = prime * result + rootIdentifier.hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof DataTreeIdentifier)) { + return false; + } + DataTreeIdentifier other = (DataTreeIdentifier) obj; + if (datastoreType != other.datastoreType) { + return false; + } + return rootIdentifier.equals(other.rootIdentifier); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeModification.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeModification.java new file mode 100644 index 0000000000..aac51a6a4c --- /dev/null +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/DataTreeModification.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 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.md.sal.binding.api; + +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * Represent root of modification. + * + * @author Tony Tkacik <ttkacik@cisco.com> + * + */ +public interface DataTreeModification { + + /** + * Get the modification root path. This is the path of the root node + * relative to the root of InstanceIdentifier namespace. + * + * @return absolute path of the root node + */ + @Nonnull DataTreeIdentifier getRootPath(); + + /** + * Get the modification root node. + * + * @return modification root node + */ + @Nonnull DataObjectModification getRootNode(); + +} diff --git a/opendaylight/md-sal/sal-dom-api/pom.xml b/opendaylight/md-sal/sal-dom-api/pom.xml index 0302a7d920..89fca50354 100644 --- a/opendaylight/md-sal/sal-dom-api/pom.xml +++ b/opendaylight/md-sal/sal-dom-api/pom.xml @@ -33,6 +33,20 @@ org.osgi org.osgi.core + + + junit + junit + + + org.opendaylight.controller + sal-test-model + + + org.opendaylight.yangtools + yang-data-impl + test + diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeInaccessibleException.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeInaccessibleException.java new file mode 100644 index 0000000000..eea1be51bb --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeInaccessibleException.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import com.google.common.base.Preconditions; + + +/** + * Failure reported when a data tree is no longer accessible. + */ +public class DOMDataTreeInaccessibleException extends DOMDataTreeListeningException { + private static final long serialVersionUID = 1L; + private final DOMDataTreeIdentifier treeIdentifier; + + public DOMDataTreeInaccessibleException(final DOMDataTreeIdentifier treeIdentifier, final String message) { + super(message); + this.treeIdentifier = Preconditions.checkNotNull(treeIdentifier); + } + + public DOMDataTreeInaccessibleException(final DOMDataTreeIdentifier treeIdentifier, final String message, final Throwable cause) { + super(message); + this.treeIdentifier = Preconditions.checkNotNull(treeIdentifier); + } + + public final DOMDataTreeIdentifier getTreeIdentifier() { + return treeIdentifier; + } +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeListener.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeListener.java new file mode 100644 index 0000000000..083cd10ef3 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import java.util.Collection; +import java.util.EventListener; +import java.util.Map; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; + +/** + * Interface implemented by data consumers, e.g. processes wanting to act on data + * after it has been introduced to the conceptual data tree. + */ +public interface DOMDataTreeListener extends EventListener { + /** + * Invoked whenever one or more registered subtrees change. The logical changes are reported, + * as well as the roll up of new state for all subscribed subtrees. + * + * @param changes The set of changes being reported. Each subscribed subtree may be present + * at most once. + * @param subtrees Per-subtree state as visible after the reported changes have been applied. + * This includes all the subtrees this listener is subscribed to, even those + * which have not changed. + */ + void onDataTreeChanged(@Nonnull Collection changes, @Nonnull Map> subtrees); + + /** + * Invoked when a subtree listening failure occurs. This can be triggered, for example, when + * a connection to external subtree source is broken. The listener will not receive any other + * callbacks, but its registration still needs to be closed to prevent resource leak. + * + * @param cause Collection of failure causes, may not be null or empty. + */ + void onDataTreeFailed(@Nonnull Collection causes); +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeListeningException.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeListeningException.java new file mode 100644 index 0000000000..e0d9b427d9 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeListeningException.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +/** + * Base exception for various causes why and {@link DOMDataTreeListener} + * may be terminated by the {@link DOMDataTreeService} implementation. + */ +public class DOMDataTreeListeningException extends Exception { + private static final long serialVersionUID = 1L; + + public DOMDataTreeListeningException(final String message) { + super(message); + } + + public DOMDataTreeListeningException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeLoopException.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeLoopException.java new file mode 100644 index 0000000000..8f498a887d --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeLoopException.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import javax.annotation.Nonnull; + +/** + * Exception thrown when a loop is detected in the way {@link DOMDataTreeListener} + * and {@link DOMDataTreeProducer} instances would be connected. + */ +public class DOMDataTreeLoopException extends Exception { + private static final long serialVersionUID = 1L; + + public DOMDataTreeLoopException(final @Nonnull String message) { + super(message); + } + + public DOMDataTreeLoopException(final @Nonnull String message, final @Nonnull Throwable cause) { + super(message, cause); + } +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducer.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducer.java new file mode 100644 index 0000000000..cbfa0122f2 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducer.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import java.util.Collection; +import javax.annotation.Nonnull; + +/** + * A data producer context. It allows transactions to be submitted to the subtrees + * specified at instantiation time. At any given time there may be a single transaction + * open. It needs to be either submitted or cancelled before another one can be open. + * Once a transaction is submitted, it will proceed to be committed asynchronously. + * + * Each instance has an upper bound on the number of transactions which can be in-flight, + * once that capacity is exceeded, an attempt to create a new transaction will block + * until some transactions complete. + * + * Each {@link DOMDataTreeProducer} can be in two logical states, bound and unbound, + * which define the lifecycle rules for when is it legal to create and submit transactions + * in relationship with {@link DOMDataTreeListener} callbacks. + * + * When a producer is first created, it is unbound. In this state the producer can be + * accessed by any application thread to allocate or submit transactions, as long as + * the 'single open transaction' rule is maintained. The producer and any transaction + * object MUST NOT be accessed, directly or indirectly, from a {@link DOMDataTreeListener} + * callback. + * + * When a producer is referenced in a call to {@link DOMDataTreeService#registerListener(DOMDataTreeListener, java.util.Collection, boolean, java.util.Collection)}, + * an attempt will be made to bind the producer to the specified {@link DOMDataTreeListener}. + * Such an attempt will fail the producer is already bound, or it has an open transaction. + * Once bound, the producer can only be accessed from within the {@link DOMDataTreeListener} + * callback on that particular instance. Any transaction which is not submitted by the + * time the callback returns will be implicitly cancelled. A producer becomes unbound + * when the listener it is bound to becomes unregistered. + */ +public interface DOMDataTreeProducer extends DOMDataTreeProducerFactory, AutoCloseable { + /** + * Allocate a new open transaction on this producer. Any and all transactions + * previously allocated must have been either submitted or cancelled by the + * time this method is invoked. + * + * @param barrier Indicates whether this transaction should be a barrier. A barrier + * transaction is processed separately from any preceding transactions. + * Non-barrier transactions may be merged and processed in a batch, + * such that any observers see the modifications contained in them as + * if the modifications were made in a single transaction. + * @return A new {@link DOMDataWriteTransaction} + * @throws {@link IllegalStateException} if a previous transaction was not closed. + * @throws {@link IllegalThreadStateException} if the calling thread context does not + * match the lifecycle rules enforced by the producer state (e.g. bound or unbound). + * This exception is thrown on a best effort basis and programs should not rely + * on it for correct operation. + */ + @Nonnull DOMDataWriteTransaction createTransaction(boolean isolated); + + /** + * {@inheritDoc} + * + * When invoked on a {@link DOMDataTreeProducer}, this method has additional restrictions. + * There may not be an open transaction from this producer. The method needs to be + * invoked in appropriate context, e.g. bound or unbound. + * + * Specified subtrees must be accessible by this producer. Accessible means they are a subset + * of the subtrees specified when the producer is instantiated. The set is further reduced as + * child producers are instantiated -- if you create a producer for /a and then a child for + * /a/b, /a/b is not accessible from the first producer. + * + * Once this method returns successfully, this (parent) producer loses the ability to + * access the specified paths until the resulting (child) producer is shut down. + * + * @throws {@link IllegalStateException} if there is an open transaction + * @throws {@link IllegalArgumentException} if subtrees contains a subtree which is not + * accessible by this producer + * @throws {@link IllegalThreadStateException} if the calling thread context does not + * match the lifecycle rules enforced by the producer state (e.g. bound or unbound). + * This exception is thrown on a best effort basis and programs should not rely + * on it for correct operation. + */ + @Override + @Nonnull DOMDataTreeProducer createProducer(@Nonnull Collection subtrees); + + /** + * {@inheritDoc} + * + * @throws DOMDataTreeProducerBusyException when there is an open transaction. + */ + @Override + void close() throws DOMDataTreeProducerException; +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerBusyException.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerBusyException.java new file mode 100644 index 0000000000..a83a5ca3d2 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerBusyException.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +/** + * Exception indicating that the {@link DOMDataTreeProducer} has an open user + * transaction and cannot be closed. + */ +public class DOMDataTreeProducerBusyException extends DOMDataTreeProducerException { + private static final long serialVersionUID = 1L; + + public DOMDataTreeProducerBusyException(final String message) { + super(message); + } + + public DOMDataTreeProducerBusyException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerException.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerException.java new file mode 100644 index 0000000000..16c26760ff --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerException.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +/** + * Base exception for all exceptions related to {@link DOMDataTreeProducer}s. + */ +public class DOMDataTreeProducerException extends Exception { + private static final long serialVersionUID = 1L; + + public DOMDataTreeProducerException(final String message) { + super(message); + } + + public DOMDataTreeProducerException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerFactory.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerFactory.java new file mode 100644 index 0000000000..89ac8d1e6c --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeProducerFactory.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import java.util.Collection; +import javax.annotation.Nonnull; + +/** + * Base source of {@link DOMDataTreeProducer}s. This interface is usually not used directly, + * but rather through one of its sub-interfaces. + */ +public interface DOMDataTreeProducerFactory { + /** + * Create a producer, which is able to access to a set of trees. + * + * @param subtrees The collection of subtrees the resulting producer should have access to. + * @return A {@link DOMDataTreeProducer} instance. + * @throws {@link IllegalArgumentException} if subtrees is empty. + */ + @Nonnull DOMDataTreeProducer createProducer(@Nonnull Collection subtrees); +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeService.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeService.java new file mode 100644 index 0000000000..21ff44c539 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeService.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import java.util.Collection; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.concepts.ListenerRegistration; + +/** + * A {@link DOMService} providing access to the conceptual data tree. Interactions + * with the data tree are split into data producers and consumers (listeners). Each + * of them operate on a set of subtrees, which need to be declared at instantiation time. + * + * Returned instances are not thread-safe and expected to be used by a single thread + * at a time. Furthermore, producers may not be accessed from consumer callbacks + * unless they were specified when the listener is registered. + * + * The service maintains a loop-free topology of producers and consumers. What this means + * is that a consumer is not allowed to access a producer, which affects any of the + * subtrees it is subscribed to. This restriction is in place to ensure the system does + * not go into a feedback loop, where it is impossible to block either a producer or + * a consumer without accumulating excess work in the backlog stemming from its previous + * activity. + */ +public interface DOMDataTreeService extends DOMDataTreeProducerFactory, DOMService { + /** + * Register a {@link DOMDataTreeListener} instance. Once registered, the listener + * will start receiving changes on the selected subtrees. If the listener cannot + * keep up with the rate of changes, and allowRxMerges is set to true, this service + * is free to merge the changes, so that a smaller number of them will be reported, + * possibly hiding some data transitions (like flaps). + * + * If the listener wants to write into any producer, that producer has to be mentioned + * in the call to this method. Those producers will be bound exclusively to the + * registration, so that accessing them outside of this listener's callback will trigger + * an error. Any producers mentioned must be idle, e.g. they may not have an open + * transaction at the time this method is invoked. + * + * Each listener instance can be registered at most once. Implementations of this + * interface have to guarantee that the listener's methods will not be invoked + * concurrently from multiple threads. + * + * @param listener {@link DOMDataTreeListener} that is being registered + * @param subtrees Conceptual subtree identifier of subtrees which should be monitored + * for changes. May not be null or empty. + * @param allowRxMerges True if the backend may perform ingress state compression. + * @param producers {@link DOMDataTreeProducer} instances to bind to the listener. + * @return A listener registration. Once closed, the listener will no longer be + * invoked and the producers will be unbound. + * @throws IllegalArgumentException if subtrees is empty or the listener is already bound + * @throws DOMDataTreeLoopException if the registration of the listener to the specified + * subtrees with specified producers would form a + * feedback loop + */ + @Nonnull ListenerRegistration registerListener(@Nonnull T listener, + @Nonnull Collection subtrees, boolean allowRxMerges, @Nonnull Collection producers); +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShard.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShard.java new file mode 100644 index 0000000000..e9ef0034ea --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShard.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import java.util.EventListener; +import javax.annotation.Nonnull; + +/** + * A single shard of the conceptual data tree. This interface defines the basic notifications + * a shard can receive. Each shard implementation is expected to also implement some of the + * datastore-level APIs. Which interfaces are required depends on the {@link DOMDataTreeShardingService} + * implementation. + */ +public interface DOMDataTreeShard extends EventListener { + /** + * Invoked whenever a child is getting attached as a more specific prefix under this shard. + * + * @param prefix Child's prefix + * @param child Child shard + */ + void onChildAttached(@Nonnull DOMDataTreeIdentifier prefix, @Nonnull DOMDataTreeShard child); + + /** + * Invoked whenever a child is getting detached as a more specific prefix under this shard. + * + * @param prefix Child's prefix + * @param child Child shard + */ + void onChildDetached(@Nonnull DOMDataTreeIdentifier prefix, @Nonnull DOMDataTreeShard child); +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShardingConflictException.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShardingConflictException.java new file mode 100644 index 0000000000..d44316d39d --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShardingConflictException.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import javax.annotation.Nonnull; + +/** + * Exception thrown when an attempt to attach a conflicting shard to the global + * table. + */ +public class DOMDataTreeShardingConflictException extends Exception { + private static final long serialVersionUID = 1L; + + public DOMDataTreeShardingConflictException(final @Nonnull String message) { + super(message); + } + + public DOMDataTreeShardingConflictException(final @Nonnull String message, final @Nonnull Throwable cause) { + super(message, cause); + } +} diff --git a/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShardingService.java b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShardingService.java new file mode 100644 index 0000000000..c087224090 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/md/sal/dom/api/DOMDataTreeShardingService.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.concepts.ListenerRegistration; + +/** + * A {@link DOMService} providing access to details on how the conceptual data tree + * is distributed among providers (also known as shards). Each shard is tied to a + * single {@link DOMDataTreeIdentifier}. Based on those data tree identifiers, the + * shards are organized in a tree, where there is a logical parent/child relationship. + * + * It is not allowed to attach two shards to the same data tree identifier, which means + * the mapping of each piece of information has an unambiguous home. When accessing + * the information, the shard with the longest matching data tree identifier is used, + * which is why this interface treats it is a prefix. + * + * Whenever a parent/child relationship is changed, the parent is notified, so it can + * understand that a logical child has been attached. + */ +public interface DOMDataTreeShardingService extends DOMService { + /** + * Register a shard as responsible for a particular subtree prefix. + * + * @param prefix Data tree identifier, may not be null. + * @param shard Responsible shard instance + * @return A registration. To remove the shard's binding, close the registration. + * @throws DOMDataTreeShardingConflictException if the prefix is already bound + */ + @Nonnull ListenerRegistration registerDataTreeShard(@Nonnull DOMDataTreeIdentifier prefix, @Nonnull T shard) throws DOMDataTreeShardingConflictException; +} diff --git a/opendaylight/md-sal/sal-dom-api/src/test/java/org/opendaylight/controller/md/sal/dom/api/AbstractDOMDataTreeServiceTestSuite.java b/opendaylight/md-sal/sal-dom-api/src/test/java/org/opendaylight/controller/md/sal/dom/api/AbstractDOMDataTreeServiceTestSuite.java new file mode 100644 index 0000000000..896c606eb9 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-api/src/test/java/org/opendaylight/controller/md/sal/dom/api/AbstractDOMDataTreeServiceTestSuite.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 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.md.sal.dom.api; + +import static org.junit.Assert.assertNotNull; +import com.google.common.util.concurrent.CheckedFuture; +import java.net.URI; +import java.util.Collections; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; + +/** + * Abstract test suite demonstrating various access patterns on how a {@link DOMDataTreeService} + * can be used. + */ +public abstract class AbstractDOMDataTreeServiceTestSuite { + protected static final QNameModule TEST_MODULE = QNameModule.create(URI.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"), null); + + protected static final YangInstanceIdentifier UNORDERED_CONTAINER_IID = YangInstanceIdentifier.create( + new NodeIdentifier(QName.create(TEST_MODULE, "lists")), + new NodeIdentifier(QName.create(TEST_MODULE, "unordered-container"))); + protected static final DOMDataTreeIdentifier UNORDERED_CONTAINER_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID); + + /** + * Return a reference to the service used in this test. The instance + * needs to be reused within the same test and must be isolated between + * tests. + * + * @return {@link DOMDataTreeService} instance. + */ + protected abstract @Nonnull DOMDataTreeService service(); + + /** + * A simple unbound producer. It write some basic things into the data store based on the + * test model. + * @throws DOMDataTreeProducerException + * @throws TransactionCommitFailedException + */ + @Test + public final void testBasicProducer() throws DOMDataTreeProducerException, TransactionCommitFailedException { + // Create a producer. It is an AutoCloseable resource, hence the try-with pattern + try (final DOMDataTreeProducer prod = service().createProducer(Collections.singleton(UNORDERED_CONTAINER_TREE))) { + assertNotNull(prod); + + final DOMDataWriteTransaction tx = prod.createTransaction(true); + assertNotNull(tx); + + tx.put(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID, ImmutableContainerNodeBuilder.create().build()); + + final CheckedFuture f = tx.submit(); + assertNotNull(f); + + f.checkedGet(); + } + } + + // TODO: simple listener +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java index 2f02f981ab..2a7c8b6682 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java @@ -60,8 +60,8 @@ public class DOMBrokerPerformanceTest { @Before public void setupStore() { - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java index c1d301c549..cd8ac09980 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java @@ -57,9 +57,9 @@ public class DOMBrokerTest { public void setupStore() { InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor()); + MoreExecutors.newDirectExecutorService()); InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor()); + MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java index 03d39a2a62..aba78f7559 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java @@ -41,8 +41,8 @@ public class DOMTransactionChainTest { @Before public void setupStore() { - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); diff --git a/opendaylight/md-sal/sal-dom-xsql/pom.xml b/opendaylight/md-sal/sal-dom-xsql/pom.xml index c7fd20248d..f0e27cf2ac 100644 --- a/opendaylight/md-sal/sal-dom-xsql/pom.xml +++ b/opendaylight/md-sal/sal-dom-xsql/pom.xml @@ -48,6 +48,10 @@ org.osgi org.osgi.core + + junit + junit + diff --git a/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml index c7ee3a5c0c..85ae59b161 100644 --- a/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml @@ -81,7 +81,6 @@ org.slf4j slf4j-simple - ${slf4j.version} test @@ -94,7 +93,6 @@ org.slf4j slf4j-simple - 1.7.7 @@ -178,7 +176,6 @@ org.apache.maven.plugins maven-shade-plugin - 1.5 package diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java index 4720f4b4b9..9de4892d91 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java @@ -45,7 +45,7 @@ public class InMemoryDataStoreTest { @Before public void setupStore() { - domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor()); + domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); domStore.onGlobalContextUpdated(schemaContext); } diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java index 15e5f716f6..e7af4dffae 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java @@ -31,7 +31,7 @@ public class SchemaUpdateForTransactionTest { @Before public void setupStore() { - domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor()); + domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService()); loadSchemas(RockTheHouseInput.class); } diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestDCLExecutorService.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestDCLExecutorService.java index f6e6461bf5..a01933c295 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestDCLExecutorService.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestDCLExecutorService.java @@ -8,10 +8,9 @@ package org.opendaylight.controller.md.sal.dom.store.impl; -import java.util.concurrent.ExecutorService; - import com.google.common.util.concurrent.ForwardingExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import java.util.concurrent.ExecutorService; /** * A forwarding Executor used by unit tests for DataChangeListener notifications @@ -21,13 +20,13 @@ import com.google.common.util.concurrent.MoreExecutors; public class TestDCLExecutorService extends ForwardingExecutorService { // Start with a same thread executor to avoid timing issues during test setup. - private volatile ExecutorService currentExecutor = MoreExecutors.sameThreadExecutor(); + private volatile ExecutorService currentExecutor = MoreExecutors.newDirectExecutorService(); // The real executor to use when test setup is complete. private final ExecutorService postSetupExecutor; - public TestDCLExecutorService( ExecutorService postSetupExecutor ) { + public TestDCLExecutorService( final ExecutorService postSetupExecutor ) { this.postSetupExecutor = postSetupExecutor; } diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java index b966fae3d4..44b2435da2 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java @@ -111,7 +111,7 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co new NetconfDevice.SchemaResourcesDTO(schemaRegistry, schemaContextFactory, new NetconfStateSchemas.NetconfStateSchemasResolverImpl()); final NetconfDevice device = - new NetconfDevice(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, new NetconfMessageTransformer(), true); + new NetconfDevice(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, new NetconfMessageTransformer(), getReconnectOnChangedSchema()); final NetconfDeviceCommunicator listener = userCapabilities.isPresent() ? new NetconfDeviceCommunicator(id, device, userCapabilities.get()) : new NetconfDeviceCommunicator(id, device); diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java index 9a5b239024..281f82ba2a 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java @@ -223,6 +223,8 @@ public final class NetconfDevice implements RemoteDevice sourceRegistration : sourceRegistrations) { sourceRegistration.close(); @@ -314,6 +316,7 @@ public final class NetconfDevice implements RemoteDevice filterNotification(CompositeNode notification); diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java index 82c04a50e0..590f4c4ceb 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java @@ -8,10 +8,19 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; +import com.google.common.base.Optional; import java.lang.management.ManagementFactory; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import javax.management.MBeanServer; import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.confignetconfconnector.util.Util; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.yangtools.yang.model.api.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,4 +77,117 @@ public class NetconfOperationServiceFactoryImpl implements NetconfOperationServi public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { return new NetconfOperationServiceImpl(yangStoreService, jmxClient, netconfSessionIdForReporting); } + + + @Override + public Set getCapabilities() { + return setupCapabilities(yangStoreService); + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + return yangStoreService.registerCapabilityListener(listener); + } + + public static Set setupCapabilities(final YangStoreContext yangStoreSnapshot) { + Set capabilities = new HashSet<>(); + // [RFC6241] 8.3. Candidate Configuration Capability + capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); + + // TODO rollback on error not supported EditConfigXmlParser:100 + // [RFC6241] 8.5. Rollback-on-Error Capability + // capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:rollback-on-error:1.0")); + + Set modules = yangStoreSnapshot.getModules(); + for (Module module : modules) { + capabilities.add(new YangStoreCapability(module, yangStoreSnapshot.getModuleSource(module))); + } + + return capabilities; + } + + private static class BasicCapability implements Capability { + + private final String capability; + + private BasicCapability(final String capability) { + this.capability = capability; + } + + @Override + public String getCapabilityUri() { + return capability; + } + + @Override + public Optional getModuleNamespace() { + return Optional.absent(); + } + + @Override + public Optional getModuleName() { + return Optional.absent(); + } + + @Override + public Optional getRevision() { + return Optional.absent(); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.absent(); + } + + @Override + public Collection getLocation() { + return Collections.emptyList(); + } + + @Override + public String toString() { + return capability; + } + } + + static final class YangStoreCapability extends BasicCapability { + + private final String content; + private final String revision; + private final String moduleName; + private final String moduleNamespace; + + public YangStoreCapability(final Module module, final String moduleContent) { + super(toCapabilityURI(module)); + this.content = moduleContent; + this.moduleName = module.getName(); + this.moduleNamespace = module.getNamespace().toString(); + this.revision = Util.writeDate(module.getRevision()); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.of(content); + } + + private static String toCapabilityURI(final Module module) { + return String.valueOf(module.getNamespace()) + "?module=" + + module.getName() + "&revision=" + Util.writeDate(module.getRevision()); + } + + @Override + public Optional getModuleName() { + return Optional.of(moduleName); + } + + @Override + public Optional getModuleNamespace() { + return Optional.of(moduleNamespace); + } + + @Override + public Optional getRevision() { + return Optional.of(revision); + } + } } diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceImpl.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceImpl.java index ef0a72c0f0..28001851cc 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceImpl.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/NetconfOperationServiceImpl.java @@ -8,18 +8,11 @@ package org.opendaylight.controller.netconf.confignetconfconnector.osgi; -import com.google.common.base.Optional; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider; -import org.opendaylight.controller.netconf.confignetconfconnector.util.Util; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.yangtools.yang.model.api.Module; /** * Manages life cycle of {@link YangStoreContext}. @@ -28,132 +21,23 @@ public class NetconfOperationServiceImpl implements NetconfOperationService { private final NetconfOperationProvider operationProvider; private final TransactionProvider transactionProvider; - private final YangStoreService yangStoreService; public NetconfOperationServiceImpl(final YangStoreService yangStoreService, final ConfigRegistryJMXClient jmxClient, final String netconfSessionIdForReporting) { - this.yangStoreService = yangStoreService; - transactionProvider = new TransactionProvider(jmxClient, netconfSessionIdForReporting); operationProvider = new NetconfOperationProvider(yangStoreService, jmxClient, transactionProvider, netconfSessionIdForReporting); } - @Override - public void close() { - transactionProvider.close(); - } - - @Override - public Set getCapabilities() { - return setupCapabilities(yangStoreService); - } - @Override public Set getNetconfOperations() { return operationProvider.getOperations(); } - private static Set setupCapabilities(final YangStoreContext yangStoreSnapshot) { - Set capabilities = new HashSet<>(); - // [RFC6241] 8.3. Candidate Configuration Capability - capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); - - // TODO rollback on error not supported EditConfigXmlParser:100 - // [RFC6241] 8.5. Rollback-on-Error Capability - // capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:rollback-on-error:1.0")); - - Set modules = yangStoreSnapshot.getModules(); - for (Module module : modules) { - capabilities.add(new YangStoreCapability(module, yangStoreSnapshot.getModuleSource(module))); - } - - return capabilities; - } - - private static class BasicCapability implements Capability { - - private final String capability; - - private BasicCapability(final String capability) { - this.capability = capability; - } - - @Override - public String getCapabilityUri() { - return capability; - } - - @Override - public Optional getModuleNamespace() { - return Optional.absent(); - } - - @Override - public Optional getModuleName() { - return Optional.absent(); - } - - @Override - public Optional getRevision() { - return Optional.absent(); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.absent(); - } - - @Override - public Collection getLocation() { - return Collections.emptyList(); - } - - @Override - public String toString() { - return capability; - } + @Override + public void close() { + transactionProvider.close(); } - private static final class YangStoreCapability extends BasicCapability { - - private final String content; - private final String revision; - private final String moduleName; - private final String moduleNamespace; - - public YangStoreCapability(final Module module, final String moduleContent) { - super(toCapabilityURI(module)); - this.content = moduleContent; - this.moduleName = module.getName(); - this.moduleNamespace = module.getNamespace().toString(); - this.revision = Util.writeDate(module.getRevision()); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.of(content); - } - - private static String toCapabilityURI(final Module module) { - return String.valueOf(module.getNamespace()) + "?module=" - + module.getName() + "&revision=" + Util.writeDate(module.getRevision()); - } - - @Override - public Optional getModuleName() { - return Optional.of(moduleName); - } - - @Override - public Optional getModuleNamespace() { - return Optional.of(moduleNamespace); - } - - @Override - public Optional getRevision() { - return Optional.of(revision); - } - } } diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java index de151a8969..176800fb97 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/YangStoreService.java @@ -14,6 +14,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import java.lang.ref.SoftReference; import java.util.Collections; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -21,6 +22,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicReference; import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.notifications.BaseNetconfNotificationListener; import org.opendaylight.controller.netconf.notifications.BaseNotificationPublisherRegistration; import org.opendaylight.controller.netconf.notifications.NetconfNotificationCollector; @@ -77,6 +80,8 @@ public class YangStoreService implements YangStoreContext { } }); + private final Set listeners = Collections.synchronizedSet(new HashSet()); + public YangStoreService(final SchemaContextProvider schemaContextProvider, final BundleContext context) { this(schemaContextProvider, new NotificationCollectorTracker(context)); } @@ -130,7 +135,31 @@ public class YangStoreService implements YangStoreContext { notificationExecutor.submit(new CapabilityChangeNotifier(previous)); } + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + if(ref.get() == null || ref.get().get() == null) { + getYangStoreSnapshot(); + } + + this.listeners.add(listener); + listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(ref.get().get())); + + return new AutoCloseable() { + @Override + public void close() throws Exception { + YangStoreService.this.listeners.remove(listener); + } + }; + } + + private static final Function MODULE_TO_CAPABILITY = new Function() { + @Override + public Capability apply(final Module module) { + return new NetconfOperationServiceFactoryImpl.YangStoreCapability(module, module.getSource()); + } + }; + private final class CapabilityChangeNotifier implements Runnable { + private final YangStoreSnapshot previous; public CapabilityChangeNotifier(final YangStoreSnapshot previous) { @@ -142,7 +171,19 @@ public class YangStoreService implements YangStoreContext { final YangStoreContext current = getYangStoreSnapshot(); if(current.equals(previous) == false) { - notificationPublisher.onCapabilityChanged(computeDiff(previous, current)); + final Sets.SetView removed = Sets.difference(previous.getModules(), current.getModules()); + final Sets.SetView added = Sets.difference(current.getModules(), previous.getModules()); + + // Notify notification manager + notificationPublisher.onCapabilityChanged(computeDiff(removed, added)); + + // Notify direct capability listener TODO would it not be better if the capability listeners went through notification manager ? + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesAdded(Sets.newHashSet(Collections2.transform(added, MODULE_TO_CAPABILITY))); + } + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesRemoved(Sets.newHashSet(Collections2.transform(removed, MODULE_TO_CAPABILITY))); + } } } } @@ -150,15 +191,11 @@ public class YangStoreService implements YangStoreContext { private static final Function MODULE_TO_URI = new Function() { @Override public Uri apply(final Module input) { - final QName qName = QName.cachedReference(QName.create(input.getQNameModule(), input.getName())); - return new Uri(qName.toString()); + return new Uri(new NetconfOperationServiceFactoryImpl.YangStoreCapability(input, input.getSource()).getCapabilityUri()); } }; - static NetconfCapabilityChange computeDiff(final YangStoreContext previous, final YangStoreContext current) { - final Sets.SetView removed = Sets.difference(previous.getModules(), current.getModules()); - final Sets.SetView added = Sets.difference(current.getModules(), previous.getModules()); - + static NetconfCapabilityChange computeDiff(final Sets.SetView removed, final Sets.SetView added) { final NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder(); netconfCapabilityChangeBuilder.setChangedBy(new ChangedByBuilder().setServerOrUser(new ServerBuilder().setServer(true).build()).build()); netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(Collections2.transform(removed, MODULE_TO_URI))); diff --git a/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java b/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java index f1fc27725b..b1222997fb 100644 --- a/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java +++ b/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java @@ -95,8 +95,8 @@ import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStore import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreService; import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; @@ -141,7 +141,9 @@ public class NetconfMappingTest extends AbstractConfigTest { @Mock NetconfOperationRouter netconfOperationRouter; @Mock - NetconfOperationServiceSnapshotImpl netconfOperationServiceSnapshot; + AggregatedNetconfOperationServiceFactory netconfOperationServiceSnapshot; + @Mock + private AutoCloseable sessionCloseable; private TransactionProvider transactionProvider; @@ -157,13 +159,12 @@ public class NetconfMappingTest extends AbstractConfigTest { doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap(); doReturn(getModules()).when(this.yangStoreSnapshot).getModules(); - doNothing().when(netconfOperationServiceSnapshot).close(); this.factory = new NetconfTestImplModuleFactory(); this.factory2 = new DepTestImplModuleFactory(); this.factory3 = new IdentityTestModuleFactory(); factory4 = new TestImplModuleFactory(); - + doNothing().when(sessionCloseable).close(); super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, this.factory, this.factory2, this.factory3, factory4)); @@ -376,7 +377,7 @@ public class NetconfMappingTest extends AbstractConfigTest { edit("netconfMessages/editConfig_none.xml"); closeSession(); - verify(netconfOperationServiceSnapshot).close(); + verify(sessionCloseable).close(); verifyNoMoreInteractions(netconfOperationRouter); verifyNoMoreInteractions(netconfOperationServiceSnapshot); } @@ -390,7 +391,7 @@ public class NetconfMappingTest extends AbstractConfigTest { private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException { - DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID, netconfOperationServiceSnapshot); + DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID, sessionCloseable); executeOp(closeOp, "netconfMessages/closeSession.xml"); } diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusherImpl.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusherImpl.java index 0aebc68bbe..22b061a128 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusherImpl.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusherImpl.java @@ -33,10 +33,10 @@ import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.persist.api.ConfigPusher; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.config.persist.api.Persister; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; @@ -177,20 +177,20 @@ public class ConfigPusherImpl implements ConfigPusher { } catch(RuntimeException e) { throw new NotEnoughCapabilitiesException("Netconf service not stable for " + idForReporting, e); } - Set notFoundDiff = computeNotFoundCapabilities(expectedCapabilities, serviceCandidate); + Set notFoundDiff = computeNotFoundCapabilities(expectedCapabilities, configNetconfConnector); if (notFoundDiff.isEmpty()) { return serviceCandidate; } else { serviceCandidate.close(); LOG.trace("Netconf server did not provide required capabilities for {} ", idForReporting, "Expected but not found: {}, all expected {}, current {}", - notFoundDiff, expectedCapabilities, serviceCandidate.getCapabilities() + notFoundDiff, expectedCapabilities, configNetconfConnector.getCapabilities() ); throw new NotEnoughCapabilitiesException("Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundDiff); } } - private static Set computeNotFoundCapabilities(Set expectedCapabilities, NetconfOperationService serviceCandidate) { + private static Set computeNotFoundCapabilities(Set expectedCapabilities, NetconfOperationServiceFactory serviceCandidate) { Collection actual = Collections2.transform(serviceCandidate.getCapabilities(), new Function() { @Override public String apply(@Nonnull final Capability input) { diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java index 787f8b10b0..b27bec3c83 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java @@ -13,10 +13,10 @@ import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import javax.management.MBeanServer; import org.opendaylight.controller.config.persist.api.ConfigPusher; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.controller.netconf.persist.impl.ConfigPusherImpl; import org.opendaylight.controller.netconf.persist.impl.PersisterAggregator; @@ -70,7 +70,7 @@ public class ConfigPersisterActivator implements BundleActivator { InnerCustomizer innerCustomizer = new InnerCustomizer(configs, maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis, persisterAggregator); OuterCustomizer outerCustomizer = new OuterCustomizer(context, innerCustomizer); - new ServiceTracker<>(context, NetconfOperationProvider.class, outerCustomizer).open(); + new ServiceTracker<>(context, NetconfOperationServiceFactory.class, outerCustomizer).open(); } private long getConflictingVersionTimeoutMillis(PropertiesProviderBaseImpl propertiesProvider) { @@ -103,7 +103,7 @@ public class ConfigPersisterActivator implements BundleActivator { ")"; } - class OuterCustomizer implements ServiceTrackerCustomizer { + class OuterCustomizer implements ServiceTrackerCustomizer { private final BundleContext context; private final InnerCustomizer innerCustomizer; @@ -113,7 +113,7 @@ public class ConfigPersisterActivator implements BundleActivator { } @Override - public NetconfOperationProvider addingService(ServiceReference reference) { + public NetconfOperationServiceFactory addingService(ServiceReference reference) { LOG.trace("Got OuterCustomizer.addingService {}", reference); // JMX was registered, track config-netconf-connector Filter filter; @@ -127,12 +127,12 @@ public class ConfigPersisterActivator implements BundleActivator { } @Override - public void modifiedService(ServiceReference reference, NetconfOperationProvider service) { + public void modifiedService(ServiceReference reference, NetconfOperationServiceFactory service) { } @Override - public void removedService(ServiceReference reference, NetconfOperationProvider service) { + public void removedService(ServiceReference reference, NetconfOperationServiceFactory service) { } } @@ -141,7 +141,9 @@ public class ConfigPersisterActivator implements BundleActivator { private final List configs; private final PersisterAggregator persisterAggregator; private final long maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis; - + // This inner customizer has its filter to find the right operation service, but it gets triggered after any + // operation service appears. This means that it could start pushing thread up to N times (N = number of operation services spawned in OSGi) + private final AtomicBoolean alreadyStarted = new AtomicBoolean(false); InnerCustomizer(List configs, long maxWaitForCapabilitiesMillis, long conflictingVersionTimeoutMillis, PersisterAggregator persisterAggregator) { @@ -153,6 +155,10 @@ public class ConfigPersisterActivator implements BundleActivator { @Override public NetconfOperationServiceFactory addingService(ServiceReference reference) { + if(alreadyStarted.compareAndSet(false, true) == false) { + //Prevents multiple calls to this method spawning multiple pushing threads + return reference.getBundle().getBundleContext().getService(reference); + } LOG.trace("Got InnerCustomizer.addingService {}", reference); NetconfOperationServiceFactory service = reference.getBundle().getBundleContext().getService(reference); @@ -196,10 +202,12 @@ public class ConfigPersisterActivator implements BundleActivator { @Override public void modifiedService(ServiceReference reference, NetconfOperationServiceFactory service) { + LOG.trace("Got InnerCustomizer.modifiedService {}", reference); } @Override public void removedService(ServiceReference reference, NetconfOperationServiceFactory service) { + LOG.trace("Got InnerCustomizer.removedService {}", reference); } } diff --git a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java index 142d8f5226..7b79e41f38 100644 --- a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java +++ b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java @@ -20,8 +20,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; @@ -41,9 +41,10 @@ public class ConfigPersisterTest { private TestingExceptionHandler handler; - private void setUpContextAndStartPersister(String requiredCapability) throws Exception { + private void setUpContextAndStartPersister(String requiredCapability, final NetconfOperationService conflictingService) throws Exception { DummyAdapterWithInitialSnapshot.expectedCapability = requiredCapability; ctx = new MockedBundleContext(1000, 1000); + doReturn(getConflictingService()).when(ctx.serviceFactory).createService(anyString()); configPersisterActivator = new ConfigPersisterActivator(); configPersisterActivator.start(ctx.getBundleContext()); } @@ -62,7 +63,7 @@ public class ConfigPersisterTest { @Test public void testPersisterNotAllCapabilitiesProvided() throws Exception { - setUpContextAndStartPersister("required-cap"); + setUpContextAndStartPersister("required-cap", getConflictingService()); Thread.sleep(2000); handler.assertException(IllegalStateException.class, "Max wait for capabilities reached.Not enough capabilities " + "for . Expected but not found: [required-cap]"); @@ -71,7 +72,7 @@ public class ConfigPersisterTest { @Test public void testPersisterSuccessfulPush() throws Exception { - setUpContextAndStartPersister("cap1"); + setUpContextAndStartPersister("cap1", getConflictingService()); NetconfOperationService service = getWorkingService(getOKDocument()); doReturn(service).when(ctx.serviceFactory).createService(anyString()); Thread.sleep(2000); @@ -86,7 +87,7 @@ public class ConfigPersisterTest { public NetconfOperationService getWorkingService(Document document) throws SAXException, IOException, NetconfDocumentedException { NetconfOperationService service = mock(NetconfOperationService.class); Capability capability = mock(Capability.class); - doReturn(Sets.newHashSet(capability)).when(service).getCapabilities(); +// doReturn(Sets.newHashSet(capability)).when(service).getCapabilities(); doReturn("cap1").when(capability).getCapabilityUri(); @@ -109,9 +110,8 @@ public class ConfigPersisterTest { @Test public void testPersisterConflictingVersionException() throws Exception { - setUpContextAndStartPersister("cap1"); + setUpContextAndStartPersister("cap1", getConflictingService()); - doReturn(getConflictingService()).when(ctx.serviceFactory).createService(anyString()); Thread.sleep(2000); handler.assertException(IllegalStateException.class, "Max wait for conflicting version stabilization timeout"); } @@ -131,7 +131,7 @@ public class ConfigPersisterTest { @Test public void testSuccessConflictingVersionException() throws Exception { - setUpContextAndStartPersister("cap1"); + setUpContextAndStartPersister("cap1", getConflictingService()); doReturn(getConflictingService()).when(ctx.serviceFactory).createService(anyString()); Thread.sleep(500); // working service: diff --git a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/MockedBundleContext.java b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/MockedBundleContext.java index 0d866ecda7..bd18c8c30e 100644 --- a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/MockedBundleContext.java +++ b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/MockedBundleContext.java @@ -12,6 +12,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -28,7 +29,7 @@ import org.opendaylight.controller.config.persist.api.ConfigPusher; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.config.persist.api.Persister; import org.opendaylight.controller.config.persist.api.PropertiesProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.controller.netconf.persist.impl.DummyAdapter; @@ -60,11 +61,11 @@ final class MockedBundleContext { doReturn(null).when(context).getProperty(anyString()); initContext(maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis); - String outerFilterString = "(objectClass=org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider)"; + String outerFilterString = "(objectClass=org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory)"; doReturn(outerFilter).when(context).createFilter(outerFilterString); doNothing().when(context).addServiceListener(any(ServiceListener.class), eq(outerFilterString)); ServiceReference[] toBeReturned = {serviceReference}; - doReturn(toBeReturned).when(context).getServiceReferences(NetconfOperationProvider.class.getName(), null); + doReturn(toBeReturned).when(context).getServiceReferences(NetconfOperationServiceFactory.class.getName(), null); String innerFilterString = "innerfilter"; doReturn(innerFilterString).when(outerFilter).toString(); @@ -77,9 +78,12 @@ final class MockedBundleContext { doReturn(bundle).when(serviceReference).getBundle(); doReturn(context).when(bundle).getBundleContext(); doReturn("").when(serviceReference).toString(); + doReturn("context").when(context).toString(); doReturn(serviceFactory).when(context).getService(any(ServiceReference.class)); doReturn(service).when(serviceFactory).createService(anyString()); - doReturn(Collections.emptySet()).when(service).getCapabilities(); + final Capability cap = mock(Capability.class); + doReturn("cap1").when(cap).getCapabilityUri(); + doReturn(Collections.singleton(cap)).when(serviceFactory).getCapabilities(); doNothing().when(service).close(); doReturn("serviceFactoryMock").when(serviceFactory).toString(); diff --git a/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang b/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang index b4ad89b558..84756fc713 100644 --- a/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang +++ b/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang @@ -9,7 +9,9 @@ module ietf-netconf-monitoring { import ietf-yang-types { prefix yang; + revision-date "2010-09-24"; } + import ietf-inet-types { prefix inet; } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java index ccf751285a..bf8bdb06f3 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java @@ -26,7 +26,15 @@ public class NetconfMdsalMapperModule extends org.opendaylight.controller.config @Override public java.lang.AutoCloseable createInstance() { - return new MdsalNetconfOperationServiceFactory(getRootSchemaServiceDependency(), getDomBrokerDependency()); + final MdsalNetconfOperationServiceFactory mdsalNetconfOperationServiceFactory = new MdsalNetconfOperationServiceFactory(getRootSchemaServiceDependency(), getDomBrokerDependency()) { + @Override + public void close() throws Exception { + super.close(); + getMapperAggregatorDependency().onRemoveNetconfOperationServiceFactory(this); + } + }; + getMapperAggregatorDependency().onAddNetconfOperationServiceFactory(mdsalNetconfOperationServiceFactory); + return mdsalNetconfOperationServiceFactory; } } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java index df671e8f4f..1aa38eb80c 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java @@ -9,7 +9,12 @@ package org.opendaylight.controller.netconf.mdsal.connector; import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -18,6 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; public class CurrentSchemaContext implements SchemaContextListener, AutoCloseable { final AtomicReference currentContext = new AtomicReference(); private final ListenerRegistration schemaContextListenerListenerRegistration; + private final Set listeners = Collections.synchronizedSet(Sets.newHashSet()); public SchemaContext getCurrentContext() { Preconditions.checkState(currentContext.get() != null, "Current context not received"); @@ -31,11 +37,28 @@ public class CurrentSchemaContext implements SchemaContextListener, AutoCloseabl @Override public void onGlobalContextUpdated(final SchemaContext schemaContext) { currentContext.set(schemaContext); + // FIXME is notifying all the listeners from this callback wise ? + final Set addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get()); + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesAdded(addedCaps); + } } @Override public void close() throws Exception { + listeners.clear(); schemaContextListenerListenerRegistration.close(); currentContext.set(null); } + + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get())); + listeners.add(listener); + return new AutoCloseable() { + @Override + public void close() throws Exception { + listeners.remove(listener); + } + }; + } } \ No newline at end of file diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationService.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationService.java index f54c5e9838..cc22dd51aa 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationService.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationService.java @@ -8,34 +8,17 @@ package org.opendaylight.controller.netconf.mdsal.connector; -import com.google.common.base.Optional; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class MdsalNetconfOperationService implements NetconfOperationService { - private static final Logger LOG = LoggerFactory.getLogger(MdsalNetconfOperationService.class); - - private final CurrentSchemaContext schemaContext; - private final String netconfSessionIdForReporting; private final OperationProvider operationProvider; public MdsalNetconfOperationService(final CurrentSchemaContext schemaContext, final String netconfSessionIdForReporting, final DOMDataBroker dataBroker) { - this.schemaContext = schemaContext; - // TODO schema contexts are different in data broker and the one we receive here ... the one received here should be updated same way as broker is - this.netconfSessionIdForReporting = netconfSessionIdForReporting; this.operationProvider = new OperationProvider(netconfSessionIdForReporting, schemaContext, dataBroker); } @@ -44,115 +27,9 @@ public class MdsalNetconfOperationService implements NetconfOperationService { } - // TODO does this get called dynamically ? - @Override - public Set getCapabilities() { - final Set capabilities = new HashSet<>(); - // [RFC6241] 8.3. Candidate Configuration Capability - capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); - - final SchemaContext currentContext = schemaContext.getCurrentContext(); - final Set modules = currentContext.getModules(); - for (final Module module : modules) { - if(currentContext.getModuleSource(module).isPresent()) { - capabilities.add(new YangStoreCapability(module, currentContext.getModuleSource(module).get())); - } else { - LOG.warn("Missing source for module {}. This module will not be available from netconf server for session {}", - module, netconfSessionIdForReporting); - } - } - - return capabilities; - } - @Override public Set getNetconfOperations() { return operationProvider.getOperations(); } - // TODO reuse from netconf impl - private static class BasicCapability implements Capability { - - private final String capability; - - private BasicCapability(final String capability) { - this.capability = capability; - } - - @Override - public String getCapabilityUri() { - return capability; - } - - @Override - public Optional getModuleNamespace() { - return Optional.absent(); - } - - @Override - public Optional getModuleName() { - return Optional.absent(); - } - - @Override - public Optional getRevision() { - return Optional.absent(); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.absent(); - } - - @Override - public Collection getLocation() { - return Collections.emptyList(); - } - - @Override - public String toString() { - return capability; - } - } - - private static final class YangStoreCapability extends BasicCapability { - - private final String content; - private final String revision; - private final String moduleName; - private final String moduleNamespace; - - public YangStoreCapability(final Module module, final String moduleContent) { - super(toCapabilityURI(module)); - this.content = moduleContent; - this.moduleName = module.getName(); - this.moduleNamespace = module.getNamespace().toString(); - this.revision = SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.of(content); - } - - private static String toCapabilityURI(final Module module) { - return String.valueOf(module.getNamespace()) + "?module=" - + module.getName() + "&revision=" + SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()); - } - - @Override - public Optional getModuleName() { - return Optional.of(moduleName); - } - - @Override - public Optional getModuleNamespace() { - return Optional.of(moduleNamespace); - } - - @Override - public Optional getRevision() { - return Optional.of(revision); - } - } } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java index 098f25bf4a..ebb0e9d3d1 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java @@ -8,13 +8,27 @@ package org.opendaylight.controller.netconf.mdsal.connector; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MdsalNetconfOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(MdsalNetconfOperationServiceFactory.class); + private final DOMDataBroker dataBroker; private final CurrentSchemaContext currentSchemaContext; @@ -32,4 +46,118 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ public void close() throws Exception { currentSchemaContext.close(); } + + @Override + public Set getCapabilities() { + return transformCapabilities(currentSchemaContext.getCurrentContext()); + } + + static Set transformCapabilities(final SchemaContext currentContext1) { + final Set capabilities = new HashSet<>(); + // [RFC6241] 8.3. Candidate Configuration Capability + capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); + + final SchemaContext currentContext = currentContext1; + final Set modules = currentContext.getModules(); + for (final Module module : modules) { + if(currentContext.getModuleSource(module).isPresent()) { + capabilities.add(new YangStoreCapability(module, currentContext.getModuleSource(module).get())); + } else { + LOG.warn("Missing source for module {}. This module will not be available from netconf server", + module); + } + } + + return capabilities; + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + return currentSchemaContext.registerCapabilityListener(listener); + } + + private static class BasicCapability implements Capability { + + private final String capability; + + private BasicCapability(final String capability) { + this.capability = capability; + } + + @Override + public String getCapabilityUri() { + return capability; + } + + @Override + public Optional getModuleNamespace() { + return Optional.absent(); + } + + @Override + public Optional getModuleName() { + return Optional.absent(); + } + + @Override + public Optional getRevision() { + return Optional.absent(); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.absent(); + } + + @Override + public Collection getLocation() { + return Collections.emptyList(); + } + + @Override + public String toString() { + return capability; + } + } + + private static final class YangStoreCapability extends BasicCapability { + + private final String content; + private final String revision; + private final String moduleName; + private final String moduleNamespace; + + public YangStoreCapability(final Module module, final String moduleContent) { + super(toCapabilityURI(module)); + this.content = moduleContent; + this.moduleName = module.getName(); + this.moduleNamespace = module.getNamespace().toString(); + this.revision = SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.of(content); + } + + private static String toCapabilityURI(final Module module) { + return String.valueOf(module.getNamespace()) + "?module=" + + module.getName() + "&revision=" + SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()); + } + + @Override + public Optional getModuleName() { + return Optional.of(moduleName); + } + + @Override + public Optional getModuleNamespace() { + return Optional.of(moduleNamespace); + } + + @Override + public Optional getRevision() { + return Optional.of(revision); + } + } } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/AbstractGet.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/AbstractGet.java index e0c004461c..8f6ff417d6 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/AbstractGet.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/AbstractGet.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.netconf.mdsal.connector.ops.get; import com.google.common.base.Function; +import com.google.common.base.Optional; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import java.io.IOException; @@ -115,13 +116,13 @@ public abstract class AbstractGet extends AbstractLastNetconfOperation { } protected static final class GetConfigExecution { - private final Datastore datastore; + private final Optional datastore; - public GetConfigExecution(final Datastore datastore) { + public GetConfigExecution(final Optional datastore) { this.datastore = datastore; } - public Datastore getDatastore() { + public Optional getDatastore() { return datastore; } @@ -132,7 +133,7 @@ public abstract class AbstractGet extends AbstractLastNetconfOperation { throw new NetconfDocumentedException("Incorrect RPC: " + e.getMessage(), e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo()); } - final Datastore sourceDatastore; + final Optional sourceDatastore; try { sourceDatastore = parseSource(xml); } catch (final NetconfDocumentedException e) { @@ -144,14 +145,12 @@ public abstract class AbstractGet extends AbstractLastNetconfOperation { return new GetConfigExecution(sourceDatastore); } - private static Datastore parseSource(final XmlElement xml) throws NetconfDocumentedException { - final Datastore sourceDatastore; - final XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY, + private static Optional parseSource(final XmlElement xml) throws NetconfDocumentedException { + final Optional sourceElement = xml.getOnlyChildElementOptionally(XmlNetconfConstants.SOURCE_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - final String sourceParsed = sourceElement.getOnlyChildElement().getName(); - sourceDatastore = Datastore.valueOf(sourceParsed); - return sourceDatastore; + return sourceElement.isPresent() ? + Optional.of(Datastore.valueOf(sourceElement.get().getOnlyChildElement().getName())) : Optional.absent(); } private static void validateInputRpc(final XmlElement xml, String operationName) throws NetconfDocumentedException{ diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/Get.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/Get.java index a2b2fbb0db..cebd8c8883 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/Get.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/Get.java @@ -52,13 +52,10 @@ public class Get extends AbstractGet { } final YangInstanceIdentifier dataRoot = ROOT; - DOMDataReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore()); + DOMDataReadWriteTransaction rwTx = getTransaction(Datastore.running); try { final Optional> normalizedNodeOptional = rwTx.read(LogicalDatastoreType.OPERATIONAL, dataRoot).checkedGet(); - if (getConfigExecution.getDatastore() == Datastore.running) { - transactionProvider.abortRunningTransaction(rwTx); - rwTx = null; - } + transactionProvider.abortRunningTransaction(rwTx); return (Element) transformNormalizedNode(document, normalizedNodeOptional.get(), dataRoot); } catch (ReadFailedException e) { LOG.warn("Unable to read data: {}", dataRoot, e); diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java index b56bcc795c..f2d8abbb61 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.netconf.mdsal.connector.ops.get; import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; @@ -52,10 +53,13 @@ public class GetConfig extends AbstractGet { } final YangInstanceIdentifier dataRoot = ROOT; - DOMDataReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore()); + // Proper exception should be thrown + Preconditions.checkState(getConfigExecution.getDatastore().isPresent(), "Source element missing from request"); + + DOMDataReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore().get()); try { final Optional> normalizedNodeOptional = rwTx.read(LogicalDatastoreType.CONFIGURATION, dataRoot).checkedGet(); - if (getConfigExecution.getDatastore() == Datastore.running) { + if (getConfigExecution.getDatastore().get() == Datastore.running) { transactionProvider.abortRunningTransaction(rwTx); rwTx = null; } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang b/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang index b1d04106d7..9d9966e8f1 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang @@ -44,6 +44,15 @@ module netconf-mdsal-mapper { } } } + + container mapper-aggregator { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nnm:netconf-mapper-registry; + } + } + } } } diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/pom.xml b/opendaylight/netconf/mdsal-netconf-monitoring/pom.xml new file mode 100644 index 0000000000..3e78dd19e3 --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + org.opendaylight.controller + netconf-subsystem + 0.3.0-SNAPSHOT + + mdsal-netconf-monitoring + bundle + ${project.artifactId} + + + + + ${project.groupId} + netconf-api + + + ${project.groupId} + netconf-mapping-api + + + ${project.groupId} + netconf-monitoring + + + ${project.groupId} + netconf-util + + + org.opendaylight.controller + sal-binding-config + + + + com.google.guava + guava + + + + org.opendaylight.yangtools + mockito-configuration + + + org.opendaylight.yangtools.model + ietf-inet-types + + + org.slf4j + slf4j-api + + + + + + + org.apache.felix + maven-bundle-plugin + + + 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 + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + + + + + diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java new file mode 100644 index 0000000000..50958e423f --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015 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.config.yang.netconf.mdsal.monitoring; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class MonitoringToMdsalWriter implements AutoCloseable, NetconfMonitoringService.MonitoringListener, BindingAwareProvider { + + private static final Logger LOG = LoggerFactory.getLogger(MonitoringToMdsalWriter.class); + + private final NetconfMonitoringService serverMonitoringDependency; + private DataBroker dataBroker; + + public MonitoringToMdsalWriter(final NetconfMonitoringService serverMonitoringDependency) { + this.serverMonitoringDependency = serverMonitoringDependency; + } + + @Override + public void close() { + final WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(NetconfState.class)); + final CheckedFuture submit = tx.submit(); + + Futures.addCallback(submit, new FutureCallback() { + @Override + public void onSuccess(final Void aVoid) { + LOG.debug("Netconf state cleared successfully"); + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Unable to clear netconf state", throwable); + } + }); + } + + @Override + public void onStateChanged(final NetconfState state) { + Preconditions.checkState(dataBroker != null); + final WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(NetconfState.class), state); + // FIXME first attempt (right after we register to binding broker) always fails + // Is it due to the fact that we are writing from the onSessionInitiated callback ? + final CheckedFuture submit = tx.submit(); + + Futures.addCallback(submit, new FutureCallback() { + @Override + public void onSuccess(final Void aVoid) { + LOG.debug("Netconf state updated successfully"); + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Unable to update netconf state", throwable); + } + }); + } + + @Override + public void onSessionInitiated(final BindingAwareBroker.ProviderContext providerContext) { + dataBroker = providerContext.getSALService(DataBroker.class); + serverMonitoringDependency.registerListener(this); + } +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModule.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModule.java new file mode 100644 index 0000000000..dadc0f493b --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModule.java @@ -0,0 +1,149 @@ +package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring; + +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.monitoring.GetSchema; +import org.opendaylight.controller.netconf.monitoring.MonitoringConstants; + +public class NetconfMdsalMonitoringMapperModule extends org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.AbstractNetconfMdsalMonitoringMapperModule { + public NetconfMdsalMonitoringMapperModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfMdsalMonitoringMapperModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule oldModule, final java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final NetconfMonitoringService serverMonitoringDependency = getServerMonitoringDependency(); + + final MonitoringToMdsalWriter monitoringToMdsalWriter = new MonitoringToMdsalWriter(serverMonitoringDependency); + getBindingAwareBrokerDependency().registerProvider(monitoringToMdsalWriter); + + final MdSalMonitoringMapperFactory mdSalMonitoringMapperFactory = new MdSalMonitoringMapperFactory(new MdsalMonitoringMapper(serverMonitoringDependency)) { + @Override + public void close() { + super.close(); + monitoringToMdsalWriter.close(); + getAggregatorDependency().onRemoveNetconfOperationServiceFactory(this); + } + }; + + getAggregatorDependency().onAddNetconfOperationServiceFactory(mdSalMonitoringMapperFactory); + return mdSalMonitoringMapperFactory; + + } + + // FIXME almost exactly same code as in netconf-monitoring, refactor + private static class MdSalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable { + + private final NetconfOperationService operationService; + + private static final Set CAPABILITIES = Sets.newHashSet(new Capability() { + + @Override + public String getCapabilityUri() { + return MonitoringConstants.URI; + } + + @Override + public Optional getModuleNamespace() { + return Optional.of(MonitoringConstants.NAMESPACE); + } + + @Override + public Optional getModuleName() { + return Optional.of(MonitoringConstants.MODULE_NAME); + } + + @Override + public Optional getRevision() { + return Optional.of(MonitoringConstants.MODULE_REVISION); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.absent(); + } + + @Override + public Collection getLocation() { + return Collections.emptyList(); + } + }); + + private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + + private final List listeners = new ArrayList<>(); + + public MdSalMonitoringMapperFactory(final NetconfOperationService operationService) { + this.operationService = operationService; + } + + @Override + public NetconfOperationService createService(final String netconfSessionIdForReporting) { + return operationService; + } + + @Override + public Set getCapabilities() { + return CAPABILITIES; + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(getCapabilities()); + listeners.add(listener); + return AUTO_CLOSEABLE; + } + + @Override + public void close() { + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesRemoved(getCapabilities()); + } + } + } + + + private static class MdsalMonitoringMapper implements NetconfOperationService { + + private final NetconfMonitoringService serverMonitoringDependency; + + public MdsalMonitoringMapper(final NetconfMonitoringService serverMonitoringDependency) { + this.serverMonitoringDependency = serverMonitoringDependency; + } + + @Override + public Set getNetconfOperations() { + return Collections.singleton(new GetSchema(serverMonitoringDependency)); + } + + @Override + public void close() { + // NOOP + } + } +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModuleFactory.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModuleFactory.java new file mode 100644 index 0000000000..e0d459318f --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-mdsal-monitoring yang module local name: netconf-mdsal-monitoring-mapper +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Wed Feb 18 10:22:17 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring; +public class NetconfMdsalMonitoringMapperModuleFactory extends org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.AbstractNetconfMdsalMonitoringMapperModuleFactory { + +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationService.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationService.java new file mode 100644 index 0000000000..9ae4df429c --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationService.java @@ -0,0 +1,35 @@ +/* +* 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.monitoring; + +import com.google.common.collect.Sets; +import java.util.Set; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.monitoring.Get; +import org.opendaylight.controller.netconf.monitoring.GetSchema; + +public class NetconfMonitoringOperationService implements NetconfOperationService { + + private final NetconfMonitoringService monitor; + + public NetconfMonitoringOperationService(final NetconfMonitoringService monitor) { + this.monitor = monitor; + } + + @Override + public Set getNetconfOperations() { + return Sets.newHashSet(new Get(monitor), new GetSchema(monitor)); + } + + @Override + public void close() { + } + +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationServiceFactory.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationServiceFactory.java new file mode 100644 index 0000000000..78c23688e4 --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationServiceFactory.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2015 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.monitoring; + +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; + +/** +* Created by mmarsale on 18.2.2015. +*/ +public class NetconfMonitoringOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable { + + private final NetconfMonitoringOperationService operationService; + + private static final Set CAPABILITIES = Sets.newHashSet(new Capability() { + + @Override + public String getCapabilityUri() { + return MonitoringConstants.URI; + } + + @Override + public Optional getModuleNamespace() { + return Optional.of(MonitoringConstants.NAMESPACE); + } + + @Override + public Optional getModuleName() { + return Optional.of(MonitoringConstants.MODULE_NAME); + } + + @Override + public Optional getRevision() { + return Optional.of(MonitoringConstants.MODULE_REVISION); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.absent(); + } + + @Override + public Collection getLocation() { + return Collections.emptyList(); + } + }); + + private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + + private final List listeners = new ArrayList<>(); + + public NetconfMonitoringOperationServiceFactory(final NetconfMonitoringOperationService operationService) { + this.operationService = operationService; + } + + @Override + public NetconfOperationService createService(final String netconfSessionIdForReporting) { + return operationService; + } + + @Override + public Set getCapabilities() { + return CAPABILITIES; + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(getCapabilities()); + listeners.add(listener); + return AUTO_CLOSEABLE; + } + + @Override + public void close() { + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesRemoved(getCapabilities()); + } + } +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/yang/netconf-mdsal-monitoring.yang b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/yang/netconf-mdsal-monitoring.yang new file mode 100644 index 0000000000..68a248e48e --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/yang/netconf-mdsal-monitoring.yang @@ -0,0 +1,60 @@ +module netconf-mdsal-monitoring { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:monitoring"; + prefix "nmmonitor"; + + import netconf-northbound-mapper { prefix nnm; revision-date 2015-01-14; } + import opendaylight-md-sal-binding {prefix md-sal-binding; revision-date 2013-10-28;} + import netconf-northbound { prefix nn; revision-date 2015-01-14; } + import config { prefix config; revision-date 2013-04-05; } + + organization "Cisco Systems, Inc."; + + description + "This module contains the base YANG definitions for + an MD-SAL monitoring mapper implementation"; + + revision "2015-02-18" { + description + "Initial revision."; + } + + identity netconf-mdsal-monitoring-mapper { + base config:module-type; + config:provided-service nnm:netconf-northbound-mapper; + } + + augment "/config:modules/config:module/config:configuration" { + case netconf-mdsal-monitoring-mapper { + when "/config:modules/config:module/config:type = 'netconf-mdsal-monitoring-mapper'"; + + container server-monitoring { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nn:netconf-server-monitoring; + } + } + } + + container aggregator { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nnm:netconf-mapper-registry; + } + } + } + + container binding-aware-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity md-sal-binding:binding-broker-osgi-registry; + } + } + } + } + } + +} diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/Capability.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/Capability.java similarity index 93% rename from opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/Capability.java rename to opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/Capability.java index 408756bf4d..6a061b1ea9 100644 --- a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/Capability.java +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/Capability.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.mapping.api; +package org.opendaylight.controller.netconf.api; import com.google.common.base.Optional; import java.util.Collection; diff --git a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/CapabilityListener.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/CapabilityListener.java new file mode 100644 index 0000000000..5d9468c8ea --- /dev/null +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/CapabilityListener.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2015 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.api.monitoring; + +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; + +public interface CapabilityListener { + + void onCapabilitiesAdded(Set addedCaps); + + void onCapabilitiesRemoved(Set removedCaps); +} diff --git a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java index 51eea9307d..d22412c7cf 100644 --- a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java @@ -7,12 +7,30 @@ */ package org.opendaylight.controller.netconf.api.monitoring; +import com.google.common.base.Optional; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; -public interface NetconfMonitoringService { +public interface NetconfMonitoringService extends CapabilityListener, SessionListener { Sessions getSessions(); Schemas getSchemas(); + + String getSchemaForCapability(String moduleName, Optional revision); + + Capabilities getCapabilities(); + + /** + * Allows push based state information transfer. After the listener is registered, current state is pushed to the listener. + */ + AutoCloseable registerListener(MonitoringListener listener); + + interface MonitoringListener { + + // TODO more granular updates would make sense + void onStateChanged(NetconfState state); + } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/SessionMonitoringService.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/SessionListener.java similarity index 59% rename from opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/SessionMonitoringService.java rename to opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/SessionListener.java index 7a0b8b7170..a11fb879ca 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/SessionMonitoringService.java +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/SessionListener.java @@ -1,16 +1,17 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015 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.impl.osgi; -import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; - -public interface SessionMonitoringService { +package org.opendaylight.controller.netconf.api.monitoring; +/** + * Created by mmarsale on 13.2.2015. + */ +public interface SessionListener { void onSessionUp(NetconfManagementSession session); void onSessionDown(NetconfManagementSession session); diff --git a/opendaylight/netconf/netconf-api/src/main/yang/netconf-northbound.yang b/opendaylight/netconf/netconf-api/src/main/yang/netconf-northbound.yang index f775da91c0..e2b0d35867 100644 --- a/opendaylight/netconf/netconf-api/src/main/yang/netconf-northbound.yang +++ b/opendaylight/netconf/netconf-api/src/main/yang/netconf-northbound.yang @@ -19,4 +19,9 @@ module netconf-northbound { config:java-class "org.opendaylight.controller.netconf.api.NetconfServerDispatcher"; } + identity netconf-server-monitoring { + base "config:service-type"; + config:java-class "org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService"; + } + } \ No newline at end of file diff --git a/opendaylight/netconf/netconf-artifacts/pom.xml b/opendaylight/netconf/netconf-artifacts/pom.xml index 1248933915..d27ea55812 100644 --- a/opendaylight/netconf/netconf-artifacts/pom.xml +++ b/opendaylight/netconf/netconf-artifacts/pom.xml @@ -87,6 +87,11 @@ netconf-monitoring ${project.version} + + ${project.groupId} + mdsal-netconf-monitoring + ${project.version} + ${project.groupId} netconf-netty-util diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModule.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModule.java new file mode 100644 index 0000000000..284c600f0c --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModule.java @@ -0,0 +1,22 @@ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; + +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; + +public class NetconfMapperAggregatorModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfMapperAggregatorModule { + public NetconfMapperAggregatorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfMapperAggregatorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfMapperAggregatorModule oldModule, final java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() {} + + @Override + public java.lang.AutoCloseable createInstance() { + return new AggregatedNetconfOperationServiceFactory(); + } + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModuleFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModuleFactory.java new file mode 100644 index 0000000000..0e415bdfcb --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-northbound-impl yang module local name: netconf-mapper-aggregator +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Tue Feb 17 17:24:19 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; +public class NetconfMapperAggregatorModuleFactory extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfMapperAggregatorModuleFactory { + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java index e64620d4ad..3c476608a2 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java @@ -1,13 +1,12 @@ package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; import org.opendaylight.controller.config.api.JmxAttributeValidationException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.impl.CommitNotifier; import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; -import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; public class NetconfServerDispatcherModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerDispatcherModule { @@ -27,8 +26,8 @@ public class NetconfServerDispatcherModule extends org.opendaylight.controller.c @Override public java.lang.AutoCloseable createInstance() { - final NetconfOperationServiceFactoryListenerImpl aggregatedOpProvider = getAggregatedOpProvider(); - final SessionMonitoringService monitoringService = startMonitoringService(aggregatedOpProvider); + final AggregatedNetconfOperationServiceFactory aggregatedOpProvider = getAggregatedOpProvider(); + final NetconfMonitoringService monitoringService = getServerMonitorDependency(); final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( getTimerDependency(), aggregatedOpProvider, new SessionIdProvider(), getConnectionTimeoutMillis(), CommitNotifier.NoopCommitNotifier.getInstance(), monitoringService); final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( @@ -44,12 +43,8 @@ public class NetconfServerDispatcherModule extends org.opendaylight.controller.c } - private NetconfMonitoringServiceImpl startMonitoringService(final NetconfOperationServiceFactoryListenerImpl netconfOperationProvider) { - return new NetconfMonitoringServiceImpl(netconfOperationProvider); - } - - private NetconfOperationServiceFactoryListenerImpl getAggregatedOpProvider() { - final NetconfOperationServiceFactoryListenerImpl netconfOperationProvider = new NetconfOperationServiceFactoryListenerImpl(); + private AggregatedNetconfOperationServiceFactory getAggregatedOpProvider() { + final AggregatedNetconfOperationServiceFactory netconfOperationProvider = new AggregatedNetconfOperationServiceFactory(); for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getMappersDependency()) { netconfOperationProvider.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModule.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModule.java new file mode 100644 index 0000000000..dc18cd3687 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModule.java @@ -0,0 +1,24 @@ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; + +import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; + +public class NetconfServerMonitoringModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerMonitoringModule { + public NetconfServerMonitoringModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfServerMonitoringModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfServerMonitoringModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new NetconfMonitoringServiceImpl(getAggregatorDependency()); + } + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModuleFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModuleFactory.java new file mode 100644 index 0000000000..fe74486a77 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-northbound-impl yang module local name: netconf-server-monitoring-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Tue Feb 17 17:24:19 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; +public class NetconfServerMonitoringModuleFactory extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerMonitoringModuleFactory { + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/CapabilityProviderImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/CapabilityProviderImpl.java deleted file mode 100644 index 13cc973ba7..0000000000 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/CapabilityProviderImpl.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.impl; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; -import org.opendaylight.controller.netconf.mapping.api.Capability; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CapabilityProviderImpl implements CapabilityProvider { - private final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot; - private final Set capabilityURIs; - - private static final Logger LOG = LoggerFactory.getLogger(CapabilityProviderImpl.class); - - public CapabilityProviderImpl(NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { - this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot; - Map urisToCapabilitiesInternalMap = getCapabilitiesInternal(netconfOperationServiceSnapshot); - List capabilityURIs = new ArrayList<>(urisToCapabilitiesInternalMap.keySet()); - Collections.sort(capabilityURIs); - this.capabilityURIs = Collections.unmodifiableSet(new TreeSet<>(capabilityURIs)); - } - - private static Map getCapabilitiesInternal( - NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) { - Map capabilityMap = Maps.newHashMap(); - - for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) { - final Set caps = netconfOperationService.getCapabilities(); - - for (Capability cap : caps) { - - if(capabilityMap.containsKey(cap.getCapabilityUri())) { - LOG.debug("Duplicate capability {} from service {}", cap.getCapabilityUri(), netconfOperationService); - } - - capabilityMap.put(cap.getCapabilityUri(), cap); - } - } - - return capabilityMap; - } - - @Override - public synchronized String getSchemaForCapability(String moduleName, Optional revision) { - - Map> mappedModulesToRevisionToSchema = Maps.newHashMap(); - - for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) { - final Set caps = netconfOperationService.getCapabilities(); - - for (Capability cap : caps) { - if (!cap.getModuleName().isPresent() - || !cap.getRevision().isPresent() - || !cap.getCapabilitySchema().isPresent()){ - continue; - } - - final String currentModuleName = cap.getModuleName().get(); - Map revisionMap = mappedModulesToRevisionToSchema.get(currentModuleName); - if (revisionMap == null) { - revisionMap = Maps.newHashMap(); - mappedModulesToRevisionToSchema.put(currentModuleName, revisionMap); - } - - String currentRevision = cap.getRevision().get(); - revisionMap.put(currentRevision, cap.getCapabilitySchema().get()); - } - } - - Map revisionMapRequest = mappedModulesToRevisionToSchema.get(moduleName); - Preconditions.checkState(revisionMapRequest != null, "Capability for module %s not present, " + "" - + "available modules : %s", moduleName, capabilityURIs); - - if (revision.isPresent()) { - String schema = revisionMapRequest.get(revision.get()); - - Preconditions.checkState(schema != null, - "Capability for module %s:%s not present, available revisions for module: %s", moduleName, - revision.get(), revisionMapRequest.keySet()); - - return schema; - } else { - Preconditions.checkState(revisionMapRequest.size() == 1, - "Expected 1 capability for module %s, available revisions : %s", moduleName, - revisionMapRequest.keySet()); - return revisionMapRequest.values().iterator().next(); - } - } - - @Override - public synchronized Set getCapabilities() { - return capabilityURIs; - } - -} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java index 8f2c39df06..0cf2dbc281 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java @@ -55,9 +55,9 @@ public final class NetconfServerSession extends AbstractNetconfSession { private static final Logger LOG = LoggerFactory.getLogger(NetconfServerSessionListener.class); - private final SessionMonitoringService monitoringService; + private final NetconfMonitoringService monitoringService; private final NetconfOperationRouter operationRouter; private final AutoCloseable onSessionDownCloseable; - public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, final SessionMonitoringService monitoringService, + public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, NetconfMonitoringService monitoringService, final AutoCloseable onSessionDownCloseable) { this.operationRouter = operationRouter; this.monitoringService = monitoringService; @@ -45,6 +45,8 @@ public class NetconfServerSessionListener implements NetconfSessionListener { - - private final CommitNotifier commitNotifier; - private final SessionMonitoringService monitor; - private final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot; - private final CapabilityProvider capabilityProvider; - - public NetconfServerSessionListenerFactory(final CommitNotifier commitNotifier, - final SessionMonitoringService monitor, - final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, - final CapabilityProvider capabilityProvider) { - - this.commitNotifier = commitNotifier; - this.monitor = monitor; - this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot; - this.capabilityProvider = capabilityProvider; - } - - @Override - public NetconfServerSessionListener getSessionListener() { - NetconfOperationRouter operationRouter = new NetconfOperationRouterImpl(netconfOperationServiceSnapshot, capabilityProvider, commitNotifier); - return new NetconfServerSessionListener(operationRouter, monitor, netconfOperationServiceSnapshot); - } -} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java index 451c066b77..cf489608ca 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java @@ -8,8 +8,6 @@ package org.opendaylight.controller.netconf.impl; -import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting; - import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -19,11 +17,13 @@ import io.netty.util.concurrent.Promise; import java.util.Set; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; -import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; +import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCommit; +import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter; +import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouterImpl; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; import org.opendaylight.protocol.framework.SessionListenerFactory; import org.opendaylight.protocol.framework.SessionNegotiator; @@ -42,28 +42,28 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF private final Timer timer; private final SessionIdProvider idProvider; - private final NetconfOperationProvider netconfOperationProvider; + private final NetconfOperationServiceFactory aggregatedOpService; private final long connectionTimeoutMillis; private final CommitNotifier commitNotificationProducer; - private final SessionMonitoringService monitoringService; + private final NetconfMonitoringService monitoringService; private static final Logger LOG = LoggerFactory.getLogger(NetconfServerSessionNegotiatorFactory.class); private final Set baseCapabilities; // TODO too many params, refactor - public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider, - SessionIdProvider idProvider, long connectionTimeoutMillis, - CommitNotifier commitNot, - SessionMonitoringService monitoringService) { + public NetconfServerSessionNegotiatorFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider, + final SessionIdProvider idProvider, final long connectionTimeoutMillis, + final CommitNotifier commitNot, + final NetconfMonitoringService monitoringService) { this(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, commitNot, monitoringService, DEFAULT_BASE_CAPABILITIES); } // TODO too many params, refactor - public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider, - SessionIdProvider idProvider, long connectionTimeoutMillis, - CommitNotifier commitNot, - SessionMonitoringService monitoringService, Set baseCapabilities) { + public NetconfServerSessionNegotiatorFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider, + final SessionIdProvider idProvider, final long connectionTimeoutMillis, + final CommitNotifier commitNot, + final NetconfMonitoringService monitoringService, final Set baseCapabilities) { this.timer = timer; - this.netconfOperationProvider = netconfOperationProvider; + this.aggregatedOpService = netconfOperationProvider; this.idProvider = idProvider; this.connectionTimeoutMillis = connectionTimeoutMillis; this.commitNotificationProducer = commitNot; @@ -73,12 +73,12 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF private ImmutableSet validateBaseCapabilities(final Set baseCapabilities) { // Check base capabilities to be supported by the server - Sets.SetView unknownBaseCaps = Sets.difference(baseCapabilities, DEFAULT_BASE_CAPABILITIES); + final Sets.SetView unknownBaseCaps = Sets.difference(baseCapabilities, DEFAULT_BASE_CAPABILITIES); Preconditions.checkArgument(unknownBaseCaps.isEmpty(), "Base capabilities that will be supported by netconf server have to be subset of %s, unknown base capabilities: %s", DEFAULT_BASE_CAPABILITIES, unknownBaseCaps); - ImmutableSet.Builder b = ImmutableSet.builder(); + final ImmutableSet.Builder b = ImmutableSet.builder(); b.addAll(baseCapabilities); // Base 1.0 capability is supported by default b.add(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0); @@ -95,32 +95,33 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF * @return session negotiator */ @Override - public SessionNegotiator getSessionNegotiator(SessionListenerFactory defunctSessionListenerFactory, - Channel channel, Promise promise) { - long sessionId = idProvider.getNextSessionId(); - NetconfOperationServiceSnapshot netconfOperationServiceSnapshot = netconfOperationProvider.openSnapshot( - getNetconfSessionIdForReporting(sessionId)); - CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot); - - NetconfServerSessionPreferences proposal = null; + public SessionNegotiator getSessionNegotiator(final SessionListenerFactory defunctSessionListenerFactory, + final Channel channel, final Promise promise) { + final long sessionId = idProvider.getNextSessionId(); + + NetconfServerSessionPreferences proposal; try { - proposal = new NetconfServerSessionPreferences( - createHelloMessage(sessionId, capabilityProvider), sessionId); - } catch (NetconfDocumentedException e) { - LOG.error("Unable to create hello mesage for session {} with capability provider {}", sessionId,capabilityProvider); + proposal = new NetconfServerSessionPreferences(createHelloMessage(sessionId, monitoringService), sessionId); + } catch (final NetconfDocumentedException e) { + LOG.error("Unable to create hello message for session {} with {}", sessionId, monitoringService); throw new IllegalStateException(e); } - NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory( - commitNotificationProducer, monitoringService, - netconfOperationServiceSnapshot, capabilityProvider); - return new NetconfServerSessionNegotiator(proposal, promise, channel, timer, - sessionListenerFactory.getSessionListener(), connectionTimeoutMillis); + getListener(Long.toString(sessionId)), connectionTimeoutMillis); + } + + private NetconfServerSessionListener getListener(final String netconfSessionIdForReporting) { + final NetconfOperationService service = + this.aggregatedOpService.createService(netconfSessionIdForReporting); + final NetconfOperationRouter operationRouter = + new NetconfOperationRouterImpl(service, commitNotificationProducer, monitoringService, netconfSessionIdForReporting); + return new NetconfServerSessionListener(operationRouter, monitoringService, service); + } - private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) throws NetconfDocumentedException { - return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), baseCapabilities), sessionId); + private NetconfHelloMessage createHelloMessage(final long sessionId, final NetconfMonitoringService capabilityProvider) throws NetconfDocumentedException { + return NetconfHelloMessage.createServerHello(Sets.union(DefaultCommit.transformCapabilities(capabilityProvider.getCapabilities()), baseCapabilities), sessionId); } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/CapabilityProvider.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/CapabilityProvider.java deleted file mode 100644 index 60cde27fe5..0000000000 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/CapabilityProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.impl.mapping; - -import com.google.common.base.Optional; -import java.util.Set; - -public interface CapabilityProvider { - - String getSchemaForCapability(String moduleName, Optional revision); - - Set getCapabilities(); - -} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java index 742255f973..8b2c02bcd4 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java @@ -8,18 +8,24 @@ package org.opendaylight.controller.netconf.impl.mapping.operations; +import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.collect.Collections2; +import com.google.common.collect.Sets; import java.io.InputStream; +import java.util.Set; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.impl.CommitNotifier; -import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -32,10 +38,10 @@ public class DefaultCommit extends AbstractNetconfOperation { private static final String NOTIFY_ATTR = "notify"; private final CommitNotifier notificationProducer; - private final CapabilityProvider cap; + private final NetconfMonitoringService cap; private final NetconfOperationRouter operationRouter; - public DefaultCommit(CommitNotifier notifier, CapabilityProvider cap, + public DefaultCommit(CommitNotifier notifier, NetconfMonitoringService cap, String netconfSessionIdForReporting, NetconfOperationRouter netconfOperationRouter) { super(netconfSessionIdForReporting); this.notificationProducer = notifier; @@ -73,12 +79,22 @@ public class DefaultCommit extends AbstractNetconfOperation { removePersisterAttributes(requestMessage); Element cfgSnapshot = getConfigSnapshot(operationRouter); LOG.debug("Config snapshot retrieved successfully {}", cfgSnapshot); - notificationProducer.sendCommitNotification("ok", cfgSnapshot, cap.getCapabilities()); + notificationProducer.sendCommitNotification("ok", cfgSnapshot, transformCapabilities(cap.getCapabilities())); } return subsequentOperation.execute(requestMessage); } + // FIXME move somewhere to util since this is required also by negotiatiorFactory + public static Set transformCapabilities(final Capabilities capabilities) { + return Sets.newHashSet(Collections2.transform(capabilities.getCapability(), new Function() { + @Override + public String apply(final Uri uri) { + return uri.getValue(); + } + })); + } + @Override protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { throw new UnsupportedOperationException("Never gets called"); diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java new file mode 100644 index 0000000000..ae68ecc120 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java @@ -0,0 +1,140 @@ +/* + * 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.impl.osgi; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; +import org.opendaylight.controller.netconf.util.CloseableUtil; + +/** + * NetconfOperationService aggregator. Makes a collection of operation services accessible as one. + */ +public class AggregatedNetconfOperationServiceFactory implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener, AutoCloseable { + + private final Set factories = new HashSet<>(); + private final Multimap registrations = HashMultimap.create(); + private final Set listeners = Sets.newHashSet(); + + @Override + public synchronized void onAddNetconfOperationServiceFactory(NetconfOperationServiceFactory service) { + factories.add(service); + + for (final CapabilityListener listener : listeners) { + AutoCloseable reg = service.registerCapabilityListener(listener); + registrations.put(service, reg); + } + } + + @Override + public synchronized void onRemoveNetconfOperationServiceFactory(NetconfOperationServiceFactory service) { + factories.remove(service); + + for (final AutoCloseable autoCloseable : registrations.get(service)) { + try { + autoCloseable.close(); + } catch (Exception e) { + // FIXME Issue warning + } + } + + registrations.removeAll(service); + } + + @Override + public synchronized Set getCapabilities() { + final HashSet capabilities = Sets.newHashSet(); + for (final NetconfOperationServiceFactory factory : factories) { + capabilities.addAll(factory.getCapabilities()); + } + return capabilities; + } + + @Override + public synchronized AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + final Map regs = Maps.newHashMap(); + + for (final NetconfOperationServiceFactory factory : factories) { + final AutoCloseable reg = factory.registerCapabilityListener(listener); + regs.put(factory, reg); + } + listeners.add(listener); + + return new AutoCloseable() { + @Override + public void close() throws Exception { + synchronized (AggregatedNetconfOperationServiceFactory.this) { + listeners.remove(listener); + CloseableUtil.closeAll(regs.values()); + for (final Map.Entry reg : regs.entrySet()) { + registrations.remove(reg.getKey(), reg.getValue()); + } + } + } + }; + } + + @Override + public synchronized NetconfOperationService createService(final String netconfSessionIdForReporting) { + return new AggregatedNetconfOperation(factories, netconfSessionIdForReporting); + } + + @Override + public synchronized void close() throws Exception { + factories.clear(); + for (AutoCloseable reg : registrations.values()) { + reg.close(); + } + registrations.clear(); + listeners.clear(); + } + + private static final class AggregatedNetconfOperation implements NetconfOperationService { + + private final Set services; + + public AggregatedNetconfOperation(final Set factories, final String netconfSessionIdForReporting) { + final Builder b = ImmutableSet.builder(); + for (final NetconfOperationServiceFactory factory : factories) { + b.add(factory.createService(netconfSessionIdForReporting)); + } + this.services = b.build(); + } + + @Override + public Set getNetconfOperations() { + final HashSet operations = Sets.newHashSet(); + for (final NetconfOperationService service : services) { + operations.addAll(service.getNetconfOperations()); + } + return operations; + } + + @Override + public void close() { + try { + CloseableUtil.closeAll(services); + } catch (final Exception e) { + throw new IllegalStateException("Unable to properly close all aggregated services", e); + } + } + } +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java index a55e32a954..1e35597d9a 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java @@ -19,7 +19,7 @@ import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProduce import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -40,7 +40,7 @@ public class NetconfImplActivator implements BundleActivator { @Override public void start(final BundleContext context) { - NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); + AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); startOperationServiceFactoryTracker(context, factoriesListener); SessionIdProvider idProvider = new SessionIdProvider(); @@ -50,7 +50,7 @@ public class NetconfImplActivator implements BundleActivator { commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); - SessionMonitoringService monitoringService = startMonitoringService(context, factoriesListener); + NetconfMonitoringService monitoringService = startMonitoringService(context, factoriesListener); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( timer, factoriesListener, idProvider, connectionTimeoutMillis, commitNot, monitoringService); @@ -64,17 +64,14 @@ public class NetconfImplActivator implements BundleActivator { LocalAddress address = NetconfConfigUtil.getNetconfLocalAddress(); LOG.trace("Starting local netconf server at {}", address); dispatch.createLocalServer(address); - - context.registerService(NetconfOperationProvider.class, factoriesListener, null); - } - private void startOperationServiceFactoryTracker(BundleContext context, NetconfOperationServiceFactoryListenerImpl factoriesListener) { + private void startOperationServiceFactoryTracker(BundleContext context, NetconfOperationServiceFactoryListener factoriesListener) { factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener); factoriesTracker.open(); } - private NetconfMonitoringServiceImpl startMonitoringService(BundleContext context, NetconfOperationServiceFactoryListenerImpl factoriesListener) { + private NetconfMonitoringServiceImpl startMonitoringService(BundleContext context, AggregatedNetconfOperationServiceFactory factoriesListener) { NetconfMonitoringServiceImpl netconfMonitoringServiceImpl = new NetconfMonitoringServiceImpl(factoriesListener); Dictionary dic = new Hashtable<>(); regMonitoring = context.registerService(NetconfMonitoringService.class, netconfMonitoringServiceImpl, dic); diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java index efbe3ad68f..b02137b748 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java @@ -8,25 +8,32 @@ package org.opendaylight.controller.netconf.impl.osgi; import com.google.common.base.Function; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import io.netty.util.internal.ConcurrentSet; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nonnull; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.Capability; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfStateBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; @@ -38,7 +45,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, SessionMonitoringService { +public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, AutoCloseable { + private static final Schema.Location NETCONF_LOCATION = new Schema.Location(Schema.Location.Enumeration.NETCONF); private static final List NETCONF_LOCATIONS = ImmutableList.of(NETCONF_LOCATION); private static final Logger LOG = LoggerFactory.getLogger(NetconfMonitoringServiceImpl.class); @@ -48,67 +56,142 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S return input.toManagementSession(); } }; + private static final Function CAPABILITY_TO_URI = new Function() { + @Override + public Uri apply(final Capability input) { + return new Uri(input.getCapabilityUri()); + } + }; private final Set sessions = new ConcurrentSet<>(); - private final NetconfOperationProvider netconfOperationProvider; + private final NetconfOperationServiceFactory netconfOperationProvider; + private final Map capabilities = new ConcurrentHashMap<>(); + + private final Set listeners = Sets.newHashSet(); - public NetconfMonitoringServiceImpl(final NetconfOperationProvider netconfOperationProvider) { + public NetconfMonitoringServiceImpl(final NetconfOperationServiceFactory netconfOperationProvider) { this.netconfOperationProvider = netconfOperationProvider; + netconfOperationProvider.registerCapabilityListener(this); } @Override - public void onSessionUp(final NetconfManagementSession session) { + public synchronized void onSessionUp(final NetconfManagementSession session) { LOG.debug("Session {} up", session); Preconditions.checkState(!sessions.contains(session), "Session %s was already added", session); sessions.add(session); + notifyListeners(); } @Override - public void onSessionDown(final NetconfManagementSession session) { + public synchronized void onSessionDown(final NetconfManagementSession session) { LOG.debug("Session {} down", session); Preconditions.checkState(sessions.contains(session), "Session %s not present", session); sessions.remove(session); + notifyListeners(); } @Override - public Sessions getSessions() { + public synchronized Sessions getSessions() { return new SessionsBuilder().setSession(ImmutableList.copyOf(Collections2.transform(sessions, SESSION_FUNCTION))).build(); } @Override - public Schemas getSchemas() { - // capabilities should be split from operations (it will allow to move getSchema operation to monitoring module) - try (NetconfOperationServiceSnapshot snapshot = netconfOperationProvider.openSnapshot("netconf-monitoring")) { - return transformSchemas(snapshot.getServices()); - } catch (RuntimeException e) { + public synchronized Schemas getSchemas() { + try { + return transformSchemas(netconfOperationProvider.getCapabilities()); + } catch (final RuntimeException e) { throw e; - } catch (Exception e) { + } catch (final Exception e) { throw new IllegalStateException("Exception while closing", e); } } - private static Schemas transformSchemas(final Set services) { - // FIXME: Capability implementations do not have hashcode/equals! - final Set caps = new HashSet<>(); - for (NetconfOperationService netconfOperationService : services) { - // TODO check for duplicates ? move capability merging to snapshot - // Split capabilities from operations first and delete this duplicate code - caps.addAll(netconfOperationService.getCapabilities()); + @Override + public synchronized String getSchemaForCapability(final String moduleName, final Optional revision) { + + // FIXME not effective at all + + Map> mappedModulesToRevisionToSchema = Maps.newHashMap(); + + final Collection caps = capabilities.values(); + + for (Capability cap : caps) { + if (!cap.getModuleName().isPresent() + || !cap.getRevision().isPresent() + || !cap.getCapabilitySchema().isPresent()){ + continue; + } + + final String currentModuleName = cap.getModuleName().get(); + Map revisionMap = mappedModulesToRevisionToSchema.get(currentModuleName); + if (revisionMap == null) { + revisionMap = Maps.newHashMap(); + mappedModulesToRevisionToSchema.put(currentModuleName, revisionMap); + } + + String currentRevision = cap.getRevision().get(); + revisionMap.put(currentRevision, cap.getCapabilitySchema().get()); } + Map revisionMapRequest = mappedModulesToRevisionToSchema.get(moduleName); + Preconditions.checkState(revisionMapRequest != null, "Capability for module %s not present, " + "" + + "available modules : %s", moduleName, Collections2.transform(caps, CAPABILITY_TO_URI)); + + if (revision.isPresent()) { + String schema = revisionMapRequest.get(revision.get()); + + Preconditions.checkState(schema != null, + "Capability for module %s:%s not present, available revisions for module: %s", moduleName, + revision.get(), revisionMapRequest.keySet()); + + return schema; + } else { + Preconditions.checkState(revisionMapRequest.size() == 1, + "Expected 1 capability for module %s, available revisions : %s", moduleName, + revisionMapRequest.keySet()); + return revisionMapRequest.values().iterator().next(); + } + } + + @Override + public synchronized Capabilities getCapabilities() { + return new CapabilitiesBuilder().setCapability(Lists.newArrayList(capabilities.keySet())).build(); + } + + @Override + public synchronized AutoCloseable registerListener(final MonitoringListener listener) { + listeners.add(listener); + listener.onStateChanged(getCurrentNetconfState()); + return new AutoCloseable() { + @Override + public void close() throws Exception { + listeners.remove(listener); + } + }; + } + + private NetconfState getCurrentNetconfState() { + return new NetconfStateBuilder() + .setCapabilities(getCapabilities()) + .setSchemas(getSchemas()) + .setSessions(getSessions()) + .build(); + } + + private static Schemas transformSchemas(final Set caps) { final List schemas = new ArrayList<>(caps.size()); - for (Capability cap : caps) { + for (final Capability cap : caps) { if (cap.getCapabilitySchema().isPresent()) { - SchemaBuilder builder = new SchemaBuilder(); + final SchemaBuilder builder = new SchemaBuilder(); Preconditions.checkState(cap.getModuleNamespace().isPresent()); builder.setNamespace(new Uri(cap.getModuleNamespace().get())); Preconditions.checkState(cap.getRevision().isPresent()); - String version = cap.getRevision().get(); + final String version = cap.getRevision().get(); builder.setVersion(version); Preconditions.checkState(cap.getModuleName().isPresent()); - String identifier = cap.getModuleName().get(); + final String identifier = cap.getModuleName().get(); builder.setIdentifier(identifier); builder.setFormat(Yang.class); @@ -132,10 +215,38 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S final Builder b = ImmutableList.builder(); b.add(NETCONF_LOCATION); - for (String location : locations) { + for (final String location : locations) { b.add(new Schema.Location(new Uri(location))); } return b.build(); } + + @Override + public synchronized void onCapabilitiesAdded(final Set addedCaps) { + // FIXME howto check for duplicates + this.capabilities.putAll(Maps.uniqueIndex(addedCaps, CAPABILITY_TO_URI)); + notifyListeners(); + } + + private void notifyListeners() { + for (final MonitoringListener listener : listeners) { + listener.onStateChanged(getCurrentNetconfState()); + } + } + + @Override + public synchronized void onCapabilitiesRemoved(final Set addedCaps) { + for (final Capability addedCap : addedCaps) { + capabilities.remove(addedCap.getCapabilityUri()); + } + notifyListeners(); + } + + @Override + public synchronized void close() throws Exception { + listeners.clear(); + sessions.clear(); + capabilities.clear(); + } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java index c8fa341747..9d58bd911c 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -17,12 +17,11 @@ import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.impl.CommitNotifier; import org.opendaylight.controller.netconf.impl.NetconfServerSession; -import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCommit; -import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultGetSchema; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultNetconfOperation; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultStartExi; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultStopExi; @@ -30,7 +29,6 @@ import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.mapping.api.SessionAwareNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; @@ -40,29 +38,20 @@ import org.w3c.dom.Document; public class NetconfOperationRouterImpl implements NetconfOperationRouter { private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationRouterImpl.class); - private final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot; + private final NetconfOperationService netconfOperationServiceSnapshot; private final Collection allNetconfOperations; - public NetconfOperationRouterImpl(final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot, final CapabilityProvider capabilityProvider, - final CommitNotifier commitNotifier) { + public NetconfOperationRouterImpl(final NetconfOperationService netconfOperationServiceSnapshot, + final CommitNotifier commitNotifier, final NetconfMonitoringService netconfMonitoringService, final String sessionId) { this.netconfOperationServiceSnapshot = Preconditions.checkNotNull(netconfOperationServiceSnapshot); - final String sessionId = netconfOperationServiceSnapshot.getNetconfSessionIdForReporting(); - final Set ops = new HashSet<>(); - ops.add(new DefaultGetSchema(capabilityProvider, sessionId)); ops.add(new DefaultCloseSession(sessionId, this)); ops.add(new DefaultStartExi(sessionId)); ops.add(new DefaultStopExi(sessionId)); - ops.add(new DefaultCommit(commitNotifier, capabilityProvider, sessionId, this)); + ops.add(new DefaultCommit(commitNotifier, netconfMonitoringService, sessionId, this)); - for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) { - for (NetconfOperation netconfOperation : netconfOperationService.getNetconfOperations()) { - Preconditions.checkState(!ops.contains(netconfOperation), - "Netconf operation %s already present", netconfOperation); - ops.add(netconfOperation); - } - } + ops.addAll(netconfOperationServiceSnapshot.getNetconfOperations()); allNetconfOperations = ImmutableSet.copyOf(ops); } @@ -154,8 +143,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) { Preconditions.checkState(!sortedPriority.containsKey(handlingPriority), - "Multiple %s available to handle message %s with priority %s", - NetconfOperation.class.getName(), message, handlingPriority); + "Multiple %s available to handle message %s with priority %s, %s and %s", + NetconfOperation.class.getName(), message, handlingPriority, netconfOperation, sortedPriority.get(handlingPriority)); sortedPriority.put(handlingPriority, netconfOperation); } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListenerImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListenerImpl.java deleted file mode 100644 index 6c55c35e25..0000000000 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListenerImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.impl.osgi; - -import java.util.HashSet; -import java.util.Set; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; - -public class NetconfOperationServiceFactoryListenerImpl implements NetconfOperationServiceFactoryListener, - NetconfOperationProvider { - private final Set allFactories = new HashSet<>(); - - @Override - public synchronized void onAddNetconfOperationServiceFactory(NetconfOperationServiceFactory service) { - allFactories.add(service); - } - - @Override - public synchronized void onRemoveNetconfOperationServiceFactory(NetconfOperationServiceFactory service) { - allFactories.remove(service); - } - - @Override - public synchronized NetconfOperationServiceSnapshotImpl openSnapshot(String sessionIdForReporting) { - return new NetconfOperationServiceSnapshotImpl(allFactories, sessionIdForReporting); - } - -} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java index 9a077a6130..d97ac90922 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.netconf.impl.osgi; import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; @@ -40,8 +41,9 @@ class NetconfOperationServiceFactoryTracker extends @Override public void removedService(ServiceReference reference, NetconfOperationServiceFactory netconfOperationServiceFactory) { - if (netconfOperationServiceFactory != null) + if (netconfOperationServiceFactory != null) { factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory); + } } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceSnapshotImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceSnapshotImpl.java deleted file mode 100644 index 26abdd974d..0000000000 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceSnapshotImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.impl.osgi; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; -import java.util.Set; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; -import org.opendaylight.controller.netconf.util.CloseableUtil; - -public class NetconfOperationServiceSnapshotImpl implements NetconfOperationServiceSnapshot { - - private final Set services; - private final String netconfSessionIdForReporting; - - public NetconfOperationServiceSnapshotImpl(final Set factories, final String sessionIdForReporting) { - final Builder b = ImmutableSet.builder(); - netconfSessionIdForReporting = sessionIdForReporting; - for (NetconfOperationServiceFactory factory : factories) { - b.add(factory.createService(netconfSessionIdForReporting)); - } - this.services = b.build(); - } - - @Override - public String getNetconfSessionIdForReporting() { - return netconfSessionIdForReporting; - } - - @Override - public Set getServices() { - return services; - } - - @Override - public void close() throws Exception { - CloseableUtil.closeAll(services); - } - - @Override - public String toString() { - return "NetconfOperationServiceSnapshotImpl{" + netconfSessionIdForReporting + '}'; - } -} diff --git a/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang b/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang index 6ca0a7781c..7ad1fef55d 100644 --- a/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang +++ b/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang @@ -67,6 +67,15 @@ module netconf-northbound-impl { } } + container server-monitor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nn:netconf-server-monitoring; + } + } + } + container timer { uses config:service-ref { refine type { @@ -77,4 +86,43 @@ module netconf-northbound-impl { } } + + identity netconf-server-monitoring-impl { + base config:module-type; + config:provided-service nn:netconf-server-monitoring; + config:java-name-prefix NetconfServerMonitoring; + } + + // TODO Monitoring could expose the monitoring data over JMX... + + augment "/config:modules/config:module/config:configuration" { + case netconf-server-monitoring-impl { + when "/config:modules/config:module/config:type = 'netconf-server-monitoring-impl'"; + + container aggregator { + uses config:service-ref { + refine type { + config:required-identity nnm:netconf-northbound-mapper; + } + } + } + + } + } + + identity netconf-mapper-aggregator { + base config:module-type; + config:provided-service nnm:netconf-northbound-mapper; + config:provided-service nnm:netconf-mapper-registry; + config:java-name-prefix NetconfMapperAggregator; + description "Aggregated operation provider for netconf servers. Joins all the operations and capabilities of all the mappers it aggregates and exposes them as a single service. The dependency orientation is reversed in order to prevent cyclic dependencies when monitoring service is considered"; + } + + augment "/config:modules/config:module/config:configuration" { + case netconf-mapper-aggregator { + when "/config:modules/config:module/config:type = 'netconf-mapper-aggregator'"; + + } + } + } \ No newline at end of file diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index 8e8a73b914..512a127d22 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -12,7 +12,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anySetOf; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import com.google.common.base.Preconditions; @@ -48,8 +50,11 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; @@ -57,9 +62,7 @@ import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionList import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.Capability; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; @@ -71,6 +74,8 @@ import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -115,10 +120,19 @@ public class ConcurrentClientsTest { HashedWheelTimer hashedWheelTimer; private TestingNetconfOperation testingNetconfOperation; - public static SessionMonitoringService createMockedMonitoringService() { - SessionMonitoringService monitoring = mock(SessionMonitoringService.class); + public static NetconfMonitoringService createMockedMonitoringService() { + NetconfMonitoringService monitoring = mock(NetconfMonitoringService.class); doNothing().when(monitoring).onSessionUp(any(NetconfServerSession.class)); doNothing().when(monitoring).onSessionDown(any(NetconfServerSession.class)); + doReturn(new AutoCloseable() { + @Override + public void close() throws Exception { + + } + }).when(monitoring).registerListener(any(NetconfMonitoringService.MonitoringListener.class)); + doNothing().when(monitoring).onCapabilitiesAdded(anySetOf(Capability.class)); + doNothing().when(monitoring).onCapabilitiesRemoved(anySetOf(Capability.class)); + doReturn(new CapabilitiesBuilder().setCapability(Collections.emptyList()).build()).when(monitoring).getCapabilities(); return monitoring; } @@ -143,7 +157,7 @@ public class ConcurrentClientsTest { nettyGroup = new NioEventLoopGroup(nettyThreads); netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer); - NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); + AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); testingNetconfOperation = new TestingNetconfOperation(); factoriesListener.onAddNetconfOperationServiceFactory(new TestingOperationServiceFactory(testingNetconfOperation)); @@ -259,13 +273,22 @@ public class ConcurrentClientsTest { this.operations = operations; } + @Override + public Set getCapabilities() { + return Collections.emptySet(); + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + return new AutoCloseable(){ + @Override + public void close() throws Exception {} + }; + } + @Override public NetconfOperationService createService(String netconfSessionIdForReporting) { return new NetconfOperationService() { - @Override - public Set getCapabilities() { - return Collections.emptySet(); - } @Override public Set getNetconfOperations() { diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java index df4069ac17..4fd04e29ef 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java @@ -17,7 +17,7 @@ import java.net.InetSocketAddress; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; public class NetconfDispatcherImplTest { @@ -33,7 +33,7 @@ public class NetconfDispatcherImplTest { commitNot = new DefaultCommitNotificationProducer( ManagementFactory.getPlatformMBeanServer()); - NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); + AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); SessionIdProvider idProvider = new SessionIdProvider(); hashedWheelTimer = new HashedWheelTimer(); diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java index 93caa09286..fed4742dd8 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java @@ -8,107 +8,7 @@ package org.opendaylight.controller.netconf.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import com.google.common.base.Optional; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import io.netty.channel.Channel; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; -import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.mapping.api.Capability; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; -import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; - public class NetconfMonitoringServiceImplTest { - private NetconfMonitoringServiceImpl service; - - @Mock - private NetconfOperationProvider operationProvider; - @Mock - private NetconfManagementSession managementSession; - @Mock - private NetconfOperationServiceSnapshot snapshot; - @Mock - private NetconfOperationService operationService; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - service = new NetconfMonitoringServiceImpl(operationProvider); - } - - @Test - public void testSessions() throws Exception { - doReturn("sessToStr").when(managementSession).toString(); - service.onSessionUp(managementSession); - } - - @Test(expected = RuntimeException.class) - public void testGetSchemas() throws Exception { - doThrow(RuntimeException.class).when(operationProvider).openSnapshot(anyString()); - service.getSchemas(); - } - - @Test(expected = IllegalStateException.class) - public void testGetSchemas2() throws Exception { - doThrow(Exception.class).when(operationProvider).openSnapshot(anyString()); - service.getSchemas(); - } - - @Test - public void testGetSchemas3() throws Exception { - doReturn("").when(managementSession).toString(); - Capability cap = mock(Capability.class); - Set caps = Sets.newHashSet(cap); - Set services = Sets.newHashSet(operationService); - doReturn(snapshot).when(operationProvider).openSnapshot(anyString()); - doReturn(services).when(snapshot).getServices(); - doReturn(caps).when(operationService).getCapabilities(); - Optional opt = mock(Optional.class); - doReturn(opt).when(cap).getCapabilitySchema(); - doReturn(true).when(opt).isPresent(); - doReturn(opt).when(cap).getModuleNamespace(); - doReturn("namespace").when(opt).get(); - Optional optRev = Optional.of("rev"); - doReturn(optRev).when(cap).getRevision(); - doReturn(Optional.of("modName")).when(cap).getModuleName(); - doReturn(Lists.newArrayList("loc")).when(cap).getLocation(); - doNothing().when(snapshot).close(); - - assertNotNull(service.getSchemas()); - verify(snapshot, times(1)).close(); - - NetconfServerSessionListener sessionListener = mock(NetconfServerSessionListener.class); - Channel channel = mock(Channel.class); - doReturn("mockChannel").when(channel).toString(); - NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("name", "addr", "2", "tcp", "id"); - NetconfServerSession sm = new NetconfServerSession(sessionListener, channel, 10, header); - doNothing().when(sessionListener).onSessionUp(any(NetconfServerSession.class)); - sm.sessionUp(); - service.onSessionUp(sm); - assertEquals(1, service.getSessions().getSession().size()); - - assertEquals(Long.valueOf(10), service.getSessions().getSession().get(0).getSessionId()); - - service.onSessionDown(sm); - assertEquals(0, service.getSessions().getSession().size()); - } + // TODO redo test } diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java index 15aeb8d27c..0c7406543f 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java @@ -18,17 +18,19 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import com.google.common.collect.Sets; +import java.util.Collections; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; import org.opendaylight.controller.netconf.impl.NetconfServerSession; -import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -38,7 +40,7 @@ public class DefaultCommitTest { private Document requestMessage; private NetconfOperationRouter router; private DefaultCommitNotificationProducer notifier; - private CapabilityProvider cap; + private NetconfMonitoringService cap; private DefaultCommit commit; @Before @@ -49,8 +51,8 @@ public class DefaultCommitTest { doReturn(false).when(operation).isExecutionTermination(); notifier = mock(DefaultCommitNotificationProducer.class); doNothing().when(notifier).sendCommitNotification(anyString(), any(Element.class), anySetOf(String.class)); - cap = mock(CapabilityProvider.class); - doReturn(Sets.newHashSet()).when(cap).getCapabilities(); + cap = mock(NetconfMonitoringService.class); + doReturn(new CapabilitiesBuilder().setCapability(Collections.emptyList()).build()).when(cap).getCapabilities(); Document rpcData = XmlFileLoader.xmlFileToDocument("netconfMessages/editConfig_expectedResult.xml"); doReturn(rpcData).when(router).onNetconfMessage(any(Document.class), any(NetconfServerSession.class)); commit = new DefaultCommit(notifier, cap, "", router); diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java index 413c9cc945..2fb989507c 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java @@ -12,7 +12,6 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.util.Arrays; @@ -44,11 +43,11 @@ public class NetconfImplActivatorTest { doReturn(filter).when(bundle).createFilter(anyString()); doNothing().when(bundle).addServiceListener(any(ServiceListener.class), anyString()); - ServiceReference[] refs = new ServiceReference[0]; + ServiceReference[] refs = {}; doReturn(refs).when(bundle).getServiceReferences(anyString(), anyString()); doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), anyString()); doReturn("").when(bundle).getProperty(anyString()); - doReturn(registration).when(bundle).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class)); + doReturn(registration).when(bundle).registerService(any(Class.class), any(AggregatedNetconfOperationServiceFactory.class), any(Dictionary.class)); doNothing().when(registration).unregister(); doNothing().when(bundle).removeServiceListener(any(ServiceListener.class)); } @@ -57,7 +56,7 @@ public class NetconfImplActivatorTest { public void testStart() throws Exception { NetconfImplActivator activator = new NetconfImplActivator(); activator.start(bundle); - verify(bundle, times(2)).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class)); + verify(bundle).registerService(any(Class.class), any(AggregatedNetconfOperationServiceFactory.class), any(Dictionary.class)); activator.stop(bundle); } } diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java index 8cb569eaa2..c75cdcd27a 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java @@ -22,6 +22,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.osgi.framework.BundleContext; import org.osgi.framework.Filter; import org.osgi.framework.ServiceReference; diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java index b70e97bac9..c2812dbf61 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java @@ -13,7 +13,6 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anySetOf; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import io.netty.channel.Channel; @@ -47,6 +46,7 @@ import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesMod import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory; import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; @@ -57,13 +57,11 @@ import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProduce import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator; +import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; import org.opendaylight.controller.netconf.notifications.BaseNetconfNotificationListener; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.protocol.framework.NeverReconnectStrategy; @@ -108,14 +106,16 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { setUpTestInitial(); - final NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); + final AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); + final NetconfMonitoringService netconfMonitoringService = getNetconfMonitoringService(factoriesListener); factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore())); + factoriesListener.onAddNetconfOperationServiceFactory(new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(new NetconfMonitoringOperationService(netconfMonitoringService))); - for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories()) { + for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories(factoriesListener)) { factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); } - serverTcpChannel = startNetconfTcpServer(factoriesListener); + serverTcpChannel = startNetconfTcpServer(factoriesListener, netconfMonitoringService); clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); } @@ -137,8 +137,8 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return get; } - private Channel startNetconfTcpServer(final NetconfOperationServiceFactoryListenerImpl factoriesListener) throws Exception { - final NetconfServerDispatcherImpl dispatch = createDispatcher(factoriesListener, getNetconfMonitoringService(), getNotificationProducer()); + private Channel startNetconfTcpServer(final AggregatedNetconfOperationServiceFactory listener, final NetconfMonitoringService monitoring) throws Exception { + final NetconfServerDispatcherImpl dispatch = createDispatcher(listener, monitoring, getNotificationProducer()); final ChannelFuture s; if(getTcpServerAddress() instanceof LocalAddress) { @@ -157,16 +157,12 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return notificationProducer; } - protected Iterable getAdditionalServiceFactories() { + protected Iterable getAdditionalServiceFactories(final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception { return Collections.emptySet(); } - protected SessionMonitoringService getNetconfMonitoringService() throws Exception { - final NetconfOperationProvider netconfOperationProvider = mock(NetconfOperationProvider.class); - final NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class); - doReturn(Collections.emptySet()).when(snap).getServices(); - doReturn(snap).when(netconfOperationProvider).openSnapshot(anyString()); - return new NetconfMonitoringServiceImpl(netconfOperationProvider); + protected NetconfMonitoringService getNetconfMonitoringService(final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception { + return new NetconfMonitoringServiceImpl(factoriesListener); } protected abstract SocketAddress getTcpServerAddress(); @@ -206,7 +202,7 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { } protected NetconfServerDispatcherImpl createDispatcher( - final NetconfOperationServiceFactoryListenerImpl factoriesListener, final SessionMonitoringService sessionMonitoringService, + final AggregatedNetconfOperationServiceFactory factoriesListener, final NetconfMonitoringService sessionMonitoringService, final DefaultCommitNotificationProducer commitNotifier) { final SessionIdProvider idProvider = new SessionIdProvider(); diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java index 92c96d92f2..c421a46fdf 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java @@ -9,23 +9,18 @@ package org.opendaylight.controller.netconf.it; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElementWithName; import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertElementsCount; import static org.opendaylight.controller.netconf.util.xml.XmlUtil.readXmlToDocument; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import java.io.IOException; import java.lang.management.ManagementFactory; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.Collections; import java.util.List; -import java.util.Set; import javax.management.InstanceNotFoundException; import javax.management.Notification; import javax.management.NotificationListener; @@ -38,15 +33,6 @@ import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification; import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; -import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.Capability; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator; -import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.w3c.dom.Document; @@ -58,29 +44,12 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { public static final int PORT = 12026; private static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT); - private NetconfMonitoringServiceImpl netconfMonitoringService; - - @Override - protected void setUpTestInitial() { - netconfMonitoringService = new NetconfMonitoringServiceImpl(getNetconfOperationProvider()); - } - - @Override - protected SessionMonitoringService getNetconfMonitoringService() throws Exception { - return netconfMonitoringService; - } @Override protected SocketAddress getTcpServerAddress() { return TCP_ADDRESS; } - @Override - protected Iterable getAdditionalServiceFactories() { - return Collections.singletonList(new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory( - new NetconfMonitoringOperationService(netconfMonitoringService))); - } - @Override protected DefaultCommitNotificationProducer getNotificationProducer() { return new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); @@ -95,7 +64,6 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { try (ConfigPersisterNotificationHandler configPersisterNotificationHandler = new ConfigPersisterNotificationHandler( platformMBeanServer, mockedAggregator)) { - try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) { NetconfMessage response = netconfClient.sendMessage(loadGetConfigMessage()); assertContainsElementWithName(response.getDocument(), "modules"); @@ -112,8 +80,8 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { } notificationVerifier.assertNotificationCount(2); - notificationVerifier.assertNotificationContent(0, 0, 0, 9); - notificationVerifier.assertNotificationContent(1, 4, 3, 9); + notificationVerifier.assertNotificationContent(0, 0, 0, 8); + notificationVerifier.assertNotificationContent(1, 4, 3, 8); mockedAggregator.assertSnapshotCount(2); // Capabilities are stripped for persister @@ -143,20 +111,6 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml"); } - - public NetconfOperationProvider getNetconfOperationProvider() { - final NetconfOperationProvider factoriesListener = mock(NetconfOperationProvider.class); - final NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class); - final NetconfOperationService service = mock(NetconfOperationService.class); - final Set caps = Sets.newHashSet(); - doReturn(caps).when(service).getCapabilities(); - final Set services = Sets.newHashSet(service); - doReturn(services).when(snap).getServices(); - doReturn(snap).when(factoriesListener).openSnapshot(anyString()); - - return factoriesListener; - } - private static class VerifyingNotificationListener implements NotificationListener { public List notifications = Lists.newArrayList(); diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java index ea94fd3f8b..e745b393fb 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.netconf.it; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -26,21 +27,14 @@ import java.util.Collections; import java.util.List; import java.util.Set; import org.junit.Test; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.client.TestingNetconfClient; -import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.Capability; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator; -import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; -import org.slf4j.Logger; import org.w3c.dom.Document; public class NetconfITMonitoringTest extends AbstractNetconfConfigTest { @@ -49,45 +43,11 @@ public class NetconfITMonitoringTest extends AbstractNetconfConfigTest { public static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT); public static final TestingCapability TESTING_CAPABILITY = new TestingCapability(); - private NetconfMonitoringServiceImpl netconfMonitoringService; - - @Override - protected void setUpTestInitial() { - netconfMonitoringService = new NetconfMonitoringServiceImpl(getNetconfOperationProvider()); - } - - @Override - protected SessionMonitoringService getNetconfMonitoringService() throws Exception { - return netconfMonitoringService; - } - - @Override - protected Iterable getAdditionalServiceFactories() { - return Collections.singletonList(new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory( - new NetconfMonitoringOperationService(netconfMonitoringService))); - } - @Override protected InetSocketAddress getTcpServerAddress() { return TCP_ADDRESS; } - static SessionMonitoringService getNetconfMonitoringListenerService(final Logger LOG, final NetconfMonitoringServiceImpl monitor) { - return new SessionMonitoringService() { - @Override - public void onSessionUp(final NetconfManagementSession session) { - LOG.debug("Management session up {}", session); - monitor.onSessionUp(session); - } - - @Override - public void onSessionDown(final NetconfManagementSession session) { - LOG.debug("Management session down {}", session); - monitor.onSessionDown(session); - } - }; - } - @Test public void testGetResponseFromMonitoring() throws Exception { try (TestingNetconfClient netconfClient = new TestingNetconfClient("client-monitoring", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 10000))) { @@ -151,23 +111,24 @@ public class NetconfITMonitoringTest extends AbstractNetconfConfigTest { assertEquals("Incorrect number of session-id tags in " + XmlUtil.toString(document), i, elementSize); } - public static NetconfOperationProvider getNetconfOperationProvider() { - final NetconfOperationProvider factoriesListener = mock(NetconfOperationProvider.class); - final NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class); + public static AggregatedNetconfOperationServiceFactory getNetconfOperationProvider() throws Exception { + final AggregatedNetconfOperationServiceFactory factoriesListener = mock(AggregatedNetconfOperationServiceFactory.class); + final NetconfOperationService snap = mock(NetconfOperationService.class); try { doNothing().when(snap).close(); } catch (final Exception e) { // not happening throw new IllegalStateException(e); } - final NetconfOperationService service = mock(NetconfOperationService.class); final Set caps = Sets.newHashSet(); caps.add(TESTING_CAPABILITY); - doReturn(caps).when(service).getCapabilities(); - final Set services = Sets.newHashSet(service); - doReturn(services).when(snap).getServices(); - doReturn(snap).when(factoriesListener).openSnapshot(anyString()); + doReturn(caps).when(factoriesListener).getCapabilities(); + doReturn(snap).when(factoriesListener).createService(anyString()); + + AutoCloseable mock = mock(AutoCloseable.class); + doNothing().when(mock).close(); + doReturn(mock).when(factoriesListener).registerCapabilityListener(any(CapabilityListener.class)); return factoriesListener; } diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationProvider.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationProvider.java deleted file mode 100644 index f5c50f8167..0000000000 --- a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.mapping.api; - -public interface NetconfOperationProvider { - - NetconfOperationServiceSnapshot openSnapshot(String sessionIdForReporting); - - public static class NetconfOperationProviderUtil { - - public static String getNetconfSessionIdForReporting(long sessionId) { - return "netconf session id " + sessionId; - } - - } - -} diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationService.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationService.java index 5e2cba2cba..1a1a124895 100644 --- a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationService.java +++ b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationService.java @@ -15,11 +15,6 @@ import java.util.Set; */ public interface NetconfOperationService extends AutoCloseable { - /** - * Get capabilities announced by server hello message. - */ - Set getCapabilities(); - /** * Get set of netconf operations that are handled by this service. */ diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactory.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactory.java index 81401f26ee..8caa177bfa 100644 --- a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactory.java +++ b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactory.java @@ -8,6 +8,10 @@ package org.opendaylight.controller.netconf.mapping.api; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; + /** * Factory that must be registered in OSGi service registry in order to be used * by netconf-impl. Responsible for creating per-session instances of @@ -15,6 +19,16 @@ package org.opendaylight.controller.netconf.mapping.api; */ public interface NetconfOperationServiceFactory { + /** + * Get capabilities supported by current operation service. + */ + Set getCapabilities(); + + /** + * Supported capabilities may change over time, registering a listener allows for push based information retrieval about current notifications + */ + AutoCloseable registerCapabilityListener(CapabilityListener listener); + NetconfOperationService createService(String netconfSessionIdForReporting); } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactoryListener.java similarity index 79% rename from opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java rename to opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactoryListener.java index 8e1052cfeb..30a4f9bf82 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java +++ b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactoryListener.java @@ -6,9 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.impl.osgi; - -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +package org.opendaylight.controller.netconf.mapping.api; public interface NetconfOperationServiceFactoryListener { diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceSnapshot.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceSnapshot.java deleted file mode 100644 index eaa69379f7..0000000000 --- a/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceSnapshot.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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.mapping.api; - -import java.util.Set; - -public interface NetconfOperationServiceSnapshot extends AutoCloseable { - String getNetconfSessionIdForReporting(); - - Set getServices(); - -} diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang b/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang index a709665c63..3ffecde700 100644 --- a/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang +++ b/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang @@ -19,4 +19,9 @@ module netconf-northbound-mapper { config:java-class "org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory"; } + identity netconf-mapper-registry { + base "config:service-type"; + config:java-class "org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener"; + } + } \ No newline at end of file diff --git a/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml b/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml index 042447b1e6..4ca3c99e81 100644 --- a/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml +++ b/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml @@ -25,6 +25,10 @@ dom:dom-async-data-broker inmemory-data-broker + + prefix:netconf-mapper-registry + mapper-aggregator-registry + @@ -32,8 +36,12 @@ netconf-mdsal-server-dispatcher dom:netconf-northbound-mapper - netconf-mdsal-mapper + mapper-aggregator + + prefix:netconf-server-monitoring + server-monitor + prefix:netty-threadgroup global-boss-group @@ -48,6 +56,37 @@ + + prefix:netconf-mdsal-monitoring-mapper + netconf-mdsal-monitoring-mapper + + prefix:netconf-server-monitoring + server-monitor + + + prefix:binding-broker-osgi-registry + binding-osgi-broker + + + prefix:netconf-mapper-registry + mapper-aggregator-registry + + + + + prefix:netconf-mapper-aggregator + mapper-aggregator + + + + prefix:netconf-server-monitoring-impl + server-monitor + + dom:netconf-northbound-mapper + mapper-aggregator + + + prefix:netconf-northbound-ssh netconf-mdsal-ssh-server @@ -76,6 +115,13 @@ + + prefix:netconf-server-monitoring + + server-monitor + /modules/module[type='netconf-server-monitoring-impl'][name='server-monitor'] + + prefix:netconf-northbound-mapper @@ -83,6 +129,20 @@ /modules/module[type='netconf-mdsal-mapper'][name='netconf-mdsal-mapper'] + + prefix:netconf-northbound-mapper + + mapper-aggregator + /modules/module[type='netconf-mapper-aggregator'][name='mapper-aggregator'] + + + + prefix:netconf-mapper-registry + + mapper-aggregator-registry + /modules/module[type='netconf-mapper-aggregator'][name='mapper-aggregator'] + + prefix:netconf-server-dispatcher @@ -96,6 +156,7 @@ urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:mapper?module=netconf-mdsal-mapper&revision=2015-01-14 + urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:monitoring?module=netconf-mdsal-monitoring&revision=2015-02-18 urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:ssh?module=netconf-northbound-ssh&revision=2015-01-14 urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound:impl?module=netconf-northbound-impl&revision=2015-01-12 urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:scheduled?module=threadpool-impl-scheduled&revision=2013-12-01 diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/GetSchema.java similarity index 75% rename from opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java rename to opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/GetSchema.java index 5310704876..d02cb432cb 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java +++ b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/GetSchema.java @@ -1,19 +1,19 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015 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.impl.mapping.operations; +package org.opendaylight.controller.netconf.monitoring; import com.google.common.base.Optional; import com.google.common.collect.Maps; import java.util.Map; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; -import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException; import org.opendaylight.controller.netconf.util.mapping.AbstractLastNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlElement; @@ -23,16 +23,16 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -public final class DefaultGetSchema extends AbstractLastNetconfOperation { +public class GetSchema extends AbstractLastNetconfOperation { public static final String GET_SCHEMA = "get-schema"; public static final String IDENTIFIER = "identifier"; public static final String VERSION = "version"; - private static final Logger LOG = LoggerFactory.getLogger(DefaultGetSchema.class); - private final CapabilityProvider cap; + private static final Logger LOG = LoggerFactory.getLogger(GetSchema.class); + private final NetconfMonitoringService cap; - public DefaultGetSchema(CapabilityProvider cap, String netconfSessionIdForReporting) { - super(netconfSessionIdForReporting); + public GetSchema(final NetconfMonitoringService cap) { + super(MonitoringConstants.MODULE_NAME); this.cap = cap; } @@ -47,16 +47,16 @@ public final class DefaultGetSchema extends AbstractLastNetconfOperation { } @Override - protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { - GetSchemaEntry entry; + protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement xml) throws NetconfDocumentedException { + final GetSchemaEntry entry; entry = new GetSchemaEntry(xml); - String schema; + final String schema; try { schema = cap.getSchemaForCapability(entry.identifier, entry.version); - } catch (IllegalStateException e) { - Map errorInfo = Maps.newHashMap(); + } catch (final IllegalStateException e) { + final Map errorInfo = Maps.newHashMap(); errorInfo.put(entry.identifier, e.getMessage()); LOG.warn("Rpc error: {}", NetconfDocumentedException.ErrorTag.operation_failed, e); throw new NetconfDocumentedException(e.getMessage(), NetconfDocumentedException.ErrorType.application, @@ -64,7 +64,7 @@ public final class DefaultGetSchema extends AbstractLastNetconfOperation { NetconfDocumentedException.ErrorSeverity.error, errorInfo); } - Element getSchemaResult; + final Element getSchemaResult; getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING)); LOG.trace("{} operation successful", GET_SCHEMA); @@ -76,19 +76,19 @@ public final class DefaultGetSchema extends AbstractLastNetconfOperation { private final String identifier; private final Optional version; - GetSchemaEntry(XmlElement getSchemaElement) throws NetconfDocumentedException { + GetSchemaEntry(final XmlElement getSchemaElement) throws NetconfDocumentedException { getSchemaElement.checkName(GET_SCHEMA); getSchemaElement.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING); XmlElement identifierElement = null; try { identifierElement = getSchemaElement.getOnlyChildElementWithSameNamespace(IDENTIFIER); - } catch (MissingNameSpaceException e) { + } catch (final MissingNameSpaceException e) { LOG.trace("Can't get identifier element as only child element with same namespace due to ",e); throw NetconfDocumentedException.wrap(e); } identifier = identifierElement.getTextContent(); - Optional versionElement = getSchemaElement + final Optional versionElement = getSchemaElement .getOnlyChildElementWithSameNamespaceOptionally(VERSION); if (versionElement.isPresent()) { version = Optional.of(versionElement.get().getTextContent()); diff --git a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java index 1411350cd3..1f094f1caf 100644 --- a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java +++ b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.netconf.monitoring.osgi; +import java.util.Collections; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.osgi.framework.BundleActivator; @@ -31,22 +35,43 @@ public class NetconfMonitoringActivator implements BundleActivator { if(monitor!=null) { try { monitor.close(); - } catch (Exception e) { + } catch (final Exception e) { LOG.warn("Ignoring exception while closing {}", monitor, e); } } } - public static class NetconfMonitoringOperationServiceFactory implements NetconfOperationServiceFactory { + public static class NetconfMonitoringOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable { + private final NetconfMonitoringOperationService operationService; - public NetconfMonitoringOperationServiceFactory(NetconfMonitoringOperationService operationService) { + private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + + public NetconfMonitoringOperationServiceFactory(final NetconfMonitoringOperationService operationService) { this.operationService = operationService; } @Override - public NetconfOperationService createService(String netconfSessionIdForReporting) { + public NetconfOperationService createService(final String netconfSessionIdForReporting) { return operationService; } + + @Override + public Set getCapabilities() { + return Collections.emptySet(); + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + return AUTO_CLOSEABLE; + } + + @Override + public void close() {} } } diff --git a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationService.java b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationService.java index a17e139131..efe71e9127 100644 --- a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationService.java +++ b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationService.java @@ -7,67 +7,25 @@ */ package org.opendaylight.controller.netconf.monitoring.osgi; -import com.google.common.base.Optional; import com.google.common.collect.Sets; -import java.util.Collection; -import java.util.Collections; import java.util.Set; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.monitoring.Get; -import org.opendaylight.controller.netconf.monitoring.MonitoringConstants; +import org.opendaylight.controller.netconf.monitoring.GetSchema; public class NetconfMonitoringOperationService implements NetconfOperationService { - private static final Set CAPABILITIES = Sets.newHashSet(new Capability() { - - @Override - public String getCapabilityUri() { - return MonitoringConstants.URI; - } - - @Override - public Optional getModuleNamespace() { - return Optional.of(MonitoringConstants.NAMESPACE); - } - - @Override - public Optional getModuleName() { - return Optional.of(MonitoringConstants.MODULE_NAME); - } - - @Override - public Optional getRevision() { - return Optional.of(MonitoringConstants.MODULE_REVISION); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.absent(); - } - - @Override - public Collection getLocation() { - return Collections.emptyList(); - } - }); - private final NetconfMonitoringService monitor; public NetconfMonitoringOperationService(final NetconfMonitoringService monitor) { this.monitor = monitor; } - @Override - public Set getCapabilities() { - return CAPABILITIES; - } - @Override public Set getNetconfOperations() { - return Sets.newHashSet(new Get(monitor)); + return Sets.newHashSet(new Get(monitor), new GetSchema(monitor)); } @Override diff --git a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java index 9e7c105aa4..5d0a2a91ad 100644 --- a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java +++ b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java @@ -25,6 +25,7 @@ public class NetconfMonitoringServiceTracker extends ServiceTracker reg; + private NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory factory; NetconfMonitoringServiceTracker(final BundleContext context) { super(context, NetconfMonitoringService.class, null); @@ -38,7 +39,7 @@ public class NetconfMonitoringServiceTracker extends ServiceTracker properties = new Hashtable<>(); @@ -58,6 +59,9 @@ public class NetconfMonitoringServiceTracker extends ServiceTracker\n" + " threadpool-api\n" + @@ -45,15 +46,16 @@ public class DefaultGetSchemaTest { @Test(expected = NetconfDocumentedException.class) public void testDefaultGetSchema() throws Exception { - DefaultGetSchema schema = new DefaultGetSchema(cap, ""); + GetSchema schema = new GetSchema(cap); doThrow(IllegalStateException.class).when(cap).getSchemaForCapability(anyString(), any(Optional.class)); schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema))); } @Test public void handleWithNoSubsequentOperations() throws Exception { - DefaultGetSchema schema = new DefaultGetSchema(cap, ""); + GetSchema schema = new GetSchema(cap); doReturn("").when(cap).getSchemaForCapability(anyString(), any(Optional.class)); assertNotNull(schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema)))); } -} + +} \ No newline at end of file diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java index 7873183188..67a54366cd 100644 --- a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java @@ -11,25 +11,17 @@ package org.opendaylight.controller.netconf.monitoring.osgi; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -import com.google.common.base.Optional; -import java.util.Collections; import org.junit.Test; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; -import org.opendaylight.controller.netconf.monitoring.MonitoringConstants; public class NetconfMonitoringOperationServiceTest { @Test public void testGetters() throws Exception { NetconfMonitoringService monitor = mock(NetconfMonitoringService.class); NetconfMonitoringOperationService service = new NetconfMonitoringOperationService(monitor); + NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory serviceFactory = new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(service); - assertEquals(1, service.getNetconfOperations().size()); + assertEquals(2, service.getNetconfOperations().size()); - assertEquals(Optional.absent(), service.getCapabilities().iterator().next().getCapabilitySchema()); - assertEquals(Collections.emptyList(), service.getCapabilities().iterator().next().getLocation()); - assertEquals(Optional.of(MonitoringConstants.MODULE_REVISION), service.getCapabilities().iterator().next().getRevision()); - assertEquals(Optional.of(MonitoringConstants.MODULE_NAME), service.getCapabilities().iterator().next().getModuleName()); - assertEquals(Optional.of(MonitoringConstants.NAMESPACE), service.getCapabilities().iterator().next().getModuleNamespace()); - assertEquals(MonitoringConstants.URI, service.getCapabilities().iterator().next().getCapabilityUri()); } } diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java index 4b5dcd7d55..a8236b2ebc 100644 --- a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java @@ -11,9 +11,13 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import com.google.common.base.Optional; import com.google.common.collect.Lists; +import java.util.Set; import org.hamcrest.CoreMatchers; import org.junit.Test; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.monitoring.xml.model.NetconfState; import org.opendaylight.controller.netconf.util.xml.XmlUtil; @@ -25,6 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfSsh; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Transport; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; @@ -42,6 +47,26 @@ public class JaxBSerializerTest { final NetconfMonitoringService service = new NetconfMonitoringService() { + @Override + public void onSessionUp(final NetconfManagementSession session) { + + } + + @Override + public void onSessionDown(final NetconfManagementSession session) { + + } + + @Override + public void onCapabilitiesAdded(final Set addedCaps) { + + } + + @Override + public void onCapabilitiesRemoved(final Set addedCaps) { + + } + @Override public Sessions getSessions() { return new SessionsBuilder().setSession(Lists.newArrayList(getMockSession(NetconfTcp.class), getMockSession(NetconfSsh.class))).build(); @@ -51,6 +76,26 @@ public class JaxBSerializerTest { public Schemas getSchemas() { return new SchemasBuilder().setSchema(Lists.newArrayList(getMockSchema("id", "v1", Yang.class), getMockSchema("id2", "", Yang.class))).build(); } + + @Override + public String getSchemaForCapability(final String moduleName, final Optional revision) { + return null; + } + + @Override + public Capabilities getCapabilities() { + return null; + } + + @Override + public AutoCloseable registerListener(final MonitoringListener listener) { + return new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + } }; final NetconfState model = new NetconfState(service); final String xml = XmlUtil.toString(new JaxBSerializer().toXml(model)).replaceAll("\\s", ""); diff --git a/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java b/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java index 9eab5caff7..a0a0dfcb8f 100644 --- a/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java +++ b/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java @@ -15,8 +15,9 @@ import java.util.Collections; import java.util.Dictionary; import java.util.Hashtable; import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.api.util.NetconfConstants; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; @@ -42,16 +43,30 @@ public class Activator implements BundleActivator { final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() { + private final Set capabilities = Collections.singleton(new NotificationsCapability()); + + @Override + public Set getCapabilities() { + return capabilities; + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(capabilities); + return new AutoCloseable() { + @Override + public void close() { + listener.onCapabilitiesRemoved(capabilities); + } + }; + } + @Override public NetconfOperationService createService(final String netconfSessionIdForReporting) { return new NetconfOperationService() { private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager); - @Override - public Set getCapabilities() { - return Collections.singleton(new NotificationsCapability()); - } @Override public Set getNetconfOperations() { @@ -68,7 +83,7 @@ public class Activator implements BundleActivator { } }; - Dictionary properties = new Hashtable<>(); + final Dictionary properties = new Hashtable<>(); properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING); operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties); diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/FakeModuleBuilderCapability.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/FakeModuleBuilderCapability.java index fcb513f016..3aba6f81a3 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/FakeModuleBuilderCapability.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/FakeModuleBuilderCapability.java @@ -12,8 +12,8 @@ import com.google.common.base.Optional; import java.util.Collections; import java.util.Date; import java.util.List; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.confignetconfconnector.util.Util; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/ModuleBuilderCapability.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/ModuleBuilderCapability.java index 68f8796d81..11af568321 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/ModuleBuilderCapability.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/ModuleBuilderCapability.java @@ -12,8 +12,8 @@ import com.google.common.base.Optional; import java.util.Collections; import java.util.Date; import java.util.List; +import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.confignetconfconnector.util.Util; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java index 30b3076589..bb67af2032 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java @@ -55,19 +55,20 @@ import org.apache.sshd.common.util.ThreadUtils; import org.apache.sshd.server.PasswordAuthenticator; import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider; import org.apache.sshd.server.session.ServerSession; -import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator; import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; import org.opendaylight.controller.netconf.ssh.SshProxyServer; import org.opendaylight.controller.netconf.ssh.SshProxyServerConfiguration; @@ -141,9 +142,15 @@ public class NetconfDeviceSimulator implements Closeable { final SessionIdProvider idProvider = new SessionIdProvider(); + + final AggregatedNetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = new AggregatedNetconfOperationServiceFactory(); final SimulatedOperationProvider simulatedOperationProvider = new SimulatedOperationProvider(idProvider, capabilities, notificationsFile); - final NetconfMonitoringOperationService monitoringService = new NetconfMonitoringOperationService(new NetconfMonitoringServiceImpl(simulatedOperationProvider)); - simulatedOperationProvider.addService(monitoringService); + + final NetconfMonitoringService monitoringService1 = new NetconfMonitoringServiceImpl(aggregatedNetconfOperationServiceFactory); + final NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory monitoringService = + new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(new NetconfMonitoringOperationService(monitoringService1)); + aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(simulatedOperationProvider); + aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(monitoringService); final DefaultCommitNotificationProducer commitNotifier = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); @@ -152,7 +159,7 @@ public class NetconfDeviceSimulator implements Closeable { : Sets.newHashSet(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0, XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1); final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( - hashedWheelTimer, simulatedOperationProvider, idProvider, generateConfigsTimeout, commitNotifier, new LoggingMonitoringService(), serverCapabilities); + hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider, generateConfigsTimeout, commitNotifier, monitoringService1, serverCapabilities); final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory); @@ -396,65 +403,43 @@ public class NetconfDeviceSimulator implements Closeable { // close Everything } - private static class SimulatedOperationProvider implements NetconfOperationProvider { - private final SessionIdProvider idProvider; - private final Set netconfOperationServices; + private static class SimulatedOperationProvider implements NetconfOperationServiceFactory { + private final Set caps; + private final SimulatedOperationService simulatedOperationService; public SimulatedOperationProvider(final SessionIdProvider idProvider, final Set caps, final Optional notificationsFile) { - this.idProvider = idProvider; - final SimulatedOperationService simulatedOperationService = new SimulatedOperationService(caps, idProvider.getCurrentSessionId(), notificationsFile); - this.netconfOperationServices = Sets.newHashSet(simulatedOperationService); + this.caps = caps; + simulatedOperationService = new SimulatedOperationService(idProvider.getCurrentSessionId(), notificationsFile); } @Override - public NetconfOperationServiceSnapshot openSnapshot(final String sessionIdForReporting) { - return new SimulatedServiceSnapshot(idProvider, netconfOperationServices); + public Set getCapabilities() { + return caps; } - public void addService(final NetconfOperationService monitoringService) { - netconfOperationServices.add(monitoringService); + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + return new AutoCloseable() { + @Override + public void close() throws Exception {} + }; } - private static class SimulatedServiceSnapshot implements NetconfOperationServiceSnapshot { - private final SessionIdProvider idProvider; - private final Set netconfOperationServices; - - public SimulatedServiceSnapshot(final SessionIdProvider idProvider, final Set netconfOperationServices) { - this.idProvider = idProvider; - this.netconfOperationServices = netconfOperationServices; - } - - @Override - public String getNetconfSessionIdForReporting() { - return String.valueOf(idProvider.getCurrentSessionId()); - } - - @Override - public Set getServices() { - return netconfOperationServices; - } - - @Override - public void close() throws Exception {} + @Override + public NetconfOperationService createService(final String netconfSessionIdForReporting) { + return simulatedOperationService; } static class SimulatedOperationService implements NetconfOperationService { - private final Set capabilities; private final long currentSessionId; private final Optional notificationsFile; - public SimulatedOperationService(final Set capabilities, final long currentSessionId, final Optional notificationsFile) { - this.capabilities = capabilities; + public SimulatedOperationService(final long currentSessionId, final Optional notificationsFile) { this.currentSessionId = currentSessionId; this.notificationsFile = notificationsFile; } - @Override - public Set getCapabilities() { - return capabilities; - } - @Override public Set getNetconfOperations() { final DataList storage = new DataList(); @@ -475,16 +460,4 @@ public class NetconfDeviceSimulator implements Closeable { } } - private class LoggingMonitoringService implements SessionMonitoringService { - @Override - public void onSessionUp(final NetconfManagementSession session) { - LOG.debug("Session {} established", session); - } - - @Override - public void onSessionDown(final NetconfManagementSession session) { - LOG.debug("Session {} down", session); - } - } - } diff --git a/opendaylight/netconf/pom.xml b/opendaylight/netconf/pom.xml index 4566845e4f..a990b5c6cb 100644 --- a/opendaylight/netconf/pom.xml +++ b/opendaylight/netconf/pom.xml @@ -21,6 +21,7 @@ netconf-impl config-netconf-connector mdsal-netconf-connector + mdsal-netconf-monitoring netconf-util netconf-netty-util config-persister-impl