Bump datastore version 11/82311/21
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 29 May 2019 14:59:01 +0000 (16:59 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 8 Jun 2019 01:06:07 +0000 (01:06 +0000)
This bumps the ask-based protocol datastore version, so that
SODIUM_VERSION is using Sodium NormalizedNode{Input,Output}.

JIRA: CONTROLLER-1888
Change-Id: Ib4ad1c27566179db958ad7776f81417ab99a78cf
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/SerializationUtils.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataStoreVersions.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/AbstractRead.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadDataReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/VersionedExternalizableMessage.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModification.java

index 076e96c..6735cdb 100644 (file)
@@ -51,6 +51,19 @@ public final class SerializationUtils {
         }
     }
 
+    public static void writeNormalizedNode(final DataOutput out, final NormalizedNodeStreamVersion version,
+            final @Nullable NormalizedNode<?, ?> node) throws IOException {
+        if (node != null) {
+            out.writeBoolean(true);
+
+            try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out, version)) {
+                stream.writeNormalizedNode(node);
+            }
+        } else {
+            out.writeBoolean(false);
+        }
+    }
+
     public static YangInstanceIdentifier readPath(final DataInput in) throws IOException {
         return NormalizedNodeInputOutput.newDataInput(in).readYangInstanceIdentifier();
     }
@@ -62,6 +75,13 @@ public final class SerializationUtils {
         }
     }
 
+    public static void writePath(final DataOutput out, final NormalizedNodeStreamVersion version,
+            final @NonNull YangInstanceIdentifier path) throws IOException {
+        try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out, version)) {
+            stream.writeYangInstanceIdentifier(path);
+        }
+    }
+
     public static <T> void readNodeAndPath(final DataInput in, final T instance, final Applier<T> applier)
             throws IOException {
         final NormalizedNodeDataInput stream = NormalizedNodeInputOutput.newDataInput(in);
index 0b4115a..742c31f 100644 (file)
@@ -8,16 +8,21 @@
 package org.opendaylight.controller.cluster.datastore;
 
 /**
- * Defines version numbers.
+ * Defines version numbers where ask-based protocol is concerned.
  *
  * @author Thomas Pantelis
  */
-public interface DataStoreVersions {
-    short BASE_HELIUM_VERSION = 0;
-    short HELIUM_1_VERSION = 1;
-    short HELIUM_2_VERSION = 2;
-    short LITHIUM_VERSION = 3;
-    short BORON_VERSION = 5;
-    short FLUORINE_VERSION = 9;
-    short CURRENT_VERSION = FLUORINE_VERSION;
+public final class DataStoreVersions {
+    public static final short BASE_HELIUM_VERSION = 0;
+    public static final short HELIUM_1_VERSION = 1;
+    public static final short HELIUM_2_VERSION = 2;
+    public static final short LITHIUM_VERSION = 3;
+    public static final short BORON_VERSION = 5;
+    public static final short FLUORINE_VERSION = 9;
+    public static final short SODIUM_VERSION = 10;
+    public static final short CURRENT_VERSION = SODIUM_VERSION;
+
+    private DataStoreVersions() {
+
+    }
 }
index acd35d2..dd4c9b8 100644 (file)
@@ -49,7 +49,7 @@ public abstract class AbstractRead<T> extends VersionedExternalizableMessage {
     @Override
     public void writeExternal(final ObjectOutput out) throws IOException {
         super.writeExternal(out);
-        SerializationUtils.writePath(out, path);
+        SerializationUtils.writePath(out, getStreamVersion(), path);
     }
 
     public AbstractRead<T> asVersion(final short version) {
index 5c00cf1..91d38cc 100644 (file)
@@ -40,7 +40,7 @@ public class ReadDataReply extends VersionedExternalizableMessage {
     @Override
     public void writeExternal(final ObjectOutput out) throws IOException {
         super.writeExternal(out);
-        SerializationUtils.writeNormalizedNode(out, normalizedNode);
+        SerializationUtils.writeNormalizedNode(out, getStreamVersion(), normalizedNode);
     }
 
     public static ReadDataReply fromSerializable(final Object serializable) {
index 781580a..9eff5af 100644 (file)
@@ -11,7 +11,9 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
 
 /**
  * Abstract base class for a versioned Externalizable message.
@@ -26,7 +28,7 @@ public abstract class VersionedExternalizableMessage implements Externalizable,
     public VersionedExternalizableMessage() {
     }
 
-    public VersionedExternalizableMessage(short version) {
+    public VersionedExternalizableMessage(final short version) {
         this.version = version <= DataStoreVersions.CURRENT_VERSION ? version : DataStoreVersions.CURRENT_VERSION;
     }
 
@@ -34,13 +36,18 @@ public abstract class VersionedExternalizableMessage implements Externalizable,
         return version;
     }
 
+    protected final @NonNull NormalizedNodeStreamVersion getStreamVersion() {
+        return version < DataStoreVersions.SODIUM_VERSION
+                ? NormalizedNodeStreamVersion.LITHIUM : NormalizedNodeStreamVersion.SODIUM;
+    }
+
     @Override
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
         version = in.readShort();
     }
 
     @Override
-    public void writeExternal(ObjectOutput out) throws IOException {
+    public void writeExternal(final ObjectOutput out) throws IOException {
         out.writeShort(version);
     }
 
index 79e3b14..ba05f27 100644 (file)
@@ -5,10 +5,11 @@
  * 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.controller.cluster.datastore.modification;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
@@ -65,8 +66,7 @@ public class MutableCompositeModification extends VersionedExternalizableMessage
      * @param modification the modification to add.
      */
     public void addModification(final Modification modification) {
-        Preconditions.checkNotNull(modification);
-        modifications.add(modification);
+        modifications.add(requireNonNull(modification));
     }
 
     public void addModifications(final Iterable<Modification> newMods) {
@@ -119,7 +119,7 @@ public class MutableCompositeModification extends VersionedExternalizableMessage
         final int size = modifications.size();
         out.writeInt(size);
         if (size > 0) {
-            try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) {
+            try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out, getStreamVersion())) {
                 for (Modification mod : modifications) {
                     out.writeByte(mod.getType());
                     mod.writeTo(stream);
@@ -129,7 +129,7 @@ public class MutableCompositeModification extends VersionedExternalizableMessage
     }
 
     public static MutableCompositeModification fromSerializable(final Object serializable) {
-        Preconditions.checkArgument(serializable instanceof MutableCompositeModification);
+        checkArgument(serializable instanceof MutableCompositeModification);
         return (MutableCompositeModification)serializable;
     }
 

©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.