Eliminate RestconfInvokeOperationsServiceImpl 06/108906/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 10 Nov 2023 05:46:28 +0000 (06:46 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 10 Nov 2023 05:49:48 +0000 (06:49 +0100)
This class handles only POST, merge it into
RestconfOperationsServiceImpl, which already handles GET.

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

index 584e93e7059f26bfbb4c5e6a04dc4f17ef501768..8eef7b23d7e140a91db0093d797ab08a8cd4227c 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocu
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.MdsalRestconfServer;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfInvokeOperationsServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfOperationsServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfSchemaServiceImpl;
 
@@ -39,7 +38,6 @@ final class RestconfApplication extends Application {
         singletons = Set.of(
             new RestconfDocumentedExceptionMapper(databindProvider),
             new RestconfDataServiceImpl(databindProvider, server, actionService),
-            new RestconfInvokeOperationsServiceImpl(server),
             new RestconfOperationsServiceImpl(server),
             new RestconfSchemaServiceImpl(domSchemaService, mountPointService),
             new RestconfImpl(databindProvider));
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
deleted file mode 100644 (file)
index 9819b1b..0000000
+++ /dev/null
@@ -1,115 +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.services.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import java.io.InputStream;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.container.AsyncResponse;
-import javax.ws.rs.container.Suspended;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-import org.opendaylight.restconf.nb.rfc8040.databind.JsonOperationInputBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.OperationInputBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.XmlOperationInputBody;
-import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
-import org.opendaylight.restconf.server.spi.OperationOutput;
-
-/**
- * An operation resource represents a protocol operation defined with the YANG {@code rpc} statement. It is invoked
- * using a POST method on the operation resource.
- */
-@Path("/")
-public final class RestconfInvokeOperationsServiceImpl {
-    private final MdsalRestconfServer server;
-
-    public RestconfInvokeOperationsServiceImpl(final MdsalRestconfServer server) {
-        this.server = requireNonNull(server);
-    }
-
-    /**
-     * Invoke RPC operation.
-     *
-     * @param identifier module name and rpc identifier string for the desired operation
-     * @param body the body of the operation
-     * @param uriInfo URI info
-     * @param ar {@link AsyncResponse} which needs to be completed with a {@link NormalizedNodePayload} output
-     */
-    @POST
-    // FIXME: identifier is just a *single* QName
-    @Path("/operations/{identifier:.+}")
-    @Consumes({
-        MediaTypes.APPLICATION_YANG_DATA_XML,
-        MediaType.APPLICATION_XML,
-        MediaType.TEXT_XML
-    })
-    @Produces({
-        MediaTypes.APPLICATION_YANG_DATA_JSON,
-        MediaTypes.APPLICATION_YANG_DATA_XML,
-        MediaType.APPLICATION_JSON,
-        MediaType.APPLICATION_XML,
-        MediaType.TEXT_XML
-    })
-    public void invokeRpcXML(@Encoded @PathParam("identifier") final String identifier, final InputStream body,
-            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
-        try (var xmlBody = new XmlOperationInputBody(body)) {
-            invokeRpc(identifier, uriInfo, ar, xmlBody);
-        }
-    }
-
-    /**
-     * Invoke RPC operation.
-     *
-     * @param identifier module name and rpc identifier string for the desired operation
-     * @param body the body of the operation
-     * @param uriInfo URI info
-     * @param ar {@link AsyncResponse} which needs to be completed with a {@link NormalizedNodePayload} output
-     */
-    @POST
-    // FIXME: identifier is just a *single* QName
-    @Path("/operations/{identifier:.+}")
-    @Consumes({
-        MediaTypes.APPLICATION_YANG_DATA_JSON,
-        MediaType.APPLICATION_JSON,
-    })
-    @Produces({
-        MediaTypes.APPLICATION_YANG_DATA_JSON,
-        MediaTypes.APPLICATION_YANG_DATA_XML,
-        MediaType.APPLICATION_JSON,
-        MediaType.APPLICATION_XML,
-        MediaType.TEXT_XML
-    })
-    public void invokeRpcJSON(@Encoded @PathParam("identifier") final String identifier, final InputStream body,
-            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
-        try (var jsonBody = new JsonOperationInputBody(body)) {
-            invokeRpc(identifier, uriInfo, ar, jsonBody);
-        }
-    }
-
-    private void invokeRpc(final String identifier, final UriInfo uriInfo, final AsyncResponse ar,
-            final OperationInputBody body) {
-        server.invokeRpc(uriInfo.getBaseUri(), identifier, body)
-            .addCallback(new JaxRsRestconfCallback<OperationOutput>(ar) {
-                @Override
-                Response transform(final OperationOutput result) {
-                    final var body = result.output();
-                    return body == null ? Response.noContent().build()
-                        : Response.ok().entity(new NormalizedNodePayload(result.operation(), body)).build();
-                }
-            });
-    }
-}
index ba3c1b52e2aa640f25665c7405a107e99483c72f..7a600eb3a4ba4a2ae5c4092602638bf3bcfb8b3a 100644 (file)
@@ -9,13 +9,27 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
 import static java.util.Objects.requireNonNull;
 
+import java.io.InputStream;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Encoded;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
+import org.opendaylight.restconf.nb.rfc8040.databind.JsonOperationInputBody;
+import org.opendaylight.restconf.nb.rfc8040.databind.OperationInputBody;
+import org.opendaylight.restconf.nb.rfc8040.databind.XmlOperationInputBody;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
+import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 /**
@@ -83,4 +97,76 @@ public final class RestconfOperationsServiceImpl {
     public String getOperationXML(@PathParam("identifier") final String identifier) {
         return OperationsContent.XML.bodyFor(server.bindRequestPath(identifier).inference());
     }
+
+    /**
+     * Invoke RPC operation.
+     *
+     * @param identifier module name and rpc identifier string for the desired operation
+     * @param body the body of the operation
+     * @param uriInfo URI info
+     * @param ar {@link AsyncResponse} which needs to be completed with a {@link NormalizedNodePayload} output
+     */
+    @POST
+    // FIXME: identifier is just a *single* QName
+    @Path("/operations/{identifier:.+}")
+    @Consumes({
+        MediaTypes.APPLICATION_YANG_DATA_XML,
+        MediaType.APPLICATION_XML,
+        MediaType.TEXT_XML
+    })
+    @Produces({
+        MediaTypes.APPLICATION_YANG_DATA_JSON,
+        MediaTypes.APPLICATION_YANG_DATA_XML,
+        MediaType.APPLICATION_JSON,
+        MediaType.APPLICATION_XML,
+        MediaType.TEXT_XML
+    })
+    public void invokeRpcXML(@Encoded @PathParam("identifier") final String identifier, final InputStream body,
+            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
+        try (var xmlBody = new XmlOperationInputBody(body)) {
+            invokeRpc(identifier, uriInfo, ar, xmlBody);
+        }
+    }
+
+    /**
+     * Invoke RPC operation.
+     *
+     * @param identifier module name and rpc identifier string for the desired operation
+     * @param body the body of the operation
+     * @param uriInfo URI info
+     * @param ar {@link AsyncResponse} which needs to be completed with a {@link NormalizedNodePayload} output
+     */
+    @POST
+    // FIXME: identifier is just a *single* QName
+    @Path("/operations/{identifier:.+}")
+    @Consumes({
+        MediaTypes.APPLICATION_YANG_DATA_JSON,
+        MediaType.APPLICATION_JSON,
+    })
+    @Produces({
+        MediaTypes.APPLICATION_YANG_DATA_JSON,
+        MediaTypes.APPLICATION_YANG_DATA_XML,
+        MediaType.APPLICATION_JSON,
+        MediaType.APPLICATION_XML,
+        MediaType.TEXT_XML
+    })
+    public void invokeRpcJSON(@Encoded @PathParam("identifier") final String identifier, final InputStream body,
+            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
+        try (var jsonBody = new JsonOperationInputBody(body)) {
+            invokeRpc(identifier, uriInfo, ar, jsonBody);
+        }
+    }
+
+    private void invokeRpc(final String identifier, final UriInfo uriInfo, final AsyncResponse ar,
+            final OperationInputBody body) {
+        server.invokeRpc(uriInfo.getBaseUri(), identifier, body)
+            .addCallback(new JaxRsRestconfCallback<OperationOutput>(ar) {
+                @Override
+                Response transform(final OperationOutput result) {
+                    final var body = result.output();
+                    return body == null ? Response.noContent().build()
+                        : Response.ok().entity(new NormalizedNodePayload(result.operation(), body)).build();
+                }
+            });
+    }
 }
index 878fb9ebb480080ff461b7a3bea9d0a625af0231..789b192249b5b05d27a07fb0498c66cfa6b3d98e 100644 (file)
@@ -85,13 +85,13 @@ public class RestconfInvokeOperationsServiceImplTest {
     @Mock
     private DOMNotificationService notificationService;
 
-    private RestconfInvokeOperationsServiceImpl invokeOperationsService;
+    private RestconfOperationsServiceImpl invokeOperationsService;
     private MdsalRestconfServer server;
 
     @Before
     public void setup() {
         server = new MdsalRestconfServer(() -> CONTEXT, dataBroker, rpcService, mountPointService);
-        invokeOperationsService = new RestconfInvokeOperationsServiceImpl(server);
+        invokeOperationsService = new RestconfOperationsServiceImpl(server);
     }
 
     @Test