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