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.commands.Argument;
12 import org.apache.karaf.shell.commands.Command;
13 import org.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.OdlSrmRpcsService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityNameBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeBase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeService;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 @Command(scope = "srm", name = "reinstall", description = "Reinstall service or instance")
27 public class ReinstallCommand extends OsgiCommandSupport {
28 private static final Logger LOG = LoggerFactory.getLogger(ReinstallCommand.class);
30 @Argument(index = 0, name = "name", description = "EntityName of type service, required",
31 required = false, multiValued = false)
34 private final OdlSrmRpcsService srmRpcService;
35 private final EntityTypeBase entityType = EntityTypeService.VALUE;
37 public ReinstallCommand(OdlSrmRpcsService srmRpcService) {
38 this.srmRpcService = srmRpcService;
43 protected @Nullable Object doExecute() throws Exception {
44 ReinstallInput input = getInput();
46 // We've already shown the relevant error msg
49 Future<RpcResult<ReinstallOutput>> result = srmRpcService.reinstall(input);
50 RpcResult<ReinstallOutput> reinstallResult = result.get();
51 printResult(reinstallResult);
55 private void printResult(RpcResult<ReinstallOutput> reinstallResult) {
56 StringBuilder strResult = new StringBuilder("");
57 if (reinstallResult.isSuccessful()) {
58 strResult.append("RPC call to reinstall was successful");
59 LOG.trace("RPC Result: {}", reinstallResult.getResult());
61 strResult.append("RPC Call to reinstall failed.\n")
62 .append("ErrorMsg: ").append(reinstallResult.getResult().getMessage());
63 LOG.trace("RPC Result: {}", reinstallResult.getResult());
65 session.getConsole().println(strResult.toString());
68 private @Nullable ReinstallInput getInput() {
69 EntityNameBase entityName = SrmCliUtils.getEntityName(entityType, name);
70 if (entityName == null) {
71 session.getConsole().println(SrmCliUtils.getNameHelp(entityType));
74 ReinstallInputBuilder inputBuilder = new ReinstallInputBuilder();
75 inputBuilder.setEntityType(entityType);
76 inputBuilder.setEntityName(entityName);
77 return inputBuilder.build();