From 3988eb2044c1e30371b2a8e02f15a90649d31a84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Thu, 30 Jun 2016 14:29:51 -0400 Subject: [PATCH 1/1] Add blueprint wiring to opendaylight-archetype MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I0b219e8da4a1e58d6254c1dff993e8719aa14fd5 Signed-off-by: Alexis de Talhouët --- .../META-INF/maven/archetype-metadata.xml | 8 +-- .../archetype-resources/features/pom.xml | 7 --- .../features/src/main/features/features.xml | 1 - .../impl/src/main/config/default-config.xml | 33 ----------- .../impl/__classPrefix__Provider.java | 26 ++++++--- .../impl/rev141210/__classPrefix__Module.java | 40 ------------- .../__classPrefix__ModuleFactory.java | 15 ----- .../opendaylight/blueprint/impl-blueprint.xml | 27 +++++++++ .../src/main/yang/__artifactId__-impl.yang | 35 ----------- .../__classPrefix__ModuleFactoryTest.java | 22 ------- .../rev141210/__classPrefix__ModuleTest.java | 58 ------------------- 11 files changed, 45 insertions(+), 227 deletions(-) delete mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml delete mode 100644 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 delete mode 100644 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 create mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml delete mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang delete mode 100644 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 delete mode 100644 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 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 753f70f02a..fbd25508d4 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 @@ -82,17 +82,11 @@ - impl/src/main/config + impl/src/main/resources/org/opendaylight/blueprint **/*.xml - - impl/src/main/yang - - **/*.yang - - diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/pom.xml index 8ef2faeac4..1ca2c6d2c8 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/pom.xml +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/pom.xml @@ -107,13 +107,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL ${artifactId}-impl ${symbol_dollar}{project.version} - - ${symbol_dollar}{project.groupId} - ${artifactId}-impl - ${symbol_dollar}{project.version} - xml - config - ${symbol_dollar}{project.groupId} ${artifactId}-api diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/src/main/features/features.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/src/main/features/features.xml index 42d88b7420..9c3555ef26 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/src/main/features/features.xml +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/features/src/main/features/features.xml @@ -26,7 +26,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html odl-mdsal-broker odl-${artifactId}-api mvn:${groupId}/${artifactId}-impl/{{VERSION}} - mvn:${groupId}/${artifactId}-impl/{{VERSION}}/xml/config odl-${artifactId} diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml deleted file mode 100644 index 7f9dc7fa1a..0000000000 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/config/default-config.xml +++ /dev/null @@ -1,33 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - urn:opendaylight:params:xml:ns:yang:${artifactId}:impl?module=${artifactId}-impl&revision=2014-12-10 - urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 - - - - - - - prefix:${artifactId} - ${artifactId}-default - - binding:binding-broker-osgi-registry - binding-osgi-broker - - - - - - diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/__packageInPathFormat__/impl/__classPrefix__Provider.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/__packageInPathFormat__/impl/__classPrefix__Provider.java index c2c8f0d37b..4d0a820418 100644 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/__packageInPathFormat__/impl/__classPrefix__Provider.java +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/java/__packageInPathFormat__/impl/__classPrefix__Provider.java @@ -10,23 +10,31 @@ */ package ${package}.impl; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ${classPrefix}Provider implements BindingAwareProvider, AutoCloseable { +public class ${classPrefix}Provider { private static final Logger LOG = LoggerFactory.getLogger(${classPrefix}Provider.class); - @Override - public void onSessionInitiated(ProviderContext session) { + private final DataBroker dataBroker; + + public ${classPrefix}Provider(final DataBroker dataBroker) { + this.dataBroker = dataBroker; + } + + /** + * Method called when the blueprint container is created. + */ + public void init() { LOG.info("${classPrefix}Provider Session Initiated"); } - @Override - public void close() throws Exception { + /** + * Method called when the blueprint container is destroyed. + */ + public void close() { LOG.info("${classPrefix}Provider Closed"); } - -} +} \ No newline at end of file diff --git a/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 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 deleted file mode 100644 index 694dcda3ef..0000000000 --- a/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 +++ /dev/null @@ -1,40 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/* - * Copyright © ${copyrightYear} ${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.opendaylight.controller.config.api.DependencyResolver; -import org.opendaylight.controller.config.api.ModuleIdentifier; -import ${package}.impl.${classPrefix}Provider; - -public class ${classPrefix}Module extends Abstract${classPrefix}Module { - - public ${classPrefix}Module(ModuleIdentifier identifier, DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public ${classPrefix}Module(ModuleIdentifier identifier, DependencyResolver dependencyResolver, ${classPrefix}Module oldModule, - AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - ${classPrefix}Provider provider = new ${classPrefix}Provider(); - getBrokerDependency().registerProvider(provider); - return provider; - } - -} diff --git a/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 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 deleted file mode 100644 index e10edd6040..0000000000 --- a/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 +++ /dev/null @@ -1,15 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/* - * Copyright © ${copyrightYear} ${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; - -public class ${classPrefix}ModuleFactory extends Abstract${classPrefix}ModuleFactory { - -} diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml new file mode 100644 index 0000000000..95682b5d28 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -0,0 +1,27 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang deleted file mode 100644 index 41a74b3f1a..0000000000 --- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/impl/src/main/yang/__artifactId__-impl.yang +++ /dev/null @@ -1,35 +0,0 @@ -module ${artifactId}-impl { - yang-version 1; - namespace "urn:opendaylight:params:xml:ns:yang:${artifactId}:impl"; - prefix "${artifactId}-impl"; - - import config { prefix config; revision-date 2013-04-05; } - import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;} - - description - "Service definition for ${artifactId} project"; - - revision "2014-12-10" { - description - "Initial revision"; - } - - identity ${artifactId} { - base config:module-type; - config:java-name-prefix ${classPrefix}; - } - - augment "/config:modules/config:module/config:configuration" { - case ${artifactId} { - when "/config:modules/config:module/config:type = '${artifactId}'"; - container broker { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity md-sal-binding:binding-broker-osgi-registry; - } - } - } - } - } -} 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 deleted file mode 100644 index 40cfc63a23..0000000000 --- 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 +++ /dev/null @@ -1,22 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -#set( $factory = "${classPrefix}ModuleFactory" ) -/* - * Copyright © ${copyrightYear} ${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 deleted file mode 100644 index 6dc299cc2d..0000000000 --- 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 +++ /dev/null @@ -1,58 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -#set( $module = "${classPrefix}Module" ) -/* - * Copyright © ${copyrightYear} ${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}.impl.${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(); - } -} -- 2.36.6