Remove pre-Lithium serialization support in sal-distributed-datastore 34/47634/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 26 Oct 2016 18:06:11 +0000 (14:06 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 27 Oct 2016 01:10:34 +0000 (01:10 +0000)
We've had 3 releases since Helium so it should be safe to remove the
backwards compatible serialization support for the old format utilized by
NormalizedNodeToNodeCodec. It's not likely any user would have persisted
data in the old format in production (mainly b/c clustering was essentially
beta at best) but, in Boron, persisted journals will get snapshotted anyway
in the post-Helium format due to message migration.

Change-Id: I3fba07748b798962b7816878a791cf50a97e5a50
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/SerializationUtils.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java [deleted file]

index 014202f..825e123 100644 (file)
@@ -25,7 +25,6 @@ import javax.xml.transform.stream.StreamResult;
 import org.apache.commons.lang.SerializationUtils;
 import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
 import org.opendaylight.controller.cluster.datastore.util.TestModel;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -126,7 +125,6 @@ public class NormalizedNodeStreamReaderWriterTest {
         writer.close();
     }
 
-    @SuppressWarnings("deprecation")
     @Test
     public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException {
 
@@ -143,7 +141,7 @@ public class NormalizedNodeStreamReaderWriterTest {
 
         writer.writeYangInstanceIdentifier(path);
 
-        NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
+        NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
             ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
 
         NormalizedNode<?,?> node = reader.readNormalizedNode();
@@ -155,24 +153,20 @@ public class NormalizedNodeStreamReaderWriterTest {
         writer.close();
     }
 
-    @SuppressWarnings("deprecation")
     @Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
     public void testInvalidNormalizedNodeStream() throws IOException {
-        byte[] protobufBytes = new NormalizedNodeToNodeCodec().encode(
-                TestModel.createBaseTestContainerBuilder().build()).getNormalizedNode().toByteArray();
-
-        NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-            ByteStreams.newDataInput(protobufBytes));
+        byte[] invalidBytes = {1,2,3};
+        NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
+                ByteStreams.newDataInput(invalidBytes));
 
         reader.readNormalizedNode();
     }
 
-    @SuppressWarnings("deprecation")
     @Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
     public void testInvalidYangInstanceIdentifierStream() throws IOException {
-        byte[] protobufBytes = {1,2,3};
-        NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
-            ByteStreams.newDataInput(protobufBytes));
+        byte[] invalidBytes = {1,2,3};
+        NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
+            ByteStreams.newDataInput(invalidBytes));
 
         reader.readYangInstanceIdentifier();
     }
index f29b7d8..9ed9e9a 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.cluster.datastore.utils;
 
 import com.google.common.base.Preconditions;
-import com.google.protobuf.InvalidProtocolBufferException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInput;
@@ -16,13 +15,10 @@ import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.io.DataOutputStream;
 import java.io.IOException;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.InvalidNormalizedNodeStreamException;
 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.NormalizedNodeInputStreamReader;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -103,14 +99,6 @@ public final class SerializationUtils {
     public static NormalizedNode<?, ?> deserializeNormalizedNode(byte [] bytes) {
         try {
             return tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
-        } catch (InvalidNormalizedNodeStreamException e) {
-            // Probably from legacy protobuf serialization - try that.
-            try {
-                NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(bytes);
-                return new NormalizedNodeToNodeCodec().decode(serializedNode);
-            } catch (InvalidProtocolBufferException e2) {
-                throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
-            }
         } catch (IOException e) {
             throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
         }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java
deleted file mode 100644 (file)
index 2ecefb2..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.compat;
-
-import static org.junit.Assert.assertEquals;
-
-import akka.actor.ActorRef;
-import akka.actor.PoisonPill;
-import akka.testkit.TestActorRef;
-import java.util.Collections;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.AbstractShardTest;
-import org.opendaylight.controller.cluster.datastore.Shard;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.Snapshot;
-import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
-
-/**
- * Unit tests for backwards compatibility with pre-Lithium versions.
- *
- * @author Thomas Pantelis
- */
-public class PreLithiumShardTest extends AbstractShardTest {
-    @Test
-    public void testApplyHelium2VersionSnapshot() throws Exception {
-        TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
-                "testApplyHelium2VersionSnapshot");
-
-        NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec();
-
-        DataTree store = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        store.setSchemaContext(SCHEMA_CONTEXT);
-
-        writeToStore(store, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
-        YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY;
-        NormalizedNode<?,?> expected = readStore(store, root);
-
-        NormalizedNodeMessages.Container encode = codec.encode(expected);
-
-        Snapshot snapshot = Snapshot.create(encode.getNormalizedNode().toByteString().toByteArray(),
-                Collections.<ReplicatedLogEntry>emptyList(), 1, 2, 3, 4);
-
-        shard.underlyingActor().getRaftActorSnapshotCohort().applySnapshot(snapshot.getState());
-
-        NormalizedNode<?,?> actual = readStore(shard, root);
-
-        assertEquals("Root node", expected, actual);
-
-        shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
-    }
-}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java
deleted file mode 100644 (file)
index e27d08b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.md.cluster.datastore.model;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-public class SampleModelsTest {
-    @Test
-    public void testPeopleModel() {
-        final NormalizedNode<?, ?> expected = PeopleModel.create();
-
-
-        final NormalizedNodeMessages.Container node =
-            new NormalizedNodeToNodeCodec()
-                .encode(expected);
-
-        final NormalizedNodeMessages.Node normalizedNode =
-            node.getNormalizedNode();
-
-        final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec().decode(normalizedNode);
-
-
-        Assert.assertEquals(expected, actual);
-
-    }
-
-
-    @Test
-    public void testCarsModel() {
-        final NormalizedNode<?, ?> expected = CarsModel.create();
-
-
-        final NormalizedNodeMessages.Container node =
-            new NormalizedNodeToNodeCodec()
-                .encode(expected);
-
-        final NormalizedNodeMessages.Node normalizedNode =
-            node.getNormalizedNode();
-
-        final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec().decode(
-            normalizedNode);
-
-
-        Assert.assertEquals(expected, actual);
-
-    }
-}

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