Migrate reconciliation-framework CLI 40/104240/15
authorSangwook Ha <sangwook.ha@verizon.com>
Sat, 24 Jun 2023 01:28:12 +0000 (01:28 +0000)
committerRobert Varga <nite@hq.sk>
Thu, 8 Feb 2024 15:55:05 +0000 (15:55 +0000)
Karaf provides a more modern way of integrating CLI commands, use that
instead of Blueprint.

Change-Id: Ib063bd2a8639c1e0bf872152645fabb45f7631be
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
applications/reconciliation-framework/pom.xml
applications/reconciliation-framework/src/main/java/org/opendaylight/openflowplugin/applications/reconciliation/cli/GetRegisteredServices.java
applications/reconciliation-framework/src/main/resources/OSGI-INF/blueprint/commands.xml [deleted file]

index f19e18fb4d36063e038c2be7daf08453a1711391..fa8b81ba84b03be1d5fdb1321dcdae6668f8fb90 100644 (file)
             <artifactId>jakarta.annotation-api</artifactId>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.openflowplugin</groupId>
             <artifactId>openflowplugin-api</artifactId>
             <artifactId>org.osgi.service.component.annotations</artifactId>
         </dependency>
 
-        <!-- FIXME: migrate commands and clean up these two dependencies -->
-        <dependency>
-            <groupId>org.apache.karaf.shell</groupId>
-            <artifactId>org.apache.karaf.shell.console</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.framework</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-binding-test-utils</artifactId>
         </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Private-Package>org.opendaylight.openflowplugin.applications.reconciliation.impl</Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.karaf.tooling</groupId>
+                <artifactId>karaf-services-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
     <scm>
         <connection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</connection>
         <developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</developerConnection>
index a43743f3211fc7201f84cce9458a076d0b09d5ac..0a78db3c2c7fa344241caf7954a6153bfebc5f19 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.openflowplugin.applications.reconciliation.cli;
 
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.openflowplugin.applications.reconciliation.ReconciliationManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -18,24 +19,25 @@ import org.slf4j.LoggerFactory;
  * CLI to display the service priority, service name and service status
  * FIXME: service status
  */
+@Service
 @Command(scope = "reconciliation", name = "getRegisteredServices",
-    description = "displaying services registered to Reconciliation Framework")
-public class GetRegisteredServices extends OsgiCommandSupport {
+         description = "displaying services registered to Reconciliation Framework")
+public class GetRegisteredServices implements Action {
     private static final Logger LOG = LoggerFactory.getLogger(GetRegisteredServices.class);
-    private static final String CLI_FORMAT = "%d %-20s ";
 
     @Reference
-    ReconciliationManager reconciliationManager;
+    private ReconciliationManager reconciliationManager;
 
     @Override
-    protected Object doExecute() {
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
+    public Object execute() {
         LOG.debug("Executing getRegisteredServices to Reconciliation Framework command");
         if (reconciliationManager.getRegisteredServices().isEmpty()) {
-            session.getConsole().println("No Services have registered to Reconciliation Framework");
+            System.out.println("No Services have registered to Reconciliation Framework");
         } else {
-            for (var services : reconciliationManager.getRegisteredServices() .values()) {
+            for (var services : reconciliationManager.getRegisteredServices().values()) {
                 for (var service : services) {
-                    session.getConsole().println(String.format(CLI_FORMAT, service.getPriority(), service.getName()));
+                    System.out.println(String.format("%d %-20s ", service.getPriority(), service.getName()));
                 }
             }
         }
diff --git a/applications/reconciliation-framework/src/main/resources/OSGI-INF/blueprint/commands.xml b/applications/reconciliation-framework/src/main/resources/OSGI-INF/blueprint/commands.xml
deleted file mode 100644 (file)
index 0920964..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
-        <command>
-            <action class="org.opendaylight.openflowplugin.applications.reconciliation.cli.GetRegisteredServices"/>
-        </command>
-    </command-bundle>
-</blueprint>