Bump cds-access-api ABIVersion 12/82312/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 29 May 2019 15:33:08 +0000 (17:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 29 May 2019 18:05:08 +0000 (20:05 +0200)
In order to take advantage of improvements to NormalizedNode stream,
we need to declare a new ABI version, which will actually use
the new stream version.

JIRA: CONTROLLER-1888
Change-Id: I458a24586888e0b2fcc1c636e16d0b8e9e6e681f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequestProxyV1.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessProxyV1.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Message.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessTest.java

index 3eddf3e..bbea1a9 100644 (file)
@@ -15,6 +15,7 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
 import org.opendaylight.yangtools.concepts.WritableObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,19 +33,45 @@ public enum ABIVersion implements WritableObject {
      * Version which is older than any other version. This version exists purely for testing purposes.
      */
     @VisibleForTesting
-    TEST_PAST_VERSION(0),
+    TEST_PAST_VERSION(0) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            throw new UnsupportedOperationException();
+        }
+    },
 
     /**
      * Initial ABI version, as shipped with Boron Simultaneous release.
      */
     // We seed the initial version to be the same as DataStoreVersions.BORON-VERSION for compatibility reasons.
-    BORON(5),
+    BORON(5) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            return NormalizedNodeStreamVersion.LITHIUM;
+        }
+    },
+
+    /**
+     * Revised ABI version. The messages remain the same as {@link #BORON}, but messages bearing QNames in any shape
+     * are using {@link NormalizedNodeStreamVersion#SODIUM}, which improves encoding.
+     */
+    SODIUM(6) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            return NormalizedNodeStreamVersion.SODIUM;
+        }
+    },
 
     /**
      * Version which is newer than any other version. This version exists purely for testing purposes.
      */
     @VisibleForTesting
-    TEST_FUTURE_VERSION(65535);
+    TEST_FUTURE_VERSION(65535) {
+        @Override
+        public NormalizedNodeStreamVersion getStreamVersion() {
+            throw new UnsupportedOperationException();
+        }
+    };
 
     private static final Logger LOG = LoggerFactory.getLogger(ABIVersion.class);
 
@@ -71,7 +98,7 @@ public enum ABIVersion implements WritableObject {
      * @return Current {@link ABIVersion}
      */
     public static @NonNull ABIVersion current() {
-        return BORON;
+        return SODIUM;
     }
 
     /**
@@ -93,8 +120,10 @@ public enum ABIVersion implements WritableObject {
                 throw new PastVersionException(value, BORON);
             case 5:
                 return BORON;
+            case 6:
+                return SODIUM;
             default:
-                throw new FutureVersionException(value, BORON);
+                throw new FutureVersionException(value, SODIUM);
         }
     }
 
@@ -103,6 +132,13 @@ public enum ABIVersion implements WritableObject {
         out.writeShort(value);
     }
 
+    /**
+     * Return the NormalizedNode stream version corresponding to this particular ABI.
+     *
+     * @return Stream Version to use for this ABI version
+     */
+    public abstract @NonNull NormalizedNodeStreamVersion getStreamVersion();
+
     /**
      * Read an {@link ABIVersion} from a {@link DataInput}. This method is provided for callers which do not have
      * a recovery strategy for dealing with unsupported versions.
index bafa3d9..16049fb 100644 (file)
@@ -14,6 +14,7 @@ import java.io.ObjectOutput;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 /**
@@ -27,7 +28,9 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 abstract class AbstractReadPathTransactionRequestProxyV1<T extends AbstractReadPathTransactionRequest<T>>
         extends AbstractReadTransactionRequestProxyV1<T> {
     private static final long serialVersionUID = 1L;
+
     private YangInstanceIdentifier path;
+    private transient NormalizedNodeStreamVersion streamVersion;
 
     protected AbstractReadPathTransactionRequestProxyV1() {
         // For Externalizable
@@ -36,12 +39,13 @@ abstract class AbstractReadPathTransactionRequestProxyV1<T extends AbstractReadP
     AbstractReadPathTransactionRequestProxyV1(final T request) {
         super(request);
         path = request.getPath();
+        streamVersion = request.getVersion().getStreamVersion();
     }
 
     @Override
     public final void writeExternal(final ObjectOutput out) throws IOException {
         super.writeExternal(out);
-        try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
+        try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out, streamVersion)) {
             nnout.writeYangInstanceIdentifier(path);
         }
     }
index 846756d..026f3ea 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.controller.cluster.access.commands;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import java.io.IOException;
 import java.io.ObjectInput;
@@ -20,6 +21,7 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier
 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.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
 
 /**
  * Externalizable proxy for use with {@link ExistsTransactionRequest}. It implements the initial (Boron) serialization
@@ -31,6 +33,7 @@ final class ModifyTransactionRequestProxyV1 extends AbstractTransactionRequestPr
     private static final long serialVersionUID = 1L;
     private List<TransactionModification> modifications;
     private Optional<PersistenceProtocol> protocol;
+    private transient NormalizedNodeStreamVersion streamVersion;
 
     // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
     // be able to create instances via reflection.
@@ -41,8 +44,9 @@ final class ModifyTransactionRequestProxyV1 extends AbstractTransactionRequestPr
 
     ModifyTransactionRequestProxyV1(final ModifyTransactionRequest request) {
         super(request);
-        this.modifications = Preconditions.checkNotNull(request.getModifications());
+        this.modifications = requireNonNull(request.getModifications());
         this.protocol = request.getPersistenceProtocol();
+        this.streamVersion = request.getVersion().getStreamVersion();
     }
 
     @Override
@@ -70,7 +74,7 @@ final class ModifyTransactionRequestProxyV1 extends AbstractTransactionRequestPr
         out.writeByte(PersistenceProtocol.byteValue(protocol.orElse(null)));
         out.writeInt(modifications.size());
         if (!modifications.isEmpty()) {
-            try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
+            try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out, streamVersion)) {
                 for (TransactionModification op : modifications) {
                     op.writeTo(nnout);
                 }
index 24a305b..f755d3e 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Optional;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 /**
@@ -24,7 +25,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  */
 final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy<ReadTransactionSuccess> {
     private static final long serialVersionUID = 1L;
+
     private Optional<NormalizedNode<?, ?>> data;
+    private transient NormalizedNodeStreamVersion streamVersion;
 
     // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
     // be able to create instances via reflection.
@@ -36,6 +39,7 @@ final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProx
     ReadTransactionSuccessProxyV1(final ReadTransactionSuccess request) {
         super(request);
         this.data = request.getData();
+        this.streamVersion = request.getVersion().getStreamVersion();
     }
 
     @Override
@@ -44,7 +48,7 @@ final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProx
 
         if (data.isPresent()) {
             out.writeBoolean(true);
-            try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
+            try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out, streamVersion)) {
                 nnout.writeNormalizedNode(data.get());
             }
         } else {
index 2bc33cd..252fe22 100644 (file)
@@ -112,6 +112,7 @@ public abstract class Message<T extends WritableIdentifier, C extends Message<T,
 
         switch (toVersion) {
             case BORON:
+            case SODIUM:
                 return verifyNotNull(cloneAsVersion(toVersion));
             case TEST_PAST_VERSION:
             case TEST_FUTURE_VERSION:
index 6353843..875037b 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.controller.cluster.access.commands;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 
 public class LocalHistorySuccessTest extends AbstractRequestSuccessTest<LocalHistorySuccess> {
-
-    private static final LocalHistorySuccess OBJECT = new LocalHistorySuccess(
-            HISTORY_IDENTIFIER, 0);
+    private static final LocalHistorySuccess OBJECT = new LocalHistorySuccess(HISTORY_IDENTIFIER, 0);
 
     @Override
     protected LocalHistorySuccess object() {
@@ -24,13 +24,13 @@ public class LocalHistorySuccessTest extends AbstractRequestSuccessTest<LocalHis
     @Test
     public void cloneAsVersionTest() {
         final LocalHistorySuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
-        Assert.assertEquals(OBJECT.getSequence(), clone.getSequence());
-        Assert.assertEquals(OBJECT.getTarget(), clone.getTarget());
-        Assert.assertEquals(OBJECT.getVersion(), clone.getVersion());
+        assertEquals(ABIVersion.BORON, clone.getVersion());
+        assertEquals(OBJECT.getSequence(), clone.getSequence());
+        assertEquals(OBJECT.getTarget(), clone.getTarget());
     }
 
     @Override
     protected void doAdditionalAssertions(final Object deserialize) {
-        Assert.assertTrue(deserialize instanceof LocalHistorySuccess);
+        assertTrue(deserialize instanceof LocalHistorySuccess);
     }
 }
index 3756a8a..3cd4626 100644 (file)
@@ -7,13 +7,14 @@
  */
 package org.opendaylight.controller.cluster.access.commands;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 
 public class ModifyTransactionSuccessTest extends AbstractTransactionSuccessTest<ModifyTransactionSuccess> {
-    private static final ModifyTransactionSuccess OBJECT = new ModifyTransactionSuccess(
-            TRANSACTION_IDENTIFIER, 0);
+    private static final ModifyTransactionSuccess OBJECT = new ModifyTransactionSuccess(TRANSACTION_IDENTIFIER, 0);
 
     @Override
     protected ModifyTransactionSuccess object() {
@@ -23,13 +24,13 @@ public class ModifyTransactionSuccessTest extends AbstractTransactionSuccessTest
     @Test
     public void cloneAsVersionTest() {
         final ModifyTransactionSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
-        Assert.assertEquals(OBJECT.getVersion(), clone.getVersion());
-        Assert.assertEquals(OBJECT.getSequence(), clone.getSequence());
-        Assert.assertEquals(OBJECT.getTarget(), clone.getTarget());
+        assertEquals(ABIVersion.BORON, clone.getVersion());
+        assertEquals(OBJECT.getSequence(), clone.getSequence());
+        assertEquals(OBJECT.getTarget(), clone.getTarget());
     }
 
     @Override
     protected void doAdditionalAssertions(final Object deserialize) {
-        Assert.assertTrue(deserialize instanceof ModifyTransactionSuccess);
+        assertTrue(deserialize instanceof ModifyTransactionSuccess);
     }
 }
\ No newline at end of file

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