Introduce cli commands for clustering-test-app
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / karaf-cli / src / main / java / org / opendaylight / clustering / it / karaf / cli / AbstractRpcAction.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.clustering.it.karaf.cli;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.concurrent.ExecutionException;
12 import org.apache.karaf.shell.api.action.Action;
13 import org.opendaylight.yangtools.yang.common.RpcResult;
14
15 /**
16  * Common base class for all commands which end up invoking an RPC.
17  */
18 public abstract class AbstractRpcAction implements Action {
19     @Override
20     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
21     public final Object execute() throws InterruptedException, ExecutionException {
22         final RpcResult<?> result = invokeRpc().get();
23         if (!result.isSuccessful()) {
24             // FIXME: is there a better way to report errors?
25             System.out.println("Invocation failed: " + result.getErrors());
26         }
27         return null;
28     }
29
30     protected abstract ListenableFuture<? extends RpcResult<?>> invokeRpc();
31 }