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;
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);
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();
}
}