From eeb141311649875c03b5b10ce3a1f3ca3a2b3dcd Mon Sep 17 00:00:00 2001 From: Lorand Jakab Date: Wed, 1 Apr 2015 17:07:33 +0300 Subject: [PATCH] Add support for Karaf shell lisp:* commands This commit adds the necessary infrastructure to add Karaf shell commands for the lispflowmapping project and adds the first command: "lisp:mappings", based on the previos OSGi shell command "dumpAll". The list of implemented commands and a short help can be consulted at any time with "help lisp". Change-Id: Iee6f430053c52dc4933ce920859ce03523dd05e2 Signed-off-by: Lorand Jakab --- artifacts/pom.xml | 5 +++ commons/parent/pom.xml | 5 +++ features/pom.xml | 4 ++ features/src/main/resources/features.xml | 1 + .../interfaces/lisp/IFlowMappingShell.java | 24 +++++++++++ .../implementation/Activator.java | 21 +++++----- .../implementation/LispMappingService.java | 19 +++++---- mappingservice/pom.xml | 1 + mappingservice/shell/pom.xml | 40 +++++++++++++++++++ .../lispflowmapping/shell/LispMappings.java | 28 +++++++++++++ .../OSGI-INF/blueprint/blueprint.xml | 10 +++++ 11 files changed, 141 insertions(+), 17 deletions(-) create mode 100644 mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IFlowMappingShell.java create mode 100644 mappingservice/shell/pom.xml create mode 100644 mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispMappings.java create mode 100644 mappingservice/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml diff --git a/artifacts/pom.xml b/artifacts/pom.xml index 8136fb94a..fb8753a79 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -51,6 +51,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html mappingservice.northbound ${project.version} + + ${project.groupId} + mappingservice.shell + ${project.version} + ${project.groupId} mappingservice.southbound diff --git a/commons/parent/pom.xml b/commons/parent/pom.xml index 3d850aa3e..3074cef9f 100644 --- a/commons/parent/pom.xml +++ b/commons/parent/pom.xml @@ -278,6 +278,11 @@ mappingservice.northbound ${lispflowmapping.version} + + org.opendaylight.lispflowmapping + mappingservice.shell + ${lispflowmapping.version} + org.opendaylight.lispflowmapping mappingservice.southbound diff --git a/features/pom.xml b/features/pom.xml index 324ca1170..4cd4bc037 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -85,6 +85,10 @@ org.opendaylight.lispflowmapping mappingservice.northbound + + org.opendaylight.lispflowmapping + mappingservice.shell + org.opendaylight.lispflowmapping diff --git a/features/src/main/resources/features.xml b/features/src/main/resources/features.xml index e9d624ec1..e44c1b2bc 100644 --- a/features/src/main/resources/features.xml +++ b/features/src/main/resources/features.xml @@ -33,6 +33,7 @@ mvn:org.opendaylight.lispflowmapping/mappingservice.yangmodel/${lispflowmapping.version} mvn:org.opendaylight.lispflowmapping/mappingservice.api/${lispflowmapping.version} mvn:org.opendaylight.lispflowmapping/mappingservice.implementation/${lispflowmapping.version} + mvn:org.opendaylight.lispflowmapping/mappingservice.shell/${lispflowmapping.version} mvn:org.opendaylight.lispflowmapping/mappingservice.clusterdao/${lispflowmapping.version} diff --git a/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IFlowMappingShell.java b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IFlowMappingShell.java new file mode 100644 index 000000000..95a9722c1 --- /dev/null +++ b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IFlowMappingShell.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. 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.lispflowmapping.interfaces.lisp; + +/** + * This interface defines the methods that need to be implemented in order to + * provide commands for the Karaf shell. + * + * @author Lorand Jakab + * + */ +public interface IFlowMappingShell { + /** + * Print the full mapping database. + * + * @return the text to be printed on the Karaf console. + */ + public String printMappings(); +} diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/Activator.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/Activator.java index 6984528cc..c487176ed 100644 --- a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/Activator.java +++ b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/Activator.java @@ -16,11 +16,12 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO; import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping; +import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMappingShell; /** * Main application activator class for registering the dependencies and * initialising the Mapping Service application. - * + * */ public class Activator extends ComponentActivatorAbstractBase { @@ -28,7 +29,7 @@ public class Activator extends ComponentActivatorAbstractBase { /** * Function called when the activator starts just after some initializations * are done by the ComponentActivatorAbstractBase. - * + * */ @Override public void init() { @@ -37,7 +38,7 @@ public class Activator extends ComponentActivatorAbstractBase { /** * Function called when the activator stops just before the cleanup done by * ComponentActivatorAbstractBase - * + * */ @Override public void destroy() { @@ -46,8 +47,8 @@ public class Activator extends ComponentActivatorAbstractBase { /** * Function that is used to communicate to dependency manager the list of * known implementations for services inside a container - * - * + * + * * @return An array containing all the CLASS objects that will be * instantiated in order to get an fully working implementation * Object @@ -61,7 +62,7 @@ public class Activator extends ComponentActivatorAbstractBase { /** * Function that is called when configuration of the dependencies is * required. - * + * * @param c * dependency manager Component object, used for configuring the * dependencies exported and imported @@ -79,7 +80,7 @@ public class Activator extends ComponentActivatorAbstractBase { // export the service Dictionary props = new Hashtable(); props.put("name", "mappingservice"); - c.setInterface(new String[] { IFlowMapping.class.getName() }, props); + c.setInterface(new String[] { IFlowMapping.class.getName(), IFlowMappingShell.class.getName() }, props); c.add(createContainerServiceDependency(containerName).setService(ILispDAO.class).setCallbacks("setLispDao", "unsetLispDao") .setRequired(true)); c.add(createServiceDependency().setService(BindingAwareBroker.class).setRequired(true) @@ -94,8 +95,8 @@ public class Activator extends ComponentActivatorAbstractBase { * destroyed only at time of bundle destruction, this is the major * difference with the implementation retrieved via getImplementations where * all of them are assumed to be in a container ! - * - * + * + * * @return The list of implementations the bundle will support, in Global * version */ @@ -106,7 +107,7 @@ public class Activator extends ComponentActivatorAbstractBase { /** * Configure the dependency for a given instance Global - * + * * @param c * Component assigned for this instance, this will be what will * be used for configuration diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java index 049ab2c3a..703db250b 100644 --- a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java +++ b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java @@ -30,6 +30,7 @@ import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO; import org.opendaylight.lispflowmapping.interfaces.dao.ILispTypeConverter; import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor; import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping; +import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMappingShell; import org.opendaylight.lispflowmapping.interfaces.lisp.IMapNotifyHandler; import org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler; import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync; @@ -62,7 +63,7 @@ import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class LispMappingService implements CommandProvider, IFlowMapping, BindingAwareConsumer, // +public class LispMappingService implements CommandProvider, IFlowMapping, IFlowMappingShell, BindingAwareConsumer, IMapRequestResultHandler, IMapNotifyHandler { protected static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class); @@ -149,22 +150,26 @@ public class LispMappingService implements CommandProvider, IFlowMapping, Bindin } public void _dumpAll(final CommandInterpreter ci) { - ci.println("EID\tRLOCs"); + ci.print(printMappings()); + } + + public String printMappings() { + final StringBuffer sb = new StringBuffer(); + sb.append("EID\tRLOCs\n"); lispDao.getAll(new IRowVisitor() { String lastKey = ""; public void visitRow(Object keyId, String valueKey, Object value) { String key = keyId.getClass().getSimpleName() + "#" + keyId; if (!lastKey.equals(key)) { - ci.println(); - ci.print(key + "\t"); + sb.append("\n" + key + "\t"); } - ci.print(valueKey + "=" + value + "\t"); + sb.append(valueKey + "=" + value + "\t"); lastKey = key; } }); - ci.println(); - return; + sb.append("\n"); + return sb.toString(); } public void _setShouldOverwriteRlocs(final CommandInterpreter ci) { diff --git a/mappingservice/pom.xml b/mappingservice/pom.xml index 5eb7bad6e..a894c8e71 100644 --- a/mappingservice/pom.xml +++ b/mappingservice/pom.xml @@ -20,6 +20,7 @@ northbound neutron netconf + shell integrationtest diff --git a/mappingservice/shell/pom.xml b/mappingservice/shell/pom.xml new file mode 100644 index 000000000..8ab991471 --- /dev/null +++ b/mappingservice/shell/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + org.opendaylight.lispflowmapping + mappingservice-parent + 1.2.0-SNAPSHOT + + mappingservice.shell + bundle + LISP Flow Mapping Karaf Shell Commands + + + org.apache.karaf.shell + org.apache.karaf.shell.commands + ${karaf.version} + + + org.opendaylight.lispflowmapping + mappingservice.api + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.felix.service.command, + org.apache.karaf.shell.commands, + org.apache.karaf.shell.console, + org.opendaylight.lispflowmapping.interfaces.lisp + + + + + + diff --git a/mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispMappings.java b/mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispMappings.java new file mode 100644 index 000000000..cd3999f95 --- /dev/null +++ b/mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispMappings.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. 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.lispflowmapping.shell; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMappingShell; + +@Command(scope = "lisp", name = "mappings", description="Print LISP mapping database") +public class LispMappings extends OsgiCommandSupport { + private IFlowMappingShell lispShellService; + + @Override + protected Object doExecute() throws Exception { + System.out.print(lispShellService.printMappings()); + return null; + } + + public void setLispShellService(IFlowMappingShell lispShellService) { + this.lispShellService = lispShellService; + } +} diff --git a/mappingservice/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/mappingservice/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 000000000..af66e7845 --- /dev/null +++ b/mappingservice/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,10 @@ + + + + + + + + + + -- 2.36.6