Remove ModificationPayload class 01/32401/5
authorTom Pantelis <tpanteli@brocade.com>
Tue, 12 Jan 2016 08:31:03 +0000 (03:31 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 14 Jan 2016 14:58:35 +0000 (14:58 +0000)
The ModificationPayload class was introduced early in Lithium but was
replaced later in Lithium by DataTreeCandidatePayload. Since ModificationPayload
was never contained in a release it can be removed.

Change-Id: Ia4da96695fb9c0356d16f048451b4dab7e0bcf70
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinator.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/ModificationPayload.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/ModificationPayloadTest.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModificationTest.java

index f5ca3a86ec53e7ecacbfb3a617fa977c909c5cc5..9ea22fc1967f117ec8284ffbaee140da27c394d9 100644 (file)
@@ -50,7 +50,6 @@ import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeCh
 import org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged;
 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
 import org.opendaylight.controller.cluster.datastore.modification.Modification;
-import org.opendaylight.controller.cluster.datastore.modification.ModificationPayload;
 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
 import org.opendaylight.controller.cluster.datastore.utils.MessageTracker;
@@ -646,12 +645,6 @@ public class Shard extends RaftActor {
                 // Replication consensus reached, proceed to commit
                 finishCommit(clientActor, identifier);
             }
-        } else if (data instanceof ModificationPayload) {
-            try {
-                applyModificationToState(clientActor, identifier, ((ModificationPayload) data).getModification());
-            } catch (ClassNotFoundException | IOException e) {
-                LOG.error("{}: Error extracting ModificationPayload", persistenceId(), e);
-            }
         } else if (data instanceof CompositeModificationPayload) {
             Object modification = ((CompositeModificationPayload) data).getModification();
 
index 82a6b720f07d05303991235619515641af02acd6..634121f5e5e669b5038246876ea0228b454edfe5 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.base.Preconditions;
 import java.io.IOException;
 import java.net.URI;
 import java.util.Set;
-import org.opendaylight.controller.cluster.datastore.modification.ModificationPayload;
 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.node.utils.transformer.NormalizedNodePruner;
 import org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification;
@@ -70,10 +69,6 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
             if (payload instanceof DataTreeCandidatePayload) {
                 DataTreeCandidates.applyToModification(transaction, ((DataTreeCandidatePayload)payload).getCandidate());
                 size++;
-            } else if (payload instanceof ModificationPayload) {
-                MutableCompositeModification.fromSerializable(
-                    ((ModificationPayload) payload).getModification()).apply(transaction);
-                size++;
             } else if (payload instanceof CompositeModificationPayload) {
                 MutableCompositeModification.fromSerializable(
                     ((CompositeModificationPayload) payload).getModification()).apply(transaction);
@@ -85,7 +80,7 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
             } else {
                 log.error("{}: Unknown payload {} received during recovery", shardName, payload);
             }
-        } catch (IOException | ClassNotFoundException e) {
+        } catch (IOException e) {
             log.error("{}: Error extracting ModificationPayload", shardName, e);
         }
     }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/ModificationPayload.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/ModificationPayload.java
deleted file mode 100644 (file)
index 01d1128..0000000
+++ /dev/null
@@ -1,80 +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.modification;
-
-import com.google.protobuf.GeneratedMessage.GeneratedExtension;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.util.Map;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
-import org.opendaylight.controller.protobuff.messages.cluster.raft.AppendEntriesMessages.AppendEntries.ReplicatedLogEntry;
-
-/**
- * Payload implementation for MutableCompositeModification used for persistence and replication.
- *
- * @author Thomas Pantelis
- */
-public class ModificationPayload extends Payload implements Externalizable {
-    private static final long serialVersionUID = 1L;
-
-    private transient byte[] serializedPayload;
-
-    public ModificationPayload() {
-    }
-
-    public ModificationPayload(Modification from) throws IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream(bos);
-        out.writeObject(from);
-        out.close();
-        serializedPayload = bos.toByteArray();
-    }
-
-    public Modification getModification() throws IOException, ClassNotFoundException {
-        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedPayload));
-        Modification to = (Modification) in.readObject();
-        in.close();
-        return to;
-    }
-
-    @Override
-    public int size() {
-        return serializedPayload.length;
-    }
-
-    @Override
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        int size = in.readInt();
-        serializedPayload = new byte[size];
-        in.readFully(serializedPayload);
-    }
-
-    @Override
-    public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(serializedPayload.length);
-        out.write(serializedPayload);
-    }
-
-    @Override
-    @Deprecated
-    public <T> Map<GeneratedExtension, T> encode() {
-        return null;
-    }
-
-    @Override
-    @Deprecated
-    public Payload decode(ReplicatedLogEntry.Payload payload) {
-        return null;
-    }
-}
index b730150668fa3796eee6ed55c97553a27df74614..f4468b0e59d025a87f44365fc37e5797668e33a4 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.base.Optional;
 import java.io.IOException;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.modification.ModificationPayload;
 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
@@ -63,20 +62,6 @@ public class ShardRecoveryCoordinatorTest {
         coordinator.applyCurrentLogRecoveryBatch();
     }
 
-    @Test
-    public void testAppendRecoveredLogEntryModificationPayload() throws IOException {
-        final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree,
-                peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo"));
-        coordinator.startLogRecoveryBatch(10);
-        try {
-            final MutableCompositeModification modification  = new MutableCompositeModification((short) 1);
-            modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create()));
-            coordinator.appendRecoveredLogEntry(new ModificationPayload(modification));
-        } catch(final SchemaValidationFailedException e){
-            fail("SchemaValidationFailedException should not happen if pruning is done");
-        }
-    }
-
     @Test
     public void testAppendRecoveredLogEntryCompositeModificationPayload() throws IOException {
         final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree,
index ae751fa65d2b0a3a0917e672a1dfeab59f52a670..0121a15338a2ed807e910a793e6655a062ba35de 100644 (file)
@@ -37,7 +37,6 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.Uninterruptibles;
-import java.io.IOException;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -75,7 +74,6 @@ import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContex
 import org.opendaylight.controller.cluster.datastore.modification.DeleteModification;
 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
 import org.opendaylight.controller.cluster.datastore.modification.Modification;
-import org.opendaylight.controller.cluster.datastore.modification.ModificationPayload;
 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
 import org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener;
@@ -117,7 +115,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
@@ -465,12 +462,10 @@ public class ShardTest extends AbstractShardTest {
     @Test
     public void testApplySnapshot() throws Exception {
 
-        ShardTestKit testkit = new ShardTestKit(getSystem());
-
         final TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
                 "testApplySnapshot");
 
-        testkit.waitUntilLeader(shard);
+        ShardTestKit.waitUntilLeader(shard);
 
         final DataTree store = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
         store.setSchemaContext(SCHEMA_CONTEXT);
@@ -499,40 +494,14 @@ public class ShardTest extends AbstractShardTest {
 
     @Test
     public void testApplyState() throws Exception {
-
-        ShardTestKit testkit = new ShardTestKit(getSystem());
-
-        final TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(), "testApplyState");
-
-        testkit.waitUntilLeader(shard);
-
-        final NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-
-        final ApplyState applyState = new ApplyState(null, "test", new ReplicatedLogImplEntry(1, 2,
-                newModificationPayload(new WriteModification(TestModel.TEST_PATH, node))));
-
-        shard.underlyingActor().onReceiveCommand(applyState);
-
-        final NormalizedNode<?,?> actual = readStore(shard, TestModel.TEST_PATH);
-        assertEquals("Applied state", node, actual);
-
-        shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
-    }
-
-    @Test
-    public void testApplyStateWithCandidatePayload() throws Exception {
-
-        ShardTestKit testkit = new ShardTestKit(getSystem());
-
         final TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(), "testApplyState");
 
-        testkit.waitUntilLeader(shard);
+        ShardTestKit.waitUntilLeader(shard);
 
         final NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-        final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(TestModel.TEST_PATH, node);
 
         final ApplyState applyState = new ApplyState(null, "test", new ReplicatedLogImplEntry(1, 2,
-                DataTreeCandidatePayload.create(candidate)));
+                newDataTreeCandidatePayload(new WriteModification(TestModel.TEST_PATH, node))));
 
         shard.underlyingActor().onReceiveCommand(applyState);
 
@@ -609,9 +578,13 @@ public class ShardTest extends AbstractShardTest {
 
         InMemoryJournal.addEntry(shardID.toString(), 0, DUMMY_DATA);
 
-        InMemoryJournal.addEntry(shardID.toString(), 1, new ReplicatedLogImplEntry(0, 1, newModificationPayload(
-            new WriteModification(TestModel.OUTER_LIST_PATH,
-                ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()))));
+        ShardDataTree shardDataTree = new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION);
+
+        InMemoryJournal.addEntry(shardID.toString(), 1, new ReplicatedLogImplEntry(0, 1, newDataTreeCandidatePayload(
+                shardDataTree,
+                new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)),
+                new WriteModification(TestModel.OUTER_LIST_PATH,
+                        ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()))));
 
         final int nListEntries = 16;
         final Set<Integer> listEntryKeys = new HashSet<>();
@@ -624,7 +597,7 @@ public class ShardTest extends AbstractShardTest {
             final Modification mod = new MergeModification(path,
                     ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i));
             InMemoryJournal.addEntry(shardID.toString(), i + 1, new ReplicatedLogImplEntry(i, 1,
-                    newModificationPayload(mod)));
+                    newDataTreeCandidatePayload(shardDataTree, mod)));
         }
 
         InMemoryJournal.addEntry(shardID.toString(), nListEntries + 2,
@@ -633,13 +606,18 @@ public class ShardTest extends AbstractShardTest {
         testRecovery(listEntryKeys);
     }
 
-    private static ModificationPayload newModificationPayload(final Modification... mods) throws IOException {
-        final MutableCompositeModification compMod = new MutableCompositeModification();
+    private static DataTreeCandidatePayload newDataTreeCandidatePayload(final Modification... mods) throws Exception {
+        return newDataTreeCandidatePayload(new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION), mods);
+    }
+
+    private static DataTreeCandidatePayload newDataTreeCandidatePayload(ShardDataTree shardDataTree,
+            final Modification... mods) throws Exception {
+        DataTreeModification dataTreeModification = shardDataTree.newModification();
         for(final Modification mod: mods) {
-            compMod.addModification(mod);
+            mod.apply(dataTreeModification);
         }
 
-        return new ModificationPayload(compMod);
+        return DataTreeCandidatePayload.create(shardDataTree.commit(dataTreeModification));
     }
 
     @Test
index 725a5f009a260d3198b4f2f520d622ffa62b78f1..5fb02619e9b7e859e4fabc0d678d848aa79d82ae 100644 (file)
@@ -20,7 +20,6 @@ import akka.pattern.Patterns;
 import akka.testkit.TestActorRef;
 import akka.util.Timeout;
 import com.google.common.base.Optional;
-import java.io.IOException;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -41,7 +40,6 @@ import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionR
 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply;
 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
 import org.opendaylight.controller.cluster.datastore.modification.Modification;
-import org.opendaylight.controller.cluster.datastore.modification.ModificationPayload;
 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
@@ -93,15 +91,6 @@ public class PreLithiumShardTest extends AbstractShardTest {
         return new CompositeModificationByteStringPayload(compMod.toSerializable());
     }
 
-    private static ModificationPayload newModificationPayload(final Modification... mods) throws IOException {
-        MutableCompositeModification compMod = new MutableCompositeModification();
-        for(Modification mod: mods) {
-            compMod.addModification(mod);
-        }
-
-        return new ModificationPayload(compMod);
-    }
-
     @Test
     public void testApplyHelium2VersionSnapshot() throws Exception {
         TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/ModificationPayloadTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/ModificationPayloadTest.java
deleted file mode 100644 (file)
index 7016ada..0000000
+++ /dev/null
@@ -1,55 +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.modification;
-
-import static org.junit.Assert.assertEquals;
-import org.apache.commons.lang3.SerializationUtils;
-import org.junit.Test;
-import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-
-/**
- * Unit tests for ModificationPayload.
- *
- * @author Thomas Pantelis
- */
-public class ModificationPayloadTest {
-
-    @Test
-    public void test() throws Exception {
-
-        YangInstanceIdentifier writePath = TestModel.TEST_PATH;
-        NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
-                withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
-
-        MutableCompositeModification compositeModification = new MutableCompositeModification();
-        compositeModification.addModification(new WriteModification(writePath, writeData));
-
-        ModificationPayload payload = new ModificationPayload(compositeModification);
-
-        MutableCompositeModification deserialized = (MutableCompositeModification) payload.getModification();
-
-        assertEquals("getModifications size", 1, deserialized.getModifications().size());
-        WriteModification write = (WriteModification)deserialized.getModifications().get(0);
-        assertEquals("getPath", writePath, write.getPath());
-        assertEquals("getData", writeData, write.getData());
-
-        ModificationPayload cloned = SerializationUtils.clone(payload);
-
-        deserialized = (MutableCompositeModification) payload.getModification();
-
-        assertEquals("getModifications size", 1, deserialized.getModifications().size());
-        write = (WriteModification)deserialized.getModifications().get(0);
-        assertEquals("getPath", writePath, write.getPath());
-        assertEquals("getData", writeData, write.getData());
-    }
-}
index 58d299e5c713a544e50730d230fe6418e04fefd7..7fac06c0f89d77ba51499c1d35d50948681eee5a 100644 (file)
@@ -11,9 +11,7 @@ package org.opendaylight.controller.cluster.datastore.modification;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import com.google.common.base.Optional;
-import com.google.common.base.Stopwatch;
 import org.apache.commons.lang.SerializationUtils;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
@@ -80,35 +78,4 @@ public class MutableCompositeModificationTest extends AbstractModificationTest {
         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, delete.getVersion());
         assertEquals("getPath", deletePath, delete.getPath());
     }
-
-    @Test
-    @Ignore
-    public void testSerializationScale() throws Exception {
-        YangInstanceIdentifier writePath = TestModel.TEST_PATH;
-        NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
-                withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
-
-        MutableCompositeModification compositeModification = new MutableCompositeModification();
-        for(int i = 0; i < 1000; i++) {
-            compositeModification.addModification(new WriteModification(writePath, writeData));
-        }
-
-        Stopwatch sw = Stopwatch.createStarted();
-        for(int i = 0; i < 1000; i++) {
-            new ModificationPayload(compositeModification);
-        }
-
-        sw.stop();
-        System.out.println("Elapsed: "+sw);
-
-        ModificationPayload p = new ModificationPayload(compositeModification);
-        sw.start();
-        for(int i = 0; i < 1000; i++) {
-            p.getModification();
-        }
-
-        sw.stop();
-        System.out.println("Elapsed: "+sw);
-    }
 }