Add support for Karaf shell lisp:* commands 43/17543/1
authorLorand Jakab <lojakab@cisco.com>
Wed, 1 Apr 2015 14:07:33 +0000 (17:07 +0300)
committerLorand Jakab <lojakab@cisco.com>
Wed, 1 Apr 2015 14:10:21 +0000 (17:10 +0300)
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 <lojakab@cisco.com>
artifacts/pom.xml
commons/parent/pom.xml
features/pom.xml
features/src/main/resources/features.xml
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/lisp/IFlowMappingShell.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/Activator.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java
mappingservice/pom.xml
mappingservice/shell/pom.xml [new file with mode: 0644]
mappingservice/shell/src/main/java/org/opendaylight/lispflowmapping/shell/LispMappings.java [new file with mode: 0644]
mappingservice/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml [new file with mode: 0644]

index 8136fb94a49f3e208a7d566bfde88dd28f4b9ae3..fb8753a797158f15e80fa7093cbdf0297681d954 100644 (file)
@@ -51,6 +51,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <artifactId>mappingservice.northbound</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>${project.groupId}</groupId>
+        <artifactId>mappingservice.shell</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>${project.groupId}</groupId>
         <artifactId>mappingservice.southbound</artifactId>
index 3d850aa3e4c265270a633cd25caba948869a20b3..3074cef9fc764bf236d6025734ad1765ee3b6fa3 100644 (file)
         <artifactId>mappingservice.northbound</artifactId>
         <version>${lispflowmapping.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.lispflowmapping</groupId>
+        <artifactId>mappingservice.shell</artifactId>
+        <version>${lispflowmapping.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.opendaylight.lispflowmapping</groupId>
         <artifactId>mappingservice.southbound</artifactId>
index 324ca117090adffffdec7621d9f95e0337ad7cb6..4cd4bc037ac28a34cdeb6ff6b2eed0bc13780ca6 100644 (file)
       <groupId>org.opendaylight.lispflowmapping</groupId>
       <artifactId>mappingservice.northbound</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.lispflowmapping</groupId>
+      <artifactId>mappingservice.shell</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>org.opendaylight.lispflowmapping</groupId>
index e9d624ec1f85d809c83963d101dfd0fcc0005c14..e44c1b2bcbb0153aa17bea24b03ba646a6312a0d 100644 (file)
@@ -33,6 +33,7 @@
         <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.yangmodel/${lispflowmapping.version}</bundle>
         <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.api/${lispflowmapping.version}</bundle>
         <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.implementation/${lispflowmapping.version}</bundle>
+        <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.shell/${lispflowmapping.version}</bundle>
         <bundle>mvn:org.opendaylight.lispflowmapping/mappingservice.clusterdao/${lispflowmapping.version}</bundle>
     </feature>
 
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 (file)
index 0000000..95a9722
--- /dev/null
@@ -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();
+}
index 6984528cc2b573913655eb20b6a1c546ee593a78..c487176ed92e3c24e0d460fba58f24032016ad88 100644 (file)
@@ -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<String, String> props = new Hashtable<String, String>();
             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
index 049ab2c3a4b90d663bbd2244cf45abf463e26cdb..703db250be2932c99cdc156cc42cb1d9ce017e44 100644 (file)
@@ -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) {
index 5eb7bad6e238730e8bfd5168a38371f5bb531c2a..a894c8e715ae7f14080222b713691c712c2e00f1 100644 (file)
@@ -20,6 +20,7 @@
     <module>northbound</module>
     <module>neutron</module>
     <module>netconf</module>
+    <module>shell</module>
     <module>integrationtest</module>
   </modules>
   <dependencies>
diff --git a/mappingservice/shell/pom.xml b/mappingservice/shell/pom.xml
new file mode 100644 (file)
index 0000000..8ab9914
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.lispflowmapping</groupId>
+    <artifactId>mappingservice-parent</artifactId>
+    <version>1.2.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>mappingservice.shell</artifactId>
+  <packaging>bundle</packaging>
+  <name>LISP Flow Mapping Karaf Shell Commands</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.commands</artifactId>
+      <version>${karaf.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.lispflowmapping</groupId>
+      <artifactId>mappingservice.api</artifactId>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>org.apache.felix.service.command,
+              org.apache.karaf.shell.commands,
+              org.apache.karaf.shell.console,
+              org.opendaylight.lispflowmapping.interfaces.lisp</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
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 (file)
index 0000000..cd3999f
--- /dev/null
@@ -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 (file)
index 0000000..af66e78
--- /dev/null
@@ -0,0 +1,10 @@
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  <reference id="lispShellServiceRef" interface="org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMappingShell"/>
+  <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+    <command>
+      <action class="org.opendaylight.lispflowmapping.shell.LispMappings">
+        <property name="lispShellService" ref="lispShellServiceRef"/>
+      </action>
+    </command>
+  </command-bundle>
+</blueprint>