2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.serviceutils.srm.shell;
10 import java.util.concurrent.Future;
11 import org.apache.karaf.shell.api.action.Action;
12 import org.apache.karaf.shell.api.action.Argument;
13 import org.apache.karaf.shell.api.action.Command;
14 import org.apache.karaf.shell.api.action.lifecycle.Reference;
15 import org.apache.karaf.shell.api.action.lifecycle.Service;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.OdlSrmRpcsService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityNameBase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeBase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeService;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Implementation class of "srm:reinstall" Karaf shell command.
32 @Command(scope = "srm", name = "reinstall", description = "Reinstall service or instance")
33 public class ReinstallCommand implements Action {
34 private static final Logger LOG = LoggerFactory.getLogger(ReinstallCommand.class);
35 private static final EntityTypeBase ENTITY_TYPE = EntityTypeService.VALUE;
37 @Argument(index = 0, name = "name", description = "EntityName of type service, required",
38 required = false, multiValued = false)
41 private OdlSrmRpcsService srmRpcService;
44 public @Nullable Object execute() throws Exception {
45 ReinstallInput input = getInput();
46 if (input == null || srmRpcService == null) {
49 Future<RpcResult<ReinstallOutput>> result = srmRpcService.reinstall(input);
50 RpcResult<ReinstallOutput> reinstallResult = result.get();
51 printResult(reinstallResult);
55 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
56 private static void printResult(RpcResult<ReinstallOutput> reinstallResult) {
57 var sb = new StringBuilder("");
58 if (reinstallResult.isSuccessful()) {
59 sb.append("RPC call to reinstall was successful");
60 LOG.trace("RPC Result: {}", reinstallResult.getResult());
62 sb.append("RPC Call to reinstall failed.\n")
63 .append("ErrorMsg: ").append(reinstallResult.getResult().getMessage());
64 LOG.trace("RPC Result: {}", reinstallResult.getResult());
66 System.out.println(sb.toString());
69 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
70 private @Nullable ReinstallInput getInput() {
71 EntityNameBase entityName = SrmCliUtils.getEntityName(ENTITY_TYPE, name);
72 if (entityName == null) {
73 System.out.println(SrmCliUtils.getNameHelp(ENTITY_TYPE));
76 return new ReinstallInputBuilder()
77 .setEntityType(ENTITY_TYPE)
78 .setEntityName(entityName)