Remove RestconfInvokeOperationsUtil 85/97485/5
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 13 Sep 2021 21:55:39 +0000 (23:55 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 14 Sep 2021 07:12:08 +0000 (09:12 +0200)
This is a stateless utility class, whose only use to make cooperating
code harder to understand. Remove it by moving its methods to
Restconf{Data,InvokeOperations}ServiceImpl, who are its only users.

JIRA: NETCONF-773
Change-Id: Ie2cd32af2b26f09d4196df0c52be737809d10850
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java [deleted file]
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java

index 74e118885855b285160656216058304147ade1a0..a2454ceb3ee66854d8bad96c68e2fcbecb4f8aa6 100644 (file)
@@ -19,6 +19,8 @@ import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsCo
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.net.URI;
 import java.time.Clock;
 import java.time.LocalDateTime;
@@ -28,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
@@ -35,14 +38,17 @@ import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMActionException;
 import org.opendaylight.mdsal.dom.api.DOMActionResult;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.context.WriterParameters;
@@ -63,7 +69,6 @@ import org.opendaylight.restconf.nb.rfc8040.rests.utils.PutDataTransactionUtil;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PostPutQueryParameters.Insert;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
@@ -74,6 +79,8 @@ import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -393,15 +400,13 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         final DOMActionResult response;
         final EffectiveModelContext schemaContextRef;
         if (mountPoint != null) {
-            response = RestconfInvokeOperationsUtil.invokeAction((ContainerNode) data, schemaPath, yangIIdContext,
-                mountPoint);
+            response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, mountPoint);
             schemaContextRef = modelContext(mountPoint);
         } else {
-            response = RestconfInvokeOperationsUtil.invokeAction((ContainerNode) data, schemaPath, yangIIdContext,
-                actionService);
-            schemaContextRef = this.schemaContextHandler.get();
+            response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, actionService);
+            schemaContextRef = schemaContextHandler.get();
         }
-        final DOMActionResult result = RestconfInvokeOperationsUtil.checkActionResponse(response);
+        final DOMActionResult result = checkActionResponse(response);
 
         ActionDefinition resultNodeSchema = null;
         ContainerNode resultData = null;
@@ -424,6 +429,65 @@ public class RestconfDataServiceImpl implements RestconfDataService {
             .build();
     }
 
+
+    /**
+     * Invoking Action via mount point.
+     *
+     * @param mountPoint mount point
+     * @param data input data
+     * @param schemaPath schema path of data
+     * @return {@link DOMActionResult}
+     */
+    private static DOMActionResult invokeAction(final ContainerNode data,
+            final Absolute schemaPath, final YangInstanceIdentifier yangIId, final DOMMountPoint mountPoint) {
+        return invokeAction(data, schemaPath, yangIId, mountPoint.getService(DOMActionService.class)
+            .orElseThrow(() -> new RestconfDocumentedException("DomAction service is missing.")));
+    }
+
+    /**
+     * Invoke Action via ActionServiceHandler.
+     *
+     * @param data input data
+     * @param yangIId invocation context
+     * @param schemaPath schema path of data
+     * @param actionService action service to invoke action
+     * @return {@link DOMActionResult}
+     */
+    // 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),
+            DOMActionException.class,
+            cause -> new SimpleDOMActionResult(ImmutableList.of(RpcResultBuilder.newError(
+                RpcError.ErrorType.RPC, "operation-failed", cause.getMessage()))),
+            MoreExecutors.directExecutor()));
+    }
+
+    /**
+     * Check the validity of the result.
+     *
+     * @param response response of Action
+     * @return {@link DOMActionResult} result
+     */
+    private static DOMActionResult checkActionResponse(final DOMActionResult response) {
+        if (response == null) {
+            return null;
+        }
+
+        try {
+            if (response.getErrors().isEmpty()) {
+                return response;
+            }
+            LOG.debug("InvokeAction Error Message {}", response.getErrors());
+            throw new RestconfDocumentedException("InvokeAction Error Message ", null, response.getErrors());
+        } catch (final CancellationException e) {
+            final String errMsg = "The Action Operation was cancelled while executing.";
+            LOG.debug("Cancel Execution: {}", errMsg, e);
+            throw new RestconfDocumentedException(errMsg, ErrorType.RPC, ErrorTag.PARTIAL_OPERATION, e);
+        }
+    }
+
     /**
      * Valid input data with {@link SchemaNode}.
      *
index 76f2b1fc42188794067218efecffc7e7c742405b..05333725a6d7edf5d078dcdbf9c4fb3f3580575b 100644 (file)
@@ -9,30 +9,46 @@ 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.collect.ImmutableList;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Optional;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
 import javax.ws.rs.Path;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMRpcException;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of {@link RestconfInvokeOperationsService}.
@@ -40,6 +56,9 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
  */
 @Path("/")
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
+    private static final Logger LOG = LoggerFactory.getLogger(RestconfInvokeOperationsServiceImpl.class);
+
+    // FIXME: at some point we do not want to have this here
     private static final XMLNamespace SAL_REMOTE_NAMESPACE =
         XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote");
 
@@ -55,7 +74,6 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
     @Override
     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
             final UriInfo uriInfo) {
-        final EffectiveModelContext refSchemaCtx = this.schemaContextHandler.get();
         final QName schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
         final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
         final XMLNamespace namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace();
@@ -63,23 +81,24 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
         final DOMRpcResult response;
         final EffectiveModelContext schemaContextRef;
         if (mountPoint == null) {
+            schemaContextRef = schemaContextHandler.get();
+            // FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS
             if (SAL_REMOTE_NAMESPACE.equals(namespace)) {
                 if (identifier.contains(RestconfStreamsConstants.CREATE_DATA_SUBSCRIPTION)) {
-                    response = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
+                    response = CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContextRef);
                 } else {
                     throw new RestconfDocumentedException("Not supported operation", ErrorType.RPC,
                             ErrorTag.OPERATION_NOT_SUPPORTED);
                 }
             } else {
-                response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath, this.rpcService);
+                response = invokeRpc(payload.getData(), schemaPath, rpcService);
             }
-            schemaContextRef = this.schemaContextHandler.get();
         } else {
-            response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath, mountPoint);
+            response = invokeRpc(payload.getData(), schemaPath, mountPoint);
             schemaContextRef = modelContext(mountPoint);
         }
 
-        final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response);
+        final DOMRpcResult result = checkResponse(response);
 
         RpcDefinition resultNodeSchema = null;
         NormalizedNode resultData = null;
@@ -96,6 +115,83 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
         }
     }
 
+    /**
+     * Invoking rpc via mount point.
+     *
+     * @param mountPoint mount point
+     * @param data input data
+     * @param rpc RPC type
+     * @return {@link DOMRpcResult}
+     */
+    // FIXME: NETCONF-718: we should be returning a future here
+    @VisibleForTesting
+    static DOMRpcResult invokeRpc(final NormalizedNode data, final QName rpc, final DOMMountPoint mountPoint) {
+        return invokeRpc(data, rpc, mountPoint.getService(DOMRpcService.class).orElseThrow(() -> {
+            final String errmsg = "RPC service is missing.";
+            LOG.debug(errmsg);
+            return new RestconfDocumentedException(errmsg);
+        }));
+    }
+
+    /**
+     * Invoke rpc.
+     *
+     * @param data input data
+     * @param rpc RPC type
+     * @param rpcService rpc service to invoke rpc
+     * @return {@link DOMRpcResult}
+     */
+    // FIXME: NETCONF-718: we should be returning a future here
+    @VisibleForTesting
+    static DOMRpcResult invokeRpc(final NormalizedNode data, final QName rpc, final DOMRpcService rpcService) {
+        return checkedGet(Futures.catching(
+            rpcService.invokeRpc(rpc, nonnullInput(rpc, data)), DOMRpcException.class,
+            cause -> new DefaultDOMRpcResult(ImmutableList.of(RpcResultBuilder.newError(
+                RpcError.ErrorType.RPC, "operation-failed", cause.getMessage()))),
+            MoreExecutors.directExecutor()));
+    }
+
+    private static @NonNull NormalizedNode nonnullInput(final QName type, final NormalizedNode input) {
+        return input != null ? input
+                : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getModule()));
+    }
+
+    /**
+     * Check the validity of the result.
+     *
+     * @param response response of rpc
+     * @return {@link DOMRpcResult} result
+     */
+    @VisibleForTesting
+    static DOMRpcResult checkResponse(final DOMRpcResult response) {
+        if (response == null) {
+            return null;
+        }
+        try {
+            if (response.getErrors().isEmpty()) {
+                return response;
+            }
+            LOG.debug("RpcError message {}", response.getErrors());
+            throw new RestconfDocumentedException("RPCerror message ", null, response.getErrors());
+        } catch (final CancellationException e) {
+            final String errMsg = "The operation was cancelled while executing.";
+            LOG.debug("Cancel RpcExecution: {}", errMsg, e);
+            throw new RestconfDocumentedException(errMsg, ErrorType.RPC, ErrorTag.PARTIAL_OPERATION, e);
+        }
+    }
+
+    @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);
+        }
+    }
+
     private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) {
         return mountPoint.getService(DOMSchemaService.class)
             .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext()))
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java
deleted file mode 100644 (file)
index f9f255d..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.rests.utils;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.MoreExecutors;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMActionException;
-import org.opendaylight.mdsal.dom.api.DOMActionResult;
-import org.opendaylight.mdsal.dom.api.DOMActionService;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMRpcException;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-import org.opendaylight.yangtools.yang.common.ErrorType;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Util class for rpc.
- */
-public final class RestconfInvokeOperationsUtil {
-    private static final Logger LOG = LoggerFactory.getLogger(RestconfInvokeOperationsUtil.class);
-
-    private RestconfInvokeOperationsUtil() {
-        // Hidden on purpose
-    }
-
-    /**
-     * Invoking rpc via mount point.
-     *
-     * @param mountPoint mount point
-     * @param data input data
-     * @param rpc RPC type
-     * @return {@link DOMRpcResult}
-     */
-    // FIXME: NETCONF-718: we should be returning a future here
-    public static DOMRpcResult invokeRpc(final NormalizedNode data, final QName rpc, final DOMMountPoint mountPoint) {
-        return invokeRpc(data, rpc, mountPoint.getService(DOMRpcService.class).orElseThrow(() -> {
-            final String errmsg = "RPC service is missing.";
-            LOG.debug(errmsg);
-            return new RestconfDocumentedException(errmsg);
-        }));
-    }
-
-    /**
-     * Invoke rpc.
-     *
-     * @param data input data
-     * @param rpc RPC type
-     * @param rpcService rpc service to invoke rpc
-     * @return {@link DOMRpcResult}
-     */
-    // FIXME: NETCONF-718: we should be returning a future here
-    public static DOMRpcResult invokeRpc(final NormalizedNode data, final QName rpc, final DOMRpcService rpcService) {
-        return checkedGet(Futures.catching(
-            rpcService.invokeRpc(rpc, nonnullInput(rpc, data)), DOMRpcException.class,
-            cause -> new DefaultDOMRpcResult(ImmutableList.of(RpcResultBuilder.newError(
-                RpcError.ErrorType.RPC, "operation-failed", cause.getMessage()))),
-            MoreExecutors.directExecutor()));
-    }
-
-    private static @NonNull NormalizedNode nonnullInput(final QName type, final NormalizedNode input) {
-        return input != null ? input
-                : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getModule()));
-    }
-
-    /**
-     * Check the validity of the result.
-     *
-     * @param response response of rpc
-     * @return {@link DOMRpcResult} result
-     */
-    public static DOMRpcResult checkResponse(final DOMRpcResult response) {
-        if (response == null) {
-            return null;
-        }
-        try {
-            if (response.getErrors().isEmpty()) {
-                return response;
-            }
-            LOG.debug("RpcError message {}", response.getErrors());
-            throw new RestconfDocumentedException("RPCerror message ", null, response.getErrors());
-        } catch (final CancellationException e) {
-            final String errMsg = "The operation was cancelled while executing.";
-            LOG.debug("Cancel RpcExecution: {}", errMsg, e);
-            throw new RestconfDocumentedException(errMsg, ErrorType.RPC, ErrorTag.PARTIAL_OPERATION, e);
-        }
-    }
-
-    /**
-     * Invoking Action via mount point.
-     *
-     * @param mountPoint mount point
-     * @param data input data
-     * @param schemaPath schema path of data
-     * @return {@link DOMActionResult}
-     */
-    public static DOMActionResult invokeAction(final ContainerNode data,
-            final Absolute schemaPath, final YangInstanceIdentifier yangIId, final DOMMountPoint mountPoint) {
-        return invokeAction(data, schemaPath, yangIId, mountPoint.getService(DOMActionService.class)
-            .orElseThrow(() -> new RestconfDocumentedException("DomAction service is missing.")));
-    }
-
-    /**
-     * Invoke Action via ActionServiceHandler.
-     *
-     * @param data input data
-     * @param yangIId invocation context
-     * @param schemaPath schema path of data
-     * @param actionService action service to invoke action
-     * @return {@link DOMActionResult}
-     */
-    // FIXME: NETCONF-718: we should be returning a future here
-    public static DOMActionResult invokeAction(final ContainerNode data, final Absolute schemaPath,
-            final YangInstanceIdentifier yangIId, final DOMActionService actionService) {
-        return checkedGet(Futures.catching(actionService.invokeAction(
-            schemaPath, new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIId.getParent()), data),
-            DOMActionException.class,
-            cause -> new SimpleDOMActionResult(ImmutableList.of(RpcResultBuilder.newError(
-                RpcError.ErrorType.RPC, "operation-failed", cause.getMessage()))),
-            MoreExecutors.directExecutor()));
-    }
-
-    @Deprecated
-    private 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) {
-            final Throwable cause = e.getCause();
-            Throwables.throwIfInstanceOf(cause, RestconfDocumentedException.class);
-            throw new RestconfDocumentedException("Invocation failed", e);
-        }
-    }
-
-    /**
-     * Check the validity of the result.
-     *
-     * @param response
-     *             response of Action
-     * @return {@link DOMActionResult} result
-     */
-    public static DOMActionResult checkActionResponse(final DOMActionResult response) {
-        if (response != null) {
-            try {
-                if (response.getErrors().isEmpty()) {
-                    return response;
-                }
-                LOG.debug("InvokeAction Error Message {}", response.getErrors());
-                throw new RestconfDocumentedException("InvokeAction Error Message ", null, response.getErrors());
-            } catch (final CancellationException e) {
-                final String errMsg = "The Action Operation was cancelled while executing.";
-                LOG.debug("Cancel Execution: {}", errMsg, e);
-                throw new RestconfDocumentedException(errMsg, ErrorType.RPC, ErrorTag.PARTIAL_OPERATION, e);
-            }
-        }
-        return null;
-    }
-}
index 99cf11c4a1794f10f1b24aece7cf69c96bfa4899..ccfba855ca6762959b49fcc08dd6abd22023af25 100644 (file)
@@ -45,7 +45,6 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -132,7 +131,7 @@ public class RestconfInvokeOperationsServiceImplTest {
     public void invokeRpcTest() {
         final DOMRpcResult mockResult = new DefaultDOMRpcResult(OUTPUT, List.of());
         doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(RPC, INPUT);
-        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(INPUT, RPC, rpcService);
+        final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, rpcService);
         assertTrue(rpcResult.getErrors().isEmpty());
         assertEquals(OUTPUT, rpcResult.getResult());
     }
@@ -143,7 +142,7 @@ public class RestconfInvokeOperationsServiceImplTest {
         final DOMRpcException exception = new DOMRpcImplementationNotAvailableException(
                 "No implementation of RPC " + errorRpc + " available.");
         doReturn(immediateFailedFluentFuture(exception)).when(rpcService).invokeRpc(errorRpc, INPUT);
-        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(INPUT, errorRpc, rpcService);
+        final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, errorRpc, rpcService);
         assertNull(rpcResult.getResult());
         final Collection<? extends RpcError> errorList = rpcResult.getErrors();
         assertEquals(1, errorList.size());
@@ -152,7 +151,8 @@ public class RestconfInvokeOperationsServiceImplTest {
         assertEquals("operation-failed", actual.getTag());
         assertEquals(RpcError.ErrorType.RPC, actual.getErrorType());
 
-        assertThrows(RestconfDocumentedException.class, () -> RestconfInvokeOperationsUtil.checkResponse(rpcResult));
+        assertThrows(RestconfDocumentedException.class,
+            () -> RestconfInvokeOperationsServiceImpl.checkResponse(rpcResult));
     }
 
     @Test
@@ -160,7 +160,7 @@ public class RestconfInvokeOperationsServiceImplTest {
         doReturn(Optional.ofNullable(rpcService)).when(mountPoint).getService(DOMRpcService.class);
         final DOMRpcResult mockResult = new DefaultDOMRpcResult(OUTPUT, List.of());
         doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(RPC, INPUT);
-        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(INPUT, RPC, mountPoint);
+        final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, mountPoint);
         assertTrue(rpcResult.getErrors().isEmpty());
         assertEquals(OUTPUT, rpcResult.getResult());
     }
@@ -169,17 +169,17 @@ public class RestconfInvokeOperationsServiceImplTest {
     public void invokeRpcMissingMountPointServiceTest() {
         doReturn(Optional.empty()).when(mountPoint).getService(DOMRpcService.class);
         assertThrows(RestconfDocumentedException.class,
-            () -> RestconfInvokeOperationsUtil.invokeRpc(INPUT, RPC, mountPoint));
+            () -> RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, mountPoint));
     }
 
     @Test
     public void checkResponseTest() {
         final DOMRpcResult mockResult = new DefaultDOMRpcResult(OUTPUT, List.of());
         doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(RPC, INPUT);
-        final DOMRpcResult rpcResult = RestconfInvokeOperationsUtil.invokeRpc(INPUT, RPC, rpcService);
+        final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, rpcService);
         assertTrue(rpcResult.getErrors().isEmpty());
         assertEquals(OUTPUT, rpcResult.getResult());
-        assertNotNull(RestconfInvokeOperationsUtil.checkResponse(rpcResult));
+        assertNotNull(RestconfInvokeOperationsServiceImpl.checkResponse(rpcResult));
     }
 
     private NormalizedNodeContext prepNNC(final NormalizedNode result) {