From bab56e3f4b3cd485757b8b09a457866b21f7fdb8 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 5 Dec 2022 12:16:21 +0100 Subject: [PATCH] Specialize RPC input/output We can easily guarantee ContainerNodes, let's do that to make things simpler to migrate later. Change-Id: Ic3f41a9d3ad09fdea8baaddfa728584b341e4ee4 Signed-off-by: Robert Varga --- .../mapping/BaseRpcSchemalessTransformer.java | 2 +- .../schema/mapping/NetconfMessageTransformer.java | 8 ++++---- .../sal/connect/netconf/util/NetconfBaseOps.java | 4 ++-- .../netconf/sal/tx/FieldsAwareReadOnlyTxTest.java | 3 +-- .../sal/tx/NetconfDeviceWriteOnlyTxTest.java | 13 ++++++------- .../sal/connect/netconf/sal/tx/ReadOnlyTxTest.java | 3 +-- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseRpcSchemalessTransformer.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseRpcSchemalessTransformer.java index f3a9d010d8..7ab9718c47 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseRpcSchemalessTransformer.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseRpcSchemalessTransformer.java @@ -83,7 +83,7 @@ public class BaseRpcSchemalessTransformer implements MessageTransformer { @Override public DOMRpcResult toRpcResult(final NetconfMessage message, final QName rpc) { - final NormalizedNode normalizedNode; + final ContainerNode normalizedNode; if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpc)) { final Element xmlData = NetconfMessageTransformUtil.getDataSubtree(message.getDocument()); final Document data = XmlUtil.newDocument(); diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java index 779a2cc7c8..3d67ba2abd 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java @@ -404,7 +404,7 @@ public class NetconfMessageTransformer implements MessageTransformer { @Override public synchronized DOMRpcResult toRpcResult(final NetconfMessage message, final QName rpc) { - final NormalizedNode normalizedNode; + final ContainerNode normalizedNode; if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpc)) { normalizedNode = Builders.containerBuilder() .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_NODEID) @@ -437,7 +437,7 @@ public class NetconfMessageTransformer implements MessageTransformer { public DOMActionResult toActionResult(final Absolute action, final NetconfMessage message) { final ActionDefinition actionDefinition = actions.get(action); checkArgument(actionDefinition != null, "Action does not exist: %s", action); - final ContainerNode normalizedNode = (ContainerNode) parseResult(message, action, actionDefinition); + final ContainerNode normalizedNode = parseResult(message, action, actionDefinition); if (normalizedNode == null) { return new SimpleDOMActionResult(List.of()); @@ -446,7 +446,7 @@ public class NetconfMessageTransformer implements MessageTransformer { } } - private NormalizedNode parseResult(final NetconfMessage message, final Absolute operationPath, + private ContainerNode parseResult(final NetconfMessage message, final Absolute operationPath, final OperationDefinition operationDef) { final Optional okResponseElement = XmlElement.fromDomDocument(message.getDocument()) .getOnlyChildElementWithSameNamespaceOptionally("ok"); @@ -480,7 +480,7 @@ public class NetconfMessageTransformer implements MessageTransformer { } catch (XMLStreamException | URISyntaxException | IOException | SAXException e) { throw new IllegalArgumentException(String.format("Failed to parse RPC response %s", element), e); } - return resultHolder.getResult(); + return (ContainerNode) resultHolder.getResult(); } @Beta diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java index 6b6079767c..a537e3651a 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java @@ -220,7 +220,7 @@ public final class NetconfBaseOps { requireNonNull(callback); requireNonNull(datastore); - final NormalizedNode rpcInput; + final ContainerNode rpcInput; if (isFilterPresent(filterPath)) { final DataContainerChild node = transformer.toFilterStructure( Collections.singletonList(FieldsFilter.of(filterPath.get(), fields))); @@ -346,7 +346,7 @@ public final class NetconfBaseOps { final Optional filterPath, final List fields) { requireNonNull(callback); - final NormalizedNode rpcInput; + final ContainerNode rpcInput; if (isFilterPresent(filterPath)) { rpcInput = NetconfMessageTransformUtil.wrap(NETCONF_GET_NODEID, transformer.toFilterStructure( Collections.singletonList(FieldsFilter.of(filterPath.get(), fields)))); diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/FieldsAwareReadOnlyTxTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/FieldsAwareReadOnlyTxTest.java index b9d72762a8..5efa640e8c 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/FieldsAwareReadOnlyTxTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/FieldsAwareReadOnlyTxTest.java @@ -31,14 +31,13 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.common.QName; 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; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class FieldsAwareReadOnlyTxTest { @Mock private DOMRpcService rpc; @Mock - private NormalizedNode mockedNode; + private ContainerNode mockedNode; @Test public void testReadWithFields() { diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java index 60525f13fd..456588279b 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java @@ -50,7 +50,6 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; 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.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; @RunWith(MockitoJUnitRunner.StrictStubs.class) @@ -65,7 +64,7 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest { @Before public void setUp() { final ListenableFuture successFuture = - Futures.immediateFuture(new DefaultDOMRpcResult((NormalizedNode) null)); + Futures.immediateFuture(new DefaultDOMRpcResult((ContainerNode) null)); doReturn(successFuture) .doReturn(Futures.immediateFailedFuture(new IllegalStateException("Failed tx"))) @@ -90,7 +89,7 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest { @Test public void testDiscardChanges() throws InterruptedException { - doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))) + doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((ContainerNode) null))) .when(rpc).invokeRpc(any(QName.class), isNull()); final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), @@ -116,7 +115,7 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest { @Test public void testFailedCommit() throws Exception { - doReturn(Futures.immediateFuture(new DefaultDOMRpcResult((NormalizedNode) null))) + doReturn(Futures.immediateFuture(new DefaultDOMRpcResult((ContainerNode) null))) .doReturn(Futures.immediateFuture(new DefaultDOMRpcResult(RpcResultBuilder.newError(ErrorType.APPLICATION, new ErrorTag("a"), "m")))).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class)); @@ -133,7 +132,7 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest { @Test public void testDiscardChangesNotSentWithoutCandidate() { - doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))) + doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((ContainerNode) null))) .doReturn(FluentFutures.immediateFailedFluentFuture(new IllegalStateException("Failed tx"))) .when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class)); @@ -154,7 +153,7 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest { @Test public void testListenerSuccess() throws Exception { - doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))) + doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((ContainerNode) null))) .when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class)); final WriteCandidateTx tx = new WriteCandidateTx( id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getMountPointContext()), false); @@ -170,7 +169,7 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest { @Test public void testListenerCancellation() throws Exception { - doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))) + doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((ContainerNode) null))) .when(rpc).invokeRpc(any(QName.class), isNull()); final WriteCandidateTx tx = new WriteCandidateTx( id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getMountPointContext()), false); diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/ReadOnlyTxTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/ReadOnlyTxTest.java index f3dc37586b..0eed0a5fdd 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/ReadOnlyTxTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/ReadOnlyTxTest.java @@ -31,14 +31,13 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.common.QName; 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; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class ReadOnlyTxTest { @Mock private DOMRpcService rpc; @Mock - private NormalizedNode mockedNode; + private ContainerNode mockedNode; @Before public void setUp() { -- 2.36.6