Promote OperationOutput to restconf.server.api 86/109086/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Nov 2023 02:14:48 +0000 (03:14 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Nov 2023 02:18:36 +0000 (03:18 +0100)
If we rename this to OperationsPostResult, this goes very nicely with
OperationsGetResult.

JIRA: NETCONF-773
Change-Id: Idcc8d43fac0a7b0125dad692a70c60c9f7158bcd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostResult.java [moved from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationOutput.java with 64% similarity]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfServer.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/devnotif/SubscribeDeviceNotificationRpc.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateDataChangeEventSubscriptionRpc.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/notif/CreateNotificationStreamRpc.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationInput.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/RpcImplementation.java

index 7b3ae2b4ebe59b7fecc206a3103e2551debfd402..6e4ecc1b8c3d266cea4f9fa8eb1a764b2afdf3a0 100644 (file)
@@ -71,8 +71,8 @@ import org.opendaylight.restconf.server.api.DataPostResult.InvokeOperation;
 import org.opendaylight.restconf.server.api.DataPutResult;
 import org.opendaylight.restconf.server.api.ModulesGetResult;
 import org.opendaylight.restconf.server.api.OperationsGetResult;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.restconf.server.api.RestconfServer;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.YangConstants;
@@ -749,9 +749,9 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     private void operationsPOST(final ApiPath identifier, final UriInfo uriInfo, final AsyncResponse ar,
             final OperationInputBody body) {
         server.operationsPOST(uriInfo.getBaseUri(), identifier, body)
-            .addCallback(new JaxRsRestconfCallback<OperationOutput>(ar) {
+            .addCallback(new JaxRsRestconfCallback<OperationsPostResult>(ar) {
                 @Override
-                Response transform(final OperationOutput result) {
+                Response transform(final OperationsPostResult result) {
                     final var body = result.output();
                     return body == null ? Response.noContent().build()
                         : Response.ok().entity(new NormalizedNodePayload(result.operation(), body)).build();
index 4e5d2b1267e26c5a73844bfadce9058bdb1b96c8..50725a28237bf202d9f9abc0e2962919e5fc5210 100644 (file)
@@ -52,8 +52,8 @@ import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.restconf.server.api.DataPostResult.CreateResource;
 import org.opendaylight.restconf.server.api.DataPutResult;
 import org.opendaylight.restconf.server.api.DatabindContext;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.restconf.server.spi.OperationInput;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.restconf.server.spi.RpcImplementation;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.with.defaults.rev110601.WithDefaultsMode;
 import org.opendaylight.yangtools.yang.common.Empty;
@@ -1057,7 +1057,7 @@ public abstract class RestconfStrategy {
             y -> builder.addChild((T) prepareData(y.getValue(), stateMap.get(y.getKey()))));
     }
 
-    public @NonNull RestconfFuture<OperationOutput> invokeRpc(final URI restconfURI, final QName type,
+    public @NonNull RestconfFuture<OperationsPostResult> invokeRpc(final URI restconfURI, final QName type,
             final OperationInput input) {
         final var local = localRpcs.get(type);
         if (local != null) {
@@ -1069,7 +1069,7 @@ public abstract class RestconfStrategy {
                 ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED));
         }
 
-        final var ret = new SettableRestconfFuture<OperationOutput>();
+        final var ret = new SettableRestconfFuture<OperationsPostResult>();
         Futures.addCallback(rpcService.invokeRpc(requireNonNull(type), input.input()),
             new FutureCallback<DOMRpcResult>() {
                 @Override
similarity index 64%
rename from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationOutput.java
rename to restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostResult.java
index 6b191efbcc1246d7127f664774ee8d3789bc48db..b6d6470b2ed729297c162b896391a176609424f0 100644 (file)
@@ -5,25 +5,28 @@
  * 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.server.spi;
+package org.opendaylight.restconf.server.api;
 
 import static java.util.Objects.requireNonNull;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.restconf.server.api.DatabindAware;
-import org.opendaylight.restconf.server.api.DatabindContext;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
 
 /**
- * Output of {@link RpcImplementation#invoke(java.net.URI, OperationInput)}.
+ * RESTCONF {@code /operations} content for a {@code POST} operation as per
+ * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a>.
+ *
+ * @param databind Associated {@link DatabindContext}
+ * @param operation An {@link Inference} pointing to the invoked operation
+ * @param output Operation output, or {@code null} if output would be empty
  */
-public record OperationOutput(
+public record OperationsPostResult(
         @NonNull DatabindContext databind,
         @NonNull Inference operation,
         @Nullable ContainerNode output) implements DatabindAware {
-    public OperationOutput {
+    public OperationsPostResult {
         requireNonNull(databind);
         requireNonNull(operation);
         if (output != null && output.isEmpty()) {
index 827c3be02b1292d20775532ee31cb6f31155aafc..5d60fe25f29f2f0600f201330f94e73557d337eb 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.restconf.nb.rfc8040.databind.PatchBody;
 import org.opendaylight.restconf.nb.rfc8040.databind.ResourceBody;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.server.api.DataPostResult.CreateResource;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.yangtools.yang.common.Empty;
 
 /**
@@ -149,12 +148,12 @@ public interface RestconfServer {
      * @param restconfURI Base URI of the request
      * @param operation {@code <operation>} path, really an {@link ApiPath} to an {@code rpc}
      * @param body RPC operation
-     * @return A {@link RestconfFuture} completing with {@link OperationOutput}
+     * @return A {@link RestconfFuture} completing with {@link OperationsPostResult}
      */
     // FIXME: 'operation' should really be an ApiIdentifier with non-null module, but we also support ang-ext:mount,
     //        and hence it is a path right now
     // FIXME: use ApiPath instead of String
-    RestconfFuture<OperationOutput> operationsPOST(URI restconfURI, ApiPath operation, OperationInputBody body);
+    RestconfFuture<OperationsPostResult> operationsPOST(URI restconfURI, ApiPath operation, OperationInputBody body);
 
     /**
      * Return the revision of {@code ietf-yang-library} module implemented by this server, as defined in
index 2e0176fe8ed3f16d171c3f951c52826921844aa0..27e3d8f2e9f123c59f8bd8ab37f60516e8cd6a2e 100644 (file)
@@ -76,10 +76,10 @@ import org.opendaylight.restconf.server.api.DataPutResult;
 import org.opendaylight.restconf.server.api.DatabindContext;
 import org.opendaylight.restconf.server.api.ModulesGetResult;
 import org.opendaylight.restconf.server.api.OperationsGetResult;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.restconf.server.api.RestconfServer;
 import org.opendaylight.restconf.server.spi.DatabindProvider;
 import org.opendaylight.restconf.server.spi.OperationInput;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.restconf.server.spi.RpcImplementation;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.YangApi;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.restconf.Restconf;
@@ -602,7 +602,7 @@ public final class MdsalRestconfServer
     }
 
     @Override
-    public RestconfFuture<OperationOutput> operationsPOST(final URI restconfURI, final ApiPath apiPath,
+    public RestconfFuture<OperationsPostResult> operationsPOST(final URI restconfURI, final ApiPath apiPath,
             final OperationInputBody body) {
         final var reqPath = bindRequestPath(localStrategy(), apiPath);
         final var inference = reqPath.inference();
index 65823a2d2155dd76f20606a4d541ac69325b0304..0fe37e185b600f730932fdfed043b70b52b99467 100644 (file)
@@ -16,8 +16,8 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfFuture;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.restconf.server.spi.OperationInput;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RpcImplementation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106.SubscribeDeviceNotification;
@@ -60,7 +60,7 @@ public final class SubscribeDeviceNotificationRpc extends RpcImplementation {
     }
 
     @Override
-    public RestconfFuture<OperationOutput> invoke(final URI restconfURI, final OperationInput input) {
+    public RestconfFuture<OperationsPostResult> invoke(final URI restconfURI, final OperationInput input) {
         final var body = input.input();
         final var pathLeaf = body.childByArg(DEVICE_NOTIFICATION_PATH_NODEID);
         if (pathLeaf == null) {
index bcaff1982c2acac54c23c41205a7240716f514ad..f651b87ba7204ecf19bb04c6491ddf62e2404223 100644 (file)
@@ -19,9 +19,9 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfFuture;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.restconf.server.spi.DatabindProvider;
 import org.opendaylight.restconf.server.spi.OperationInput;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RpcImplementation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscription;
@@ -97,7 +97,7 @@ public final class CreateDataChangeEventSubscriptionRpc extends RpcImplementatio
      *     </pre>
      */
     @Override
-    public RestconfFuture<OperationOutput> invoke(final URI restconfURI, final OperationInput input) {
+    public RestconfFuture<OperationsPostResult> invoke(final URI restconfURI, final OperationInput input) {
         final var body = input.input();
         final var datastoreName = leaf(body, DATASTORE_NODEID, String.class);
         final var datastore = datastoreName != null ? LogicalDatastoreType.valueOf(datastoreName)
index ffa53cf55208248305c6507926e9ae4d022fa9ad..0c4bc6d547e412296bc2c45f6283b0b4aea91368 100644 (file)
@@ -16,9 +16,9 @@ import javax.inject.Singleton;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfFuture;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.restconf.server.spi.DatabindProvider;
 import org.opendaylight.restconf.server.spi.OperationInput;
-import org.opendaylight.restconf.server.spi.OperationOutput;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RpcImplementation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionOutput;
@@ -66,7 +66,7 @@ public final class CreateNotificationStreamRpc extends RpcImplementation {
     }
 
     @Override
-    public RestconfFuture<OperationOutput> invoke(final URI restconfURI, final OperationInput input) {
+    public RestconfFuture<OperationsPostResult> invoke(final URI restconfURI, final OperationInput input) {
         final var body = input.input();
         final var qnames = ((LeafSetNode<String>) body.getChildByArg(NOTIFICATIONS)).body().stream()
             .map(LeafSetEntryNode::body)
index bbe96663ff7b8384b4db4a68c05bf4d561d686be..6c5964f3ae53f3898f83acf4e6417ecb716dae0b 100644 (file)
@@ -13,6 +13,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.server.api.DatabindAware;
 import org.opendaylight.restconf.server.api.DatabindContext;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
 
@@ -29,12 +30,12 @@ public record OperationInput(DatabindContext databind, Inference operation, Cont
     }
 
     /**
-     * Create an {@link OperationOutput} with equal {@link #databind()} and {@link #operation()}.
+     * Create an {@link OperationsPostResult} with equal {@link #databind()} and {@link #operation()}.
      *
      * @param output Output payload
-     * @return An {@link OperationOutput}
+     * @return An {@link OperationsPostResult}
      */
-    public OperationOutput newOperationOutput(final @Nullable ContainerNode output) {
-        return new OperationOutput(databind, operation, output);
+    public OperationsPostResult newOperationOutput(final @Nullable ContainerNode output) {
+        return new OperationsPostResult(databind, operation, output);
     }
 }
\ No newline at end of file
index b3d5688bce841aafc9b677c3e84b2621cea5e705..af810b4512861700fe6ebc0cf8834dd77ae9bf0f 100644 (file)
@@ -14,6 +14,7 @@ import java.net.URI;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.common.errors.RestconfFuture;
+import org.opendaylight.restconf.server.api.OperationsPostResult;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -47,7 +48,7 @@ public abstract class RpcImplementation {
      * @param input RPC input
      * @return Future RPC output
      */
-    public abstract RestconfFuture<OperationOutput> invoke(URI restconfURI, OperationInput input);
+    public abstract RestconfFuture<OperationsPostResult> invoke(URI restconfURI, OperationInput input);
 
     @Override
     public final String toString() {