Switch default output stream version 13/82313/27
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 29 May 2019 16:17:13 +0000 (18:17 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 8 Jun 2019 01:16:35 +0000 (01:16 +0000)
All versioned callers have been converted to use appropriate
stream versions, this patch bumps the default unversioned stream
to Sodium version.

Since we're changing the serialization format for ExecuteRpc,
make sure we fully embrace writer/reader, so that we get better
instantiation.

JIRA: CONTROLLER-1888
Change-Id: I17deeda1a49394600a5b0f93bd46d3b2c812123c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ForwardingNormalizedNodeDataInput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SodiumNormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SodiumNormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/ExecuteRpc.java

index 97beda3..cc28b03 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 
 import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -29,6 +30,11 @@ abstract class ForwardingNormalizedNodeDataInput extends ForwardingDataInput imp
         return delegate().readYangInstanceIdentifier();
     }
 
+    @Override
+    public final QName readQName() throws IOException {
+        return delegate().readQName();
+    }
+
     @Override
     public final PathArgument readPathArgument() throws IOException {
         return delegate().readPathArgument();
index 1484f73..1a0d6dd 100755 (executable)
@@ -208,7 +208,8 @@ class LithiumNormalizedNodeInputStreamReader extends ForwardingDataInput impleme
         }
     }
 
-    QName readQName() throws IOException {
+    @Override
+    public QName readQName() throws IOException {
         // Read in the same sequence of writing
         String localName = readCodedString();
         String namespace = readCodedString();
index 93eb55c..37152f3 100644 (file)
@@ -10,6 +10,9 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 import com.google.common.annotations.Beta;
 import java.io.DataInput;
 import java.io.IOException;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -32,6 +35,8 @@ public interface NormalizedNodeDataInput extends DataInput {
 
     YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
 
+    @NonNull QName readQName() throws IOException;
+
     PathArgument readPathArgument() throws IOException;
 
     SchemaPath readSchemaPath() throws IOException;
@@ -43,4 +48,8 @@ public interface NormalizedNodeDataInput extends DataInput {
      * @throws IOException if the version cannot be ascertained
      */
     NormalizedNodeStreamVersion getVersion() throws IOException;
+
+    default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
+        return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();
+    }
 }
index dd267a0..681553e 100644 (file)
@@ -12,6 +12,7 @@ import java.io.DataOutput;
 import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -23,6 +24,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  */
 @Beta
 public interface NormalizedNodeDataOutput extends AutoCloseable, DataOutput {
+    void writeQName(@NonNull QName qname) throws IOException;
+
     void writeNormalizedNode(@NonNull NormalizedNode<?, ?> normalizedNode) throws IOException;
 
     void writePathArgument(PathArgument pathArgument) throws IOException;
index a9515d2..3857634 100644 (file)
@@ -23,8 +23,7 @@ import java.io.DataOutput;
  * <p>Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
  * while reading.
  */
-// FIXME: CONTROLLER-1888: switch this to Sodium once we have a corresponding datastore version
-class NormalizedNodeOutputStreamWriter extends LithiumNormalizedNodeOutputStreamWriter {
+class NormalizedNodeOutputStreamWriter extends SodiumNormalizedNodeOutputStreamWriter {
     NormalizedNodeOutputStreamWriter(final DataOutput output) {
         super(output);
     }
index 5f5c0a0..26a6613 100644 (file)
@@ -44,7 +44,7 @@ class SodiumNormalizedNodeOutputStreamWriter extends LithiumNormalizedNodeOutput
     }
 
     @Override
-    protected final void writeQName(final QName qname) throws IOException {
+    public final void writeQName(final QName qname) throws IOException {
         final Integer value = qnameCodeMap.get(qname);
         if (value == null) {
             // Fresh QName, remember it and emit as three strings
index 23fdfdc..c9fb52b 100644 (file)
@@ -18,7 +18,9 @@ import java.io.ObjectOutput;
 import java.io.Serializable;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -78,16 +80,17 @@ public final class ExecuteRpc implements Serializable {
 
         @Override
         public void writeExternal(final ObjectOutput out) throws IOException {
-            // FIXME: QName is a WritableObject
-            out.writeObject(executeRpc.getRpc());
-            SerializationUtils.writeNormalizedNode(out, executeRpc.getInputNormalizedNode());
+            try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) {
+                stream.writeQName(executeRpc.getRpc());
+                stream.writeOptionalNormalizedNode(executeRpc.getInputNormalizedNode());
+            }
         }
 
         @Override
         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
-            // FIXME: QName is a WritableObject
-            QName qname = (QName) in.readObject();
-            executeRpc = new ExecuteRpc(SerializationUtils.readNormalizedNode(in).orElse(null), qname);
+            final NormalizedNodeDataInput stream = NormalizedNodeInputOutput.newDataInput(in);
+            final QName qname = stream.readQName();
+            executeRpc = new ExecuteRpc(stream.readOptionalNormalizedNode().orElse(null), qname);
         }
 
         private Object readResolve() {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.