X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=srm%2Fshell%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fserviceutils%2Fsrm%2Fshell%2FReinstallCommand.java;fp=srm%2Fshell%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fserviceutils%2Fsrm%2Fshell%2FReinstallCommand.java;h=a8280b82cc8ab4d60196e4b559585b75bd008349;hb=d6d06853f605111e34c567bd6b07d567ab979d9d;hp=500b6daad5e64b2c8dfd141dad6e3a82e883a726;hpb=7f68a435defbc7dd4f3a26df40ac20a726ad6ed2;p=serviceutils.git diff --git a/srm/shell/src/main/java/org/opendaylight/serviceutils/srm/shell/ReinstallCommand.java b/srm/shell/src/main/java/org/opendaylight/serviceutils/srm/shell/ReinstallCommand.java index 500b6daa..a8280b82 100644 --- a/srm/shell/src/main/java/org/opendaylight/serviceutils/srm/shell/ReinstallCommand.java +++ b/srm/shell/src/main/java/org/opendaylight/serviceutils/srm/shell/ReinstallCommand.java @@ -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> result = srmRpcService.reinstall(input); @@ -52,28 +52,30 @@ public class ReinstallCommand extends OsgiCommandSupport { return null; } - private void printResult(RpcResult reinstallResult) { - StringBuilder strResult = new StringBuilder(""); + @SuppressWarnings("checkstyle:RegexpSinglelineJava") + private static void printResult(RpcResult 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(); } }