From e64a4f7e0af0f6069658b5c2063fa7e79cb45c30 Mon Sep 17 00:00:00 2001 From: Rashmi Pujar Date: Wed, 29 Jun 2016 16:08:52 -0400 Subject: [PATCH] Add CLI bundle to the startup archetype Change-Id: I19ef17236a25cc84a9ff4b94a990d324386d9b19 Signed-off-by: Rashmi Pujar --- .../META-INF/maven/archetype-metadata.xml | 20 +++++++ .../resources/archetype-resources/cli/pom.xml | 48 ++++++++++++++++ .../cli/api/__classPrefix__CliCommands.java | 20 +++++++ .../__classPrefix__CliTestCommand.java | 56 +++++++++++++++++++ .../impl/__classPrefix__CliCommandsImpl.java | 32 +++++++++++ .../opendaylight/blueprint/cli-blueprint.xml | 34 +++++++++++ .../archetype-resources/features/pom.xml | 5 ++ .../features/src/main/features/features.xml | 4 ++ .../resources/archetype-resources/pom.xml | 1 + 9 files changed, 220 insertions(+) create mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/pom.xml create mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/api/__classPrefix__CliCommands.java create mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/commands/__classPrefix__CliTestCommand.java create mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/impl/__classPrefix__CliCommandsImpl.java create mode 100644 opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/resources/org/opendaylight/blueprint/cli-blueprint.xml 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 fbd25508d4..2597e7e242 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 @@ -111,6 +111,26 @@ + + + cli + + pom.xml + + + + cli/src/main/java + + **/*.java + + + + cli/src/main/resources/org/opendaylight/blueprint + + **/*.xml + + + it diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/pom.xml new file mode 100644 index 0000000000..f87c9759e3 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/pom.xml @@ -0,0 +1,48 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + 4.0.0 + + + org.opendaylight.controller + config-parent + 0.5.0-SNAPSHOT + + + + ${groupId} + ${artifactId}-cli + ${version} + bundle + + + + + ${symbol_dollar}{project.groupId} + ${artifactId}-api + ${symbol_dollar}{project.version} + + + + + org.apache.karaf.shell + org.apache.karaf.shell.console + ${karaf.version} + + + org.apache.karaf.shell + org.apache.karaf.shell.table + ${karaf.version} + + + diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/api/__classPrefix__CliCommands.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/api/__classPrefix__CliCommands.java new file mode 100644 index 0000000000..b1ec6cea1e --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/api/__classPrefix__CliCommands.java @@ -0,0 +1,20 @@ +#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 ${package}.cli.api; + +public interface ${classPrefix}CliCommands { + + /** + * Define the Karaf command method signatures and the Javadoc for each. + * Below method is just an example + */ + Object testCommand(Object testArgument); +} diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/commands/__classPrefix__CliTestCommand.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/commands/__classPrefix__CliTestCommand.java new file mode 100644 index 0000000000..65ec5f750d --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/commands/__classPrefix__CliTestCommand.java @@ -0,0 +1,56 @@ +#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 ${package}.cli.commands; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.shell.console.AbstractAction; +import ${package}.cli.api.${classPrefix}CliCommands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is an example class. The class name can be renamed to match the command implementation that it will invoke. + * Specify command details by updating the fields in the Command annotation below. + */ +@Command(name = "test-command", scope = "add the scope of the command, usually project name", description = "add a description for the command") +public class ${classPrefix}CliTestCommand extends AbstractAction { + + private static final Logger LOG = LoggerFactory.getLogger(${classPrefix}CliTestCommand.class); + protected final ${classPrefix}CliCommands service; + + public ${classPrefix}CliTestCommand(final ${classPrefix}CliCommands service) { + this.service = service; + } + + /** + * Add the arguments required by the command. + * Any number of arguments can be added using the Option annotation + * The below argument is just an example and should be changed as per your requirements + */ + @Option(name = "-tA", + aliases = { "--testArgument" }, + description = "test command argument", + required = true, + multiValued = false) + private Object testArgument; + + @Override + protected Object doExecute() throws Exception { + /** + * Invoke commannd implementation here using the service instance. + * Implement how you want the output of the command to be displayed. + * Below is just an example. + */ + final String testMessage = (String) service.testCommand(testArgument); + return testMessage; + } +} \ No newline at end of file diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/impl/__classPrefix__CliCommandsImpl.java b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/impl/__classPrefix__CliCommandsImpl.java new file mode 100644 index 0000000000..62ca5aa2ac --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/java/__packageInPathFormat__/cli/impl/__classPrefix__CliCommandsImpl.java @@ -0,0 +1,32 @@ +#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 ${package}.cli.impl; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ${package}.cli.api.${classPrefix}CliCommands; + +public class ${classPrefix}CliCommandsImpl implements ${classPrefix}CliCommands { + + private static final Logger LOG = LoggerFactory.getLogger(${classPrefix}CliCommandsImpl.class); + private final DataBroker dataBroker; + + public ${classPrefix}CliCommandsImpl(final DataBroker db) { + this.dataBroker = db; + LOG.info("${classPrefix}CliCommandImpl initialized"); + } + + @Override + public Object testCommand(Object testArgument) { + return "This is a test implementation of test-command"; + } +} \ No newline at end of file diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/resources/org/opendaylight/blueprint/cli-blueprint.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/resources/org/opendaylight/blueprint/cli-blueprint.xml new file mode 100644 index 0000000000..5c3bd4d43f --- /dev/null +++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/cli/src/main/resources/org/opendaylight/blueprint/cli-blueprint.xml @@ -0,0 +1,34 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + 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 1ca2c6d2c8..d8a96ea935 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 @@ -112,5 +112,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL ${artifactId}-api ${symbol_dollar}{project.version} + + ${symbol_dollar}{project.groupId} + ${artifactId}-cli + ${symbol_dollar}{project.version} + 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 9c3555ef26..fb33ff8447 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 @@ -37,5 +37,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html odl-mdsal-xsql odl-dlux-yangui + + odl-${artifactId} + mvn:${groupId}/${artifactId}-cli/{{VERSION}} + 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 41822baef4..07701297f2 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 @@ -38,6 +38,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL karaf features artifacts + cli it -- 2.36.6