From 5486a047d7ccf57fe707e754b561bc7c3189a3d9 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 26 Oct 2016 14:06:11 -0400 Subject: [PATCH] Remove pre-Lithium serialization support in sal-distributed-datastore 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 --- .../NormalizedNodeStreamReaderWriterTest.java | 20 ++---- .../datastore/utils/SerializationUtils.java | 12 ---- .../datastore/compat/PreLithiumShardTest.java | 65 ------------------- .../datastore/model/SampleModelsTest.java | 57 ---------------- 4 files changed, 7 insertions(+), 147 deletions(-) delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java index 014202fb34..825e123f82 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java @@ -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(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/SerializationUtils.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/SerializationUtils.java index f29b7d8b8b..9ed9e9a88f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/SerializationUtils.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/SerializationUtils.java @@ -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 index 2ecefb2c0c..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java +++ /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 = 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.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 index e27d08b3f2..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java +++ /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); - - } -} -- 2.36.6