Eliminate blueprint from srm/shell
[serviceutils.git] / srm / shell / src / main / java / org / opendaylight / serviceutils / srm / shell / ReinstallCommand.java
index 500b6daad5e64b2c8dfd141dad6e3a82e883a726..a8280b82cc8ab4d60196e4b559585b75bd008349 100644 (file)
@@ -8,9 +8,11 @@
 package org.opendaylight.serviceutils.srm.shell;
 
 import java.util.concurrent.Future;
-import org.apache.karaf.shell.commands.Argument;
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.OdlSrmRpcsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
@@ -23,27 +25,25 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Implementation class of "srm:reinstall" Karaf shell command.
+ */
+@Service
 @Command(scope = "srm", name = "reinstall", description = "Reinstall service or instance")
-public class ReinstallCommand extends OsgiCommandSupport {
+public class ReinstallCommand implements Action {
     private static final Logger LOG = LoggerFactory.getLogger(ReinstallCommand.class);
+    private static final EntityTypeBase ENTITY_TYPE = EntityTypeService.VALUE;
 
     @Argument(index = 0, name = "name", description = "EntityName of type service, required",
         required = false, multiValued = false)
-    String name;
-
-    private final OdlSrmRpcsService srmRpcService;
-    private final EntityTypeBase entityType = EntityTypeService.VALUE;
-
-    public ReinstallCommand(OdlSrmRpcsService srmRpcService) {
-        this.srmRpcService = srmRpcService;
-    }
+    private String name;
+    @Reference
+    private OdlSrmRpcsService srmRpcService;
 
     @Override
-    @Deprecated
-    protected @Nullable Object doExecute() throws Exception {
+    public @Nullable Object execute() throws Exception {
         ReinstallInput input = getInput();
-        if (input == null) {
-            // We've already shown the relevant error msg
+        if (input == null || srmRpcService == null) {
             return null;
         }
         Future<RpcResult<ReinstallOutput>> result = srmRpcService.reinstall(input);
@@ -52,28 +52,30 @@ public class ReinstallCommand extends OsgiCommandSupport {
         return null;
     }
 
-    private void printResult(RpcResult<ReinstallOutput> reinstallResult) {
-        StringBuilder strResult = new StringBuilder("");
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
+    private static void printResult(RpcResult<ReinstallOutput> reinstallResult) {
+        var sb = new StringBuilder("");
         if (reinstallResult.isSuccessful()) {
-            strResult.append("RPC call to reinstall was successful");
+            sb.append("RPC call to reinstall was successful");
             LOG.trace("RPC Result: {}", reinstallResult.getResult());
         } else {
-            strResult.append("RPC Call to reinstall failed.\n")
+            sb.append("RPC Call to reinstall failed.\n")
                 .append("ErrorMsg: ").append(reinstallResult.getResult().getMessage());
             LOG.trace("RPC Result: {}", reinstallResult.getResult());
         }
-        session.getConsole().println(strResult.toString());
+        System.out.println(sb.toString());
     }
 
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
     private @Nullable ReinstallInput getInput() {
-        EntityNameBase entityName = SrmCliUtils.getEntityName(entityType, name);
+        EntityNameBase entityName = SrmCliUtils.getEntityName(ENTITY_TYPE, name);
         if (entityName == null) {
-            session.getConsole().println(SrmCliUtils.getNameHelp(entityType));
+            System.out.println(SrmCliUtils.getNameHelp(ENTITY_TYPE));
             return null;
         }
-        ReinstallInputBuilder inputBuilder = new ReinstallInputBuilder();
-        inputBuilder.setEntityType(entityType);
-        inputBuilder.setEntityName(entityName);
-        return inputBuilder.build();
+        return new ReinstallInputBuilder()
+            .setEntityType(ENTITY_TYPE)
+            .setEntityName(entityName)
+            .build();
     }
 }