From 17af1d6ea63ba764d847ef8bd8068a802463b7a7 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 3 Apr 2024 19:24:02 +0200 Subject: [PATCH] Remove OperationsPostPath DatabindPath.OperationPath provides a more powerful tool, use that instead. JIRA: NETCONF-1288 Change-Id: If234477cf6f304945c4e0dc574c59f0e2983d725 Signed-off-by: Robert Varga --- .../restconf/nb/jaxrs/JaxRsRestconf.java | 2 +- .../rests/transactions/RestconfStrategy.java | 13 ++--- .../restconf/server/api/DatabindPath.java | 5 +- .../server/api/JsonOperationInputBody.java | 5 +- .../server/api/OperationInputBody.java | 9 +-- .../server/api/OperationsPostPath.java | 58 ------------------- .../server/api/OperationsPostResult.java | 14 ++--- .../server/api/XmlOperationInputBody.java | 8 ++- .../SubscribeDeviceNotificationRpc.java | 6 +- .../CreateDataChangeEventSubscriptionRpc.java | 6 +- .../notif/CreateNotificationStreamRpc.java | 5 +- .../restconf/server/spi/OperationInput.java | 22 +------ .../AbstractOperationInputBodyTest.java | 19 ++++-- .../dtcl/CreateNotificationStreamRpcTest.java | 4 +- 14 files changed, 58 insertions(+), 118 deletions(-) delete mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostPath.java diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java index 4a59c104e7..9ed12ea8c7 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java @@ -761,7 +761,7 @@ public final class JaxRsRestconf implements ParamConverterProvider { 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(); + : Response.ok().entity(new NormalizedNodePayload(result.path().inference(), body)).build(); } }); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java index fba2fe19e1..dffe555f1e 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java @@ -87,7 +87,6 @@ import org.opendaylight.restconf.server.api.DatabindPath.InstanceReference; import org.opendaylight.restconf.server.api.DatabindPath.Rpc; import org.opendaylight.restconf.server.api.OperationInputBody; import org.opendaylight.restconf.server.api.OperationsGetResult; -import org.opendaylight.restconf.server.api.OperationsPostPath; import org.opendaylight.restconf.server.api.OperationsPostResult; import org.opendaylight.restconf.server.api.PatchBody; import org.opendaylight.restconf.server.api.ResourceBody; @@ -1292,10 +1291,9 @@ public abstract class RestconfStrategy { return RestconfFuture.failed(e); } - final var postPath = new OperationsPostPath(databind, path.inference()); final ContainerNode data; try { - data = body.toContainerNode(postPath); + data = body.toContainerNode(path); } catch (IOException e) { LOG.debug("Error reading input", e); return RestconfFuture.failed(new RestconfDocumentedException("Error parsing input: " + e.getMessage(), @@ -1305,7 +1303,7 @@ public abstract class RestconfStrategy { final var type = path.rpc().argument(); final var local = localRpcs.get(type); if (local != null) { - return local.invoke(restconfURI, new OperationInput(databind, postPath.operation(), data)); + return local.invoke(restconfURI, new OperationInput(path, data)); } if (rpcService == null) { LOG.debug("RPC invocation is not available"); @@ -1319,7 +1317,7 @@ public abstract class RestconfStrategy { public void onSuccess(final DOMRpcResult response) { final var errors = response.errors(); if (errors.isEmpty()) { - ret.set(new OperationsPostResult(databind, postPath.operation(), response.value())); + ret.set(new OperationsPostResult(path, response.value())); } else { LOG.debug("RPC invocation reported {}", response.errors()); ret.setFailure(new RestconfDocumentedException("RPC implementation reported errors", null, @@ -1454,10 +1452,9 @@ public abstract class RestconfStrategy { } private @NonNull RestconfFuture dataInvokePOST(final Action path, final OperationInputBody body) { - final var inference = path.inference(); final ContainerNode input; try { - input = body.toContainerNode(new OperationsPostPath(databind, inference)); + input = body.toContainerNode(path); } catch (IOException e) { LOG.debug("Error reading input", e); return RestconfFuture.failed(new RestconfDocumentedException("Error parsing input: " + e.getMessage(), @@ -1471,7 +1468,7 @@ public abstract class RestconfStrategy { final var future = dataInvokePOST(actionService, path, input); return future.transform(result -> result.getOutput() .flatMap(output -> output.isEmpty() ? Optional.empty() - : Optional.of(new InvokeOperation(new NormalizedNodePayload(inference, output)))) + : Optional.of(new InvokeOperation(new NormalizedNodePayload(path.inference(), output)))) .orElse(InvokeOperation.EMPTY)); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPath.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPath.java index b92cfdbc5c..72e1fe4560 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPath.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPath.java @@ -139,7 +139,10 @@ public sealed interface DatabindPath extends DatabindAware { /** * An intermediate trait of {@link DatabindPath}s which are referencing a YANG operation. This can be either - * an {@link Action} on an {@link Rpc}. + * an {@link Action}, as defined in + * RFC8040 Invoke Operation Mode or + * an {@link Rpc}, as defined in + * RFC8040 Operation Resource. */ sealed interface OperationPath extends DatabindPath { /** diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/JsonOperationInputBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/JsonOperationInputBody.java index 8f88d85e5b..72189650ab 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/JsonOperationInputBody.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/JsonOperationInputBody.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; +import org.opendaylight.restconf.server.api.DatabindPath.OperationPath; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; @@ -29,10 +30,10 @@ public final class JsonOperationInputBody extends OperationInputBody { } @Override - void streamTo(final OperationsPostPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer) + void streamTo(final OperationPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer) throws IOException { try { - JsonParserStream.create(writer, path.databind().jsonCodecs(), path.operation()) + JsonParserStream.create(writer, path.databind().jsonCodecs(), path.inference()) .parse(new JsonReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))); } catch (JsonParseException e) { LOG.debug("Error parsing JSON input", e); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationInputBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationInputBody.java index 45b858408f..de171abd60 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationInputBody.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationInputBody.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.restconf.server.api.DatabindPath.OperationPath; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; @@ -30,16 +31,16 @@ public abstract sealed class OperationInputBody extends AbstractBody /** * Stream the {@code input} into a {@link NormalizedNodeStreamWriter}. * - * @param path The {@link OperationsPostPath} of the operation invocation + * @param path The {@link OperationPath} of the operation invocation * @return The document body, or an empty container node * @throws IOException when an I/O error occurs */ - public @NonNull ContainerNode toContainerNode(final @NonNull OperationsPostPath path) throws IOException { + public @NonNull ContainerNode toContainerNode(final @NonNull OperationPath path) throws IOException { try (var is = new PushbackInputStream(acquireStream())) { final var firstByte = is.read(); if (firstByte == -1) { return ImmutableNodes.newContainerBuilder() - .withNodeIdentifier(new NodeIdentifier(path.inputQName())) + .withNodeIdentifier(new NodeIdentifier(path.inputStatement().argument())) .build(); } is.unread(firstByte); @@ -52,6 +53,6 @@ public abstract sealed class OperationInputBody extends AbstractBody } } - abstract void streamTo(@NonNull OperationsPostPath path, @NonNull InputStream inputStream, + abstract void streamTo(@NonNull OperationPath path, @NonNull InputStream inputStream, @NonNull NormalizedNodeStreamWriter writer) throws IOException; } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostPath.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostPath.java deleted file mode 100644 index 723769571c..0000000000 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostPath.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.server.api; - -import static java.util.Objects.requireNonNull; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.opendaylight.restconf.api.ApiPath; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement; -import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; -import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; - -/** - * An {@link ApiPath} subpath of {@code /operations} {@code POST} HTTP operation, as defined in - * RFC8040 Operation Resource and - * RFC8040 Invoke Operation Mode. - * - * @param databind Associated {@link DatabindContext} - * @param operation Associated {@link Inference} pointing to the {@link EffectiveStatement} of an {@code rpc} or an - * {@code action} invocation, inference pointing to the statement - * @see OperationsPostResult - */ -@NonNullByDefault -public record OperationsPostPath(DatabindContext databind, Inference operation) implements DatabindAware { - public OperationsPostPath { - requireNonNull(databind); - requireNonNull(operation); - } - - public Inference input() { - final var stack = operation.toSchemaInferenceStack(); - stack.enterDataTree(inputQName(stack)); - return stack.toInference(); - } - - public QName inputQName() { - return inputQName(operation.toSchemaInferenceStack()); - } - - private static QName inputQName(final SchemaInferenceStack stack) { - final var stmt = stack.currentStatement(); - if (stmt instanceof RpcEffectiveStatement rpc) { - return rpc.input().argument(); - } else if (stmt instanceof ActionEffectiveStatement action) { - return action.input().argument(); - } else { - throw new IllegalStateException(stack + " does not identify an 'rpc' nor an 'action' statement"); - } - } -} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostResult.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostResult.java index 8ce4b5a0c5..6794c9415b 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostResult.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/OperationsPostResult.java @@ -11,26 +11,20 @@ import static java.util.Objects.requireNonNull; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.restconf.server.api.DatabindPath.OperationPath; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; /** * RESTCONF {@code /operations} content for a {@code POST} operation as per * RFC8040 Operation Resource and * RFC8040 Invoke Operation Mode. * - * @param databind Associated {@link DatabindContext} - * @param operation An {@link Inference} pointing to the invoked operation + * @param path associated {@link OperationPath} * @param output Operation output, or {@code null} if output would be empty - * @see OperationsPostPath */ -public record OperationsPostResult( - @NonNull DatabindContext databind, - @NonNull Inference operation, - @Nullable ContainerNode output) implements DatabindAware { +public record OperationsPostResult(@NonNull OperationPath path, @Nullable ContainerNode output) { public OperationsPostResult { - requireNonNull(databind); - requireNonNull(operation); + requireNonNull(path); if (output != null && output.isEmpty()) { output = null; } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/XmlOperationInputBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/XmlOperationInputBody.java index cc84311980..e609d89002 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/XmlOperationInputBody.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/XmlOperationInputBody.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.InputStream; import javax.xml.stream.XMLStreamException; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; +import org.opendaylight.restconf.server.api.DatabindPath.OperationPath; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -27,10 +28,13 @@ public final class XmlOperationInputBody extends OperationInputBody { } @Override - void streamTo(final OperationsPostPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer) + void streamTo(final OperationPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer) throws IOException { + final var stack = path.inference().toSchemaInferenceStack(); + stack.enterDataTree(path.inputStatement().argument()); + try { - XmlParserStream.create(writer, path.databind().xmlCodecs(), path.input()) + XmlParserStream.create(writer, path.databind().xmlCodecs(), stack.toInference()) .parse(UntrustedXML.createXMLStreamReader(inputStream)); } catch (XMLStreamException e) { LOG.debug("Error parsing XML input", e); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/devnotif/SubscribeDeviceNotificationRpc.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/devnotif/SubscribeDeviceNotificationRpc.java index e0518e2bc3..027410f17b 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/devnotif/SubscribeDeviceNotificationRpc.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/devnotif/SubscribeDeviceNotificationRpc.java @@ -79,10 +79,12 @@ public final class SubscribeDeviceNotificationRpc extends RpcImplementation { ErrorType.APPLICATION, ErrorTag.INVALID_VALUE)); } + final var operPath = input.path(); + return streamRegistry.createStream(restconfURI, new DeviceNotificationSource(mountPointService, path), "All YANG notifications occuring on mount point /" - + new ApiPathNormalizer(input.databind()).canonicalize(path).toString()) - .transform(stream -> input.newOperationOutput(ImmutableNodes.newContainerBuilder() + + new ApiPathNormalizer(operPath.databind()).canonicalize(path).toString()) + .transform(stream -> new OperationsPostResult(operPath, ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(SubscribeDeviceNotificationOutput.QNAME)) .withChild(ImmutableNodes.leafNode(DEVICE_NOTIFICATION_STREAM_NAME_NODEID, stream.name())) .build())); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateDataChangeEventSubscriptionRpc.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateDataChangeEventSubscriptionRpc.java index e7aa20bb75..3654b1037c 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateDataChangeEventSubscriptionRpc.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateDataChangeEventSubscriptionRpc.java @@ -108,11 +108,13 @@ public final class CreateDataChangeEventSubscriptionRpc extends RpcImplementatio new RestconfDocumentedException("missing path", ErrorType.APPLICATION, ErrorTag.MISSING_ELEMENT)); } + final var operPath = input.path(); + return streamRegistry.createStream(restconfURI, new DataTreeChangeSource(databindProvider, changeService, datastore, path), "Events occuring in " + datastore + " datastore under /" - + new ApiPathNormalizer(input.databind()).canonicalize(path).toString()) - .transform(stream -> input.newOperationOutput(ImmutableNodes.newContainerBuilder() + + new ApiPathNormalizer(operPath.databind()).canonicalize(path).toString()) + .transform(stream -> new OperationsPostResult(operPath, ImmutableNodes.newContainerBuilder() .withNodeIdentifier(OUTPUT_NODEID) .withChild(ImmutableNodes.leafNode(STREAM_NAME_NODEID, stream.name())) .build())); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/notif/CreateNotificationStreamRpc.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/notif/CreateNotificationStreamRpc.java index af3ba4a7a6..da45ff5fec 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/notif/CreateNotificationStreamRpc.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/streams/notif/CreateNotificationStreamRpc.java @@ -73,7 +73,8 @@ public final class CreateNotificationStreamRpc extends RpcImplementation { .sorted() .collect(ImmutableSet.toImmutableSet()); - final var modelContext = input.databind().modelContext(); + final var operPath = input.path(); + final var modelContext = operPath.databind().modelContext(); final var description = new StringBuilder("YANG notifications matching any of {"); var haveFirst = false; for (var qname : qnames) { @@ -105,7 +106,7 @@ public final class CreateNotificationStreamRpc extends RpcImplementation { return streamRegistry.createStream(restconfURI, new NotificationSource(databindProvider, notificationService, qnames), description.toString()) - .transform(stream -> input.newOperationOutput(ImmutableNodes.newContainerBuilder() + .transform(stream -> new OperationsPostResult(operPath, ImmutableNodes.newContainerBuilder() .withNodeIdentifier(SAL_REMOTE_OUTPUT_NODEID) .withChild(ImmutableNodes.leafNode(STREAM_NAME_NODEID, stream.name())) .build())); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationInput.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationInput.java index 6c5964f3ae..a372d05703 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationInput.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationInput.java @@ -10,32 +10,16 @@ package org.opendaylight.restconf.server.spi; import static java.util.Objects.requireNonNull; 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.restconf.server.api.DatabindPath.OperationPath; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; /** * Input to an operation invocation. */ @NonNullByDefault -public record OperationInput(DatabindContext databind, Inference operation, ContainerNode input) - implements DatabindAware { +public record OperationInput(OperationPath path, ContainerNode input) { public OperationInput { - requireNonNull(databind); - requireNonNull(operation); + requireNonNull(path); requireNonNull(input); } - - /** - * Create an {@link OperationsPostResult} with equal {@link #databind()} and {@link #operation()}. - * - * @param output Output payload - * @return An {@link OperationsPostResult} - */ - public OperationsPostResult newOperationOutput(final @Nullable ContainerNode output) { - return new OperationsPostResult(databind, operation, output); - } } \ No newline at end of file diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractOperationInputBodyTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractOperationInputBodyTest.java index 286b66c0fa..41ce7a3049 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractOperationInputBodyTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractOperationInputBodyTest.java @@ -8,30 +8,37 @@ package org.opendaylight.restconf.nb.rfc8040.databind; import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.restconf.nb.rfc8040.AbstractInstanceIdentifierTest; import org.opendaylight.restconf.server.api.DatabindContext; +import org.opendaylight.restconf.server.api.DatabindPath.Action; +import org.opendaylight.restconf.server.api.DatabindPath.Rpc; import org.opendaylight.restconf.server.api.OperationInputBody; -import org.opendaylight.restconf.server.api.OperationsPostPath; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; +import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifierTest { private static final NodeIdentifier INPUT_NID = new NodeIdentifier(QName.create(CONT_QNAME, "input")); - private static OperationsPostPath RESET_PATH; + private static Action RESET_PATH; @BeforeClass public static final void setupInference() { final var stack = SchemaInferenceStack.ofDataTreePath(IID_SCHEMA, CONT_QNAME, CONT1_QNAME); - stack.enterSchemaTree(RESET_QNAME); - RESET_PATH = new OperationsPostPath(IID_DATABIND, stack.toInference()); + final var action = assertInstanceOf(ActionEffectiveStatement.class, stack.enterSchemaTree(RESET_QNAME)); + + RESET_PATH = new Action(IID_DATABIND, stack.toInference(), YangInstanceIdentifier.of(CONT_QNAME, CONT1_QNAME), + action); } @Test @@ -60,7 +67,7 @@ abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifier final var rpcTest = QName.create("invoke:rpc:module", "2013-12-03", "rpc-test"); final var modelContext = YangParserTestUtils.parseYangResourceDirectory("/invoke-rpc"); final var stack = SchemaInferenceStack.of(modelContext); - stack.enterSchemaTree(rpcTest); + final var rpc = assertInstanceOf(RpcEffectiveStatement.class, stack.enterSchemaTree(rpcTest)); final var body = testRpcModuleInputBody(); @@ -71,7 +78,7 @@ abstract class AbstractOperationInputBodyTest extends AbstractInstanceIdentifier .withChild(ImmutableNodes.leafNode(QName.create(rpcTest, "lf"), "lf-test")) .build()) .build(), - body.toContainerNode(new OperationsPostPath(DatabindContext.ofModel(modelContext), stack.toInference()))); + body.toContainerNode(new Rpc(DatabindContext.ofModel(modelContext), stack.toInference(), rpc))); } abstract OperationInputBody testRpcModuleInputBody(); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java index 7ba967e134..4bfac3b84c 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java @@ -37,6 +37,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker.DataTreeChangeExtension; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.server.api.DatabindContext; +import org.opendaylight.restconf.server.api.DatabindPath; import org.opendaylight.restconf.server.mdsal.MdsalRestconfStreamRegistry; import org.opendaylight.restconf.server.spi.DatabindProvider; import org.opendaylight.restconf.server.spi.OperationInput; @@ -178,6 +179,7 @@ class CreateNotificationStreamRpcTest { stack.enterDataTree(lfQName); builder.withChild(ImmutableNodes.leafNode(lfQName, leafValue)); } - return new OperationInput(databindProvider.currentDatabind(), inference, builder.build()); + return new OperationInput(new DatabindPath.Rpc(databindProvider.currentDatabind(), inference, rpcStmt), + builder.build()); } } -- 2.36.6