Update RPC invocation to take ContainerNode 96/89296/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Apr 2020 00:07:59 +0000 (02:07 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 23 Apr 2020 06:12:21 +0000 (06:12 +0000)
Our acceptance of NormalizedNode here is misleading, we should be
taking a ContainerNode, just as actions do.

Change-Id: I1c24a24a8f42decd4a000b01805b51913fe05bf2
JIRA: MDSAL-303
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcImplementationAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDOMRpcResultFuture.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMRpcImplementation.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMRpcResult.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMRpcService.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMRpcRouter.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TestUtils.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/DefaultDOMRpcResult.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMRpcImplementation.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMRpcResult.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMRpcService.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/DefaultDOMRpcResultTest.java

index 35b2d8b97022946855378de8f941818b61aa4abe..bd8cdc20afbdbc3b1d7ad561ccc200355f868056 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 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.model.api.SchemaPath;
 
 final class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation {
@@ -66,7 +65,7 @@ final class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation {
     }
 
     @Override
-    public ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
+    public ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
         final SchemaPath schemaPath = rpc.getType();
         final CurrentAdapterSerializer serializer = adapterContext.currentSerializer();
         final DataObject bindingInput = input != null ? deserialize(serializer, schemaPath, input) : null;
@@ -80,12 +79,12 @@ final class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation {
     }
 
     private DataObject deserialize(final CurrentAdapterSerializer serializer, final SchemaPath rpcPath,
-            final NormalizedNode<?, ?> input) {
+            final ContainerNode input) {
         if (ENABLE_CODEC_SHORTCUT && input instanceof BindingLazyContainerNode) {
             return ((BindingLazyContainerNode<?>) input).getDataObject();
         }
         final SchemaPath inputSchemaPath = rpcPath.createChild(inputQname);
-        return serializer.fromNormalizedNodeRpcData(inputSchemaPath, (ContainerNode) input);
+        return serializer.fromNormalizedNodeRpcData(inputSchemaPath, input);
     }
 
     private ListenableFuture<RpcResult<?>> invoke(final SchemaPath schemaPath, final DataObject input) {
index 426ab7559da437ad776d34471531747c0468a3e1..7d366dd0a8be6b9d8b7c9b88a7d6fb2c1d8831c6 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 final class LazyDOMRpcResultFuture extends AbstractFuture<DOMRpcResult> implements BindingRpcFutureAware {
     private static final ExceptionMapper<DOMRpcException> DOM_RPC_EX_MAPPER = new ExceptionMapper<>("rpc",
@@ -117,7 +117,7 @@ final class LazyDOMRpcResultFuture extends AbstractFuture<DOMRpcResult> implemen
                 return new DefaultDOMRpcResult(codec.toNormalizedNodeRpcData((DataContainer) inputData));
             }
 
-            return new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
+            return new DefaultDOMRpcResult((ContainerNode) null);
         }
         return new DefaultDOMRpcResult(input.getErrors());
     }
index 357cb3bf21831d517af354d046ffe444e4eea8a9..7074eef968ecae2329c154a6652ddb1a573a2287 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.mdsal.dom.api;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 /**
  * Interface implemented by an individual RPC implementation. This API allows for dispatch
@@ -28,7 +28,7 @@ public interface DOMRpcImplementation {
      * @throws NullPointerException if any argument is null
      */
     @NonNull ListenableFuture<? extends DOMRpcResult> invokeRpc(@NonNull DOMRpcIdentifier rpc,
-            @NonNull NormalizedNode<?, ?> input);
+            @NonNull ContainerNode input);
 
     /**
      * Return the relative invocation cost of this implementation. Default implementation return 0.
index 5a0fd1acc087c5f85e499b6b0f62319c25880614..66feb0f68d626db566b73b5b0ae33afc6cdd2237 100644 (file)
@@ -11,7 +11,7 @@ import java.util.Collection;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 /**
  * Interface defining a result of an RPC call.
@@ -33,5 +33,5 @@ public interface DOMRpcResult {
      * @return Invocation result, null if the operation has not produced a result. This might
      *         be the case if the operation does not produce a result, or if it failed.
      */
-    @Nullable NormalizedNode<?, ?> getResult();
+    @Nullable ContainerNode getResult();
 }
index a6b103cb4338f84ad74ec3c3f3d416adb78c8f8e..d86b29c6e70fb59cba060204c67acf843a6765fe 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.mdsal.dom.api;
 import com.google.common.util.concurrent.ListenableFuture;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
@@ -30,14 +30,14 @@ public interface DOMRpcService extends DOMService {
      *         of {@link DOMRpcException} reporting a transport error.
      */
     @NonNull ListenableFuture<? extends DOMRpcResult> invokeRpc(@NonNull SchemaPath type,
-            @NonNull NormalizedNode<?, ?> input);
+            @NonNull ContainerNode input);
 
     /**
      * Register a {@link DOMRpcAvailabilityListener} with this service to receive notifications
      * about RPC implementations becoming (un)available. The listener will be invoked with the
      * current implementations reported and will be kept uptodate as implementations come and go.
      * Users should note that using a listener does not necessarily mean that
-     * {@link #invokeRpc(SchemaPath, NormalizedNode)} will not report a failure due to
+     * {@link #invokeRpc(SchemaPath, ContainerNode)} will not report a failure due to
      * {@link DOMRpcImplementationNotAvailableException} and need to be ready to handle it.
      * Implementations are encouraged to take reasonable precautions to prevent this scenario from
      * occurring.
index f1fa5a70de1cf0f8a4bb03f6a4af3ea049732181..622a8b3c1597dc34f5e8f54ddd415f6d5d4c61cf 100644 (file)
@@ -435,8 +435,7 @@ public final class DOMRpcRouter extends AbstractRegistration
 
     private final class RpcServiceFacade implements DOMRpcService {
         @Override
-        public ListenableFuture<? extends DOMRpcResult> invokeRpc(final SchemaPath type,
-                final NormalizedNode<?, ?> input) {
+        public ListenableFuture<? extends DOMRpcResult> invokeRpc(final SchemaPath type, final ContainerNode input) {
             final AbstractDOMRpcRoutingTableEntry entry = (AbstractDOMRpcRoutingTableEntry) routingTable.getEntry(type);
             if (entry == null) {
                 return Futures.immediateFailedFuture(
@@ -499,7 +498,7 @@ public final class DOMRpcRouter extends AbstractRegistration
         }
 
         static ListenableFuture<? extends DOMRpcResult> invoke(final AbstractDOMRpcRoutingTableEntry entry,
-                final NormalizedNode<?, ?> input) {
+                final ContainerNode input) {
             if (entry instanceof UnknownDOMRpcRoutingTableEntry) {
                 return Futures.immediateFailedFuture(
                     new DOMRpcImplementationNotAvailableException("SchemaPath %s is not resolved to an RPC",
@@ -515,7 +514,7 @@ public final class DOMRpcRouter extends AbstractRegistration
         }
 
         private static ListenableFuture<? extends DOMRpcResult> invokeRoutedRpc(
-                final RoutedDOMRpcRoutingTableEntry entry, final NormalizedNode<?, ?> input) {
+                final RoutedDOMRpcRoutingTableEntry entry, final ContainerNode input) {
             final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input,
                 entry.getRpcId().getContextReference());
 
@@ -561,7 +560,7 @@ public final class DOMRpcRouter extends AbstractRegistration
         }
 
         private static ListenableFuture<? extends DOMRpcResult> invokeGlobalRpc(
-                final GlobalDOMRpcRoutingTableEntry entry, final NormalizedNode<?, ?> input) {
+                final GlobalDOMRpcRoutingTableEntry entry, final ContainerNode input) {
             return entry.getImplementations(YangInstanceIdentifier.empty()).get(0).invokeRpc(entry.getRpcId(), input);
         }
     }
index 8fc8dbf454d90c2e425ff32e9444f3b0902b22dc..68a3d2d933d153f6f8d42fe0db3a351a3c7ac1c0 100644 (file)
@@ -20,9 +20,9 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
@@ -49,12 +49,12 @@ abstract class TestUtils {
             .withChild(TOP_LEVEL_LIST_NODE)
             .build();
 
-    static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
+    static final ContainerNode TEST_CONTAINER = Builders.containerBuilder()
             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
             .withChild(OUTER_LIST)
             .build();
 
-    static final NormalizedNode<?, ?> TEST_CHILD = Builders.containerBuilder()
+    static final ContainerNode TEST_CHILD = Builders.containerBuilder()
             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
             .withChild(CHILD_LIST)
             .build();
@@ -74,7 +74,7 @@ abstract class TestUtils {
         }
 
         @Override
-        public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
+        public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
             requireNonNull(input);
             return unknownRpc;
         }
index cfc47d090d65939263842bc8e497b03b39676d3e..87eb55c3c7fab8ff17b5d065ac2daff2dd616657 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 /**
  * Utility class implementing {@link DefaultDOMRpcResult}.
@@ -32,10 +32,10 @@ public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Seria
     private static final long serialVersionUID = 1L;
 
     @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Interfaces do not specify Serializable")
-    private final @Nullable NormalizedNode<?, ?> result;
+    private final @Nullable ContainerNode result;
     private final Collection<? extends RpcError> errors;
 
-    public DefaultDOMRpcResult(final NormalizedNode<?, ?> result, final RpcError... errors) {
+    public DefaultDOMRpcResult(final ContainerNode result, final RpcError... errors) {
         this(result, asCollection(errors));
     }
 
@@ -43,11 +43,11 @@ public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Seria
         this(null, asCollection(errors));
     }
 
-    public DefaultDOMRpcResult(final @Nullable NormalizedNode<?, ?> result) {
+    public DefaultDOMRpcResult(final @Nullable ContainerNode result) {
         this(result, Collections.emptyList());
     }
 
-    public DefaultDOMRpcResult(final @Nullable NormalizedNode<?, ?> result,
+    public DefaultDOMRpcResult(final @Nullable ContainerNode result,
             final Collection<? extends RpcError> errors) {
         this.result = result;
         this.errors = requireNonNull(errors);
@@ -67,7 +67,7 @@ public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Seria
     }
 
     @Override
-    public @Nullable NormalizedNode<?, ?> getResult() {
+    public @Nullable ContainerNode getResult() {
         return result;
     }
 
index 311864f45a8f8fd4a4fc0c08e246145e6633d078..fbc26cf11f2c2976847348ae6275ea3d04cdd7c3 100644 (file)
@@ -13,19 +13,17 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 /**
- * Utility implementation which implements {@link DOMRpcImplementation} by forwarding it to
- * a backing delegate.
+ * Utility implementation which implements {@link DOMRpcImplementation} by forwarding it to a backing delegate.
  */
 public abstract class ForwardingDOMRpcImplementation extends ForwardingObject implements DOMRpcImplementation {
     @Override
     protected abstract @NonNull DOMRpcImplementation delegate();
 
     @Override
-    public ListenableFuture<? extends DOMRpcResult> invokeRpc(final DOMRpcIdentifier type,
-            final NormalizedNode<?, ?> input) {
+    public ListenableFuture<? extends DOMRpcResult> invokeRpc(final DOMRpcIdentifier type, final ContainerNode input) {
         return delegate().invokeRpc(type, input);
     }
 }
index 0b47282278d81a5775fca74ba67e4494ab043fb7..429fb9a03d99552bc0e828a8403e1d6ade9768e9 100644 (file)
@@ -13,7 +13,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 /**
  * Utility class which implements {@link DOMRpcResult} by forwarding all methods
@@ -30,7 +30,7 @@ public abstract class ForwardingDOMRpcResult extends ForwardingObject implements
     }
 
     @Override
-    public @Nullable NormalizedNode<?, ?> getResult() {
+    public @Nullable ContainerNode getResult() {
         return delegate().getResult();
     }
 }
index e1f51292eeebc0301334216f8c331df0e0dc6651..7fa38d1e10b57f5c595f38ea8f8285b9a0ebbbf8 100644 (file)
@@ -14,7 +14,7 @@ import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
@@ -25,7 +25,7 @@ public abstract class ForwardingDOMRpcService extends ForwardingObject implement
     protected abstract @NonNull DOMRpcService delegate();
 
     @Override
-    public ListenableFuture<? extends DOMRpcResult> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
+    public ListenableFuture<? extends DOMRpcResult> invokeRpc(final SchemaPath type, final ContainerNode input) {
         return delegate().invokeRpc(type, input);
     }
 
index e6a41935ec9b56cbf82dbbddeac8856d2c51123f..71258d0d92257a1d6346e9434bb9177c8d60c893 100644 (file)
@@ -15,14 +15,13 @@ import static org.mockito.Mockito.mock;
 import java.util.Collections;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 
 public class DefaultDOMRpcResultTest {
-
     @Test
     public void basicTest() throws Exception {
         RpcError rpcError = mock(RpcError.class);
-        NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
+        ContainerNode normalizedNode = mock(ContainerNode.class);
         DefaultDOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(normalizedNode, rpcError);
         assertEquals(normalizedNode, defaultDOMRpcResult.getResult());
         assertTrue(defaultDOMRpcResult.getErrors().contains(rpcError));