Inline checkedGet() 92/107892/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 16 Sep 2023 11:36:31 +0000 (13:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 16 Sep 2023 11:59:59 +0000 (13:59 +0200)
This method has only a single caller which we want to evolve further.
Inline it into invokeAction().

JIRA: NETCONF-718
Change-Id: I0c017955ab51ddebf54c8bd6a46495f434fe55b3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java

index d315c54ca5ed72d3bdf65c9b8078c06f7d12f907..7e7244ea6f97067303d55efc981cf0cb7f0ca56e 100644 (file)
@@ -16,6 +16,7 @@ import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsCo
 import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH_PART;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -883,12 +884,22 @@ public final class RestconfDataServiceImpl {
     // FIXME: NETCONF-718: we should be returning a future here
     private static DOMActionResult invokeAction(final ContainerNode data, final Absolute schemaPath,
             final YangInstanceIdentifier yangIId, final DOMActionService actionService) {
-        return RestconfInvokeOperationsServiceImpl.checkedGet(Futures.catching(actionService.invokeAction(
-            schemaPath, new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIId.getParent()), data),
+        final var future = Futures.catching(
+            actionService.invokeAction(schemaPath,
+                new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIId.getParent()), data),
             DOMActionException.class,
             cause -> new SimpleDOMActionResult(List.of(RpcResultBuilder.newError(
                 ErrorType.RPC, ErrorTag.OPERATION_FAILED, cause.getMessage()))),
-            MoreExecutors.directExecutor()));
+            MoreExecutors.directExecutor());
+
+        try {
+            return future.get();
+        } catch (InterruptedException e) {
+            throw new RestconfDocumentedException("Interrupted while waiting for result of invocation", e);
+        } catch (ExecutionException e) {
+            Throwables.throwIfInstanceOf(e.getCause(), RestconfDocumentedException.class);
+            throw new RestconfDocumentedException("Invocation failed", e);
+        }
     }
 
     /**
index a13a628e81872f4719a67aa220b7743f6a9532df..660a5b8a69fc073672fa8e6853f9138f2f11d8c1 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -18,7 +17,6 @@ import com.google.common.util.concurrent.MoreExecutors;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.POST;
@@ -238,16 +236,4 @@ public final class RestconfInvokeOperationsServiceImpl {
         return input != null ? input
                 : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getModule()));
     }
-
-    @Deprecated
-    static <T> T checkedGet(final ListenableFuture<T> future) {
-        try {
-            return future.get();
-        } catch (InterruptedException e) {
-            throw new RestconfDocumentedException("Interrupted while waiting for result of invocation", e);
-        } catch (ExecutionException e) {
-            Throwables.throwIfInstanceOf(e.getCause(), RestconfDocumentedException.class);
-            throw new RestconfDocumentedException("Invocation failed", e);
-        }
-    }
 }