0a85b562eb2cef8720c4177da7f974034dec0794
[controller.git] / opendaylight / md-sal / sal-cluster-admin-karaf-cli / src / main / java / org / opendaylight / controller / cluster / datastore / admin / command / 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.controller.cluster.datastore.admin.command;
9
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.ExecutionException;
13 import org.apache.karaf.shell.api.action.Action;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15
16
17 /**
18  * Common base class for all commands which end up invoking an RPC.
19  */
20 public abstract class AbstractRpcAction implements Action {
21     @Override
22     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
23     public final Object execute() throws InterruptedException, ExecutionException {
24         final RpcResult<?> result = invokeRpc().get();
25         if (!result.isSuccessful()) {
26             // FIXME: is there a better way to report errors?
27             System.out.println("Invocation failed: " + result.getErrors());
28         }
29         return null;
30     }
31
32     protected abstract ListenableFuture<? extends RpcResult<?>> invokeRpc();
33 }