Introduce remaining 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 / AbstractDOMRpcAction.java
1 /*
2  * Copyright (c) 2022 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.mdsal.dom.api.DOMRpcResult;
14
15 public abstract class AbstractDOMRpcAction implements Action {
16     @Override
17     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
18     public final Object execute() throws InterruptedException, ExecutionException {
19         final DOMRpcResult result = invokeRpc().get();
20         if (!result.getErrors().isEmpty()) {
21             // FIXME: is there a better way to report errors?
22             System.out.println("Invocation failed: " + result.getErrors());
23             return null;
24         } else {
25             return result.getResult().prettyTree().get();
26         }
27     }
28
29     protected abstract ListenableFuture<? extends DOMRpcResult> invokeRpc();
30 }