Update DOMRpcResult a bit 71/102571/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Oct 2022 12:16:23 +0000 (14:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Oct 2022 16:36:07 +0000 (18:36 +0200)
Use ContainerNode for result value and replace getErrors()/getResult()
with errors()/result().

This cleans up parlance a bit and makes the object model actually match
YANG RPCs.

JIRA: MDSAL-541
Change-Id: I0b1c0456385fd64eba06aa90580a7b56a5be0a86
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDOMRpcResultFuture.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcIntegrationTest.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal500Test.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMRpcResult.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/ForwardingDOMRpcResult.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/DefaultDOMRpcResultTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMRpcResultTest.java

index b49b2fa9d9e2a086a4ab55aff25552f0aecb009e..0c272f57aa55ff3998873bdd08b7c7be0c5646ef 100644 (file)
@@ -24,7 +24,6 @@ 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;
 
 final class LazyDOMRpcResultFuture extends AbstractFuture<DOMRpcResult> implements BindingRpcFutureAware {
     private static final ExceptionMapper<DOMRpcException> DOM_RPC_EX_MAPPER = new ExceptionMapper<>("rpc",
@@ -42,7 +41,7 @@ final class LazyDOMRpcResultFuture extends AbstractFuture<DOMRpcResult> implemen
 
     private LazyDOMRpcResultFuture(final ListenableFuture<RpcResult<?>> delegate,
             final BindingNormalizedNodeSerializer codec) {
-        this.bindingFuture = requireNonNull(delegate, "delegate");
+        bindingFuture = requireNonNull(delegate, "delegate");
         this.codec = requireNonNull(codec, "codec");
     }
 
@@ -112,12 +111,9 @@ final class LazyDOMRpcResultFuture extends AbstractFuture<DOMRpcResult> implemen
 
     private DOMRpcResult transform(final RpcResult<?> input) {
         if (input.isSuccessful()) {
-            final Object inputData = input.getResult();
-            if (inputData instanceof DataContainer) {
-                return new DefaultDOMRpcResult(codec.toNormalizedNodeRpcData((DataContainer) inputData));
-            }
-
-            return new DefaultDOMRpcResult((NormalizedNode) null);
+            final var value = input.getResult() instanceof DataContainer container
+                ? codec.toNormalizedNodeRpcData(container) : null;
+            return new DefaultDOMRpcResult(value);
         }
         return new DefaultDOMRpcResult(input.getErrors());
     }
index 2421a8baa08bf4ae6eb42b0a572a023978558c51..5c2ab06080262c85404f1ff2039363bafa456f63 100644 (file)
@@ -146,7 +146,7 @@ class RpcServiceAdapter implements InvocationHandler {
         private ListenableFuture<RpcResult<?>> transformFuture(final ListenableFuture<? extends DOMRpcResult> domFuture,
                 final BindingNormalizedNodeSerializer resultCodec) {
             return Futures.transform(domFuture, input -> {
-                final NormalizedNode domData = input.getResult();
+                final NormalizedNode domData = input.value();
                 final DataObject bindingResult;
                 if (domData != null) {
                     bindingResult = resultCodec.fromNormalizedNodeRpcData(outputPath, (ContainerNode) domData);
@@ -154,7 +154,7 @@ class RpcServiceAdapter implements InvocationHandler {
                     bindingResult = null;
                 }
 
-                return RpcResultUtil.rpcResultFromDOM(input.getErrors(), bindingResult);
+                return RpcResultUtil.rpcResultFromDOM(input.errors(), bindingResult);
             }, MoreExecutors.directExecutor());
         }
     }
index f56b299a3fbc6ada335c13b6d1d9dc29a9bff89d..815315efc522f70914bae8a2f014a97637d2e621 100644 (file)
@@ -94,7 +94,7 @@ public class BindingDOMRpcIntegrationTest {
         ContainerNode biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
         DOMRpcResult domResult = biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput).get(5, TimeUnit.SECONDS);
         assertNotNull(domResult);
-        assertNotNull(domResult.getResult());
+        assertNotNull(domResult.value());
         assertTrue("Binding KnockKnock service was not invoked",
                 knockRpcImpl.getReceivedKnocks().containsKey(BA_NODE_ID));
         assertEquals(baKnockKnockInput, knockRpcImpl.getReceivedKnocks().get(BA_NODE_ID).iterator().next());
@@ -162,7 +162,7 @@ public class BindingDOMRpcIntegrationTest {
 
         OpendaylightKnockKnockRpcServiceImpl setKnockKnockResult(
                 final ListenableFuture<RpcResult<KnockKnockOutput>> kkOutput) {
-            this.knockKnockResult = kkOutput;
+            knockKnockResult = kkOutput;
             return this;
         }
 
index 3069084eb99e2ae9b6199e5f81d2f5bf1bcd7a78..bc54e670eaeb1bcae19f415df417f25feb2aa716 100644 (file)
@@ -86,7 +86,7 @@ public class Mdsal500Test {
         ContainerNode biSwitchInput = toDOMSwitchInput(baSwitchInput);
         DOMRpcResult domResult = biRpcService.invokeRpc(SWITCH_QNAME, biSwitchInput).get(5, TimeUnit.SECONDS);
         assertNotNull(domResult);
-        assertNotNull(domResult.getResult());
+        assertNotNull(domResult.value());
         assertTrue("Binding KnockKnock service was not invoked",
                 switchRpcImpl.getReceivedSwitch().containsKey(FOO));
         assertEquals(baSwitchInput, switchRpcImpl.getReceivedSwitch().get(FOO).iterator().next());
@@ -146,7 +146,7 @@ public class Mdsal500Test {
         private final Multimap<String, SwitchInput> receivedSwitch = HashMultimap.create();
 
         Mdsal500ServiceImpl setSwitchResult(final ListenableFuture<RpcResult<SwitchOutput>> switchOutput) {
-            this.switchResult = switchOutput;
+            switchResult = switchOutput;
             return this;
         }
 
index 735340e60a0e965881b853ecad026eee65c26991..f6aa3484a781b0935f3f34f5b0a39eeec9498888 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.
@@ -19,19 +19,42 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 @NonNullByDefault
 public interface DOMRpcResult {
     /**
-     * Returns a set of errors and warnings which occurred during processing
-     * the call.
+     * Returns a set of errors and warnings which occurred during processing the call.
      *
-     * @return a Collection of {@link RpcError}, guaranteed to be non-null. In case
-     *         no errors are reported, an empty collection is returned.
+     * @return a Collection of {@link RpcError}, guaranteed to be non-null. In case no errors are reported, an empty
+     *         collection is returned.
+     * @deprecated Use {@link #errors()} instead.
      */
-    Collection<? extends RpcError> getErrors();
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default Collection<? extends RpcError> getErrors() {
+        return errors();
+    }
+
+    /**
+     * Returns a set of errors and warnings which occurred during processing the call.
+     *
+     * @return a Collection of {@link RpcError}, guaranteed to be non-null. In case no errors are reported, an empty
+     *         collection is returned.
+     */
+    Collection<? extends RpcError> errors();
 
     /**
      * Returns the value result of the call or null if no result is available.
      *
-     * @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.
+     * @return Invocation result, {@code 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.
+     * @deprecated Use {@link #value()} instead.
+     */
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @Nullable ContainerNode getResult() {
+        return value();
+    }
+
+    /**
+     * Returns the value result of the call or {code null} if no result is available.
+     *
+     * @return Invocation result, {@code 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 value();
 }
index ab83d863cf6847c57cc57dbd7b96f0880c8b4f54..7974cc1582d66d0eee6bc2919943fb47e79d5af2 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}.
@@ -33,25 +33,24 @@ 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;
     // FIXME: a plain Collection is bad for equality
     private final Collection<? extends RpcError> errors;
 
-    public DefaultDOMRpcResult(final NormalizedNode result, final RpcError... errors) {
-        this(result, List.of(errors));
+    public DefaultDOMRpcResult(final ContainerNode value, final RpcError... errors) {
+        this(value, List.of(errors));
     }
 
     public DefaultDOMRpcResult(final RpcError... errors) {
         this(null, List.of(errors));
     }
 
-    public DefaultDOMRpcResult(final @Nullable NormalizedNode result) {
+    public DefaultDOMRpcResult(final @Nullable ContainerNode result) {
         this(result, List.of());
     }
 
-    public DefaultDOMRpcResult(final @Nullable NormalizedNode result,
-            final Collection<? extends RpcError> errors) {
-        this.result = result;
+    public DefaultDOMRpcResult(final @Nullable ContainerNode value, final Collection<? extends RpcError> errors) {
+        result = value;
         this.errors = requireNonNull(errors);
     }
 
@@ -60,12 +59,12 @@ public final class DefaultDOMRpcResult implements DOMRpcResult, Immutable, Seria
     }
 
     @Override
-    public Collection<? extends RpcError> getErrors() {
+    public Collection<? extends RpcError> errors() {
         return errors;
     }
 
     @Override
-    public @Nullable NormalizedNode getResult() {
+    public @Nullable ContainerNode value() {
         return result;
     }
 
index e96f822227c6ad53144122ab139269d6e02e6ca8..d9f38fdc08f1a040e99ed136eb9eb8400d624a7f 100644 (file)
@@ -9,28 +9,26 @@ package org.opendaylight.mdsal.dom.spi;
 
 import com.google.common.collect.ForwardingObject;
 import java.util.Collection;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
 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
  * to a backing instance.
  */
-@NonNullByDefault
 public abstract class ForwardingDOMRpcResult extends ForwardingObject implements DOMRpcResult {
     @Override
-    protected abstract DOMRpcResult delegate();
+    protected abstract @NonNull DOMRpcResult delegate();
 
     @Override
-    public Collection<? extends RpcError> getErrors() {
-        return delegate().getErrors();
+    public Collection<? extends RpcError> errors() {
+        return delegate().errors();
     }
 
     @Override
-    public @Nullable NormalizedNode getResult() {
-        return delegate().getResult();
+    public ContainerNode value() {
+        return delegate().value();
     }
 }
index a8dc5931f4c1d8abdc8816deba377d4bae926ae3..bbb8ad0b20b537bab6b7670121927d0e385325dd 100644 (file)
@@ -12,23 +12,22 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
-import java.util.Collections;
+import java.util.List;
 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 {
+    public void basicTest() {
         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));
-        assertTrue(new DefaultDOMRpcResult(normalizedNode).getErrors().isEmpty());
-        assertTrue(new DefaultDOMRpcResult().getErrors().isEmpty());
-        assertTrue(new DefaultDOMRpcResult(Collections.emptyList()).getErrors().isEmpty());
+        assertEquals(normalizedNode, defaultDOMRpcResult.value());
+        assertTrue(defaultDOMRpcResult.errors().contains(rpcError));
+        assertTrue(new DefaultDOMRpcResult(normalizedNode).errors().isEmpty());
+        assertTrue(new DefaultDOMRpcResult().errors().isEmpty());
+        assertTrue(new DefaultDOMRpcResult(List.of()).errors().isEmpty());
         assertEquals(defaultDOMRpcResult.hashCode(), new DefaultDOMRpcResult(normalizedNode, rpcError).hashCode());
         assertTrue(new DefaultDOMRpcResult(normalizedNode, rpcError).equals(defaultDOMRpcResult));
         assertTrue(defaultDOMRpcResult.equals(defaultDOMRpcResult));
index 1f19b4e3700ddfbf2a78a83487d1d3f6667d789b..1f4b6b295d8004aa090fe4b4228a40a54e84307c 100644 (file)
@@ -19,21 +19,21 @@ import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ForwardingDOMRpcResultTest extends ForwardingDOMRpcResult {
     @Mock(name = "domRpcResult")
-    public DOMRpcResult domRpcResult;
+    public DOMRpcResult delegate;
 
     @Test
     public void basicTest() throws Exception {
-        doReturn(null).when(domRpcResult).getErrors();
-        this.getErrors();
-        verify(domRpcResult).getErrors();
+        doReturn(null).when(delegate).errors();
+        errors();
+        verify(delegate).errors();
 
-        doReturn(null).when(domRpcResult).getResult();
-        this.getResult();
-        verify(domRpcResult).getResult();
+        doReturn(null).when(delegate).value();
+        value();
+        verify(delegate).value();
     }
 
     @Override
     protected DOMRpcResult delegate() {
-        return domRpcResult;
+        return delegate;
     }
 }
\ No newline at end of file