Cleanup warnings around methods being potentially static
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardRecoveryCoordinator.java
index 70a701075ec6b5867e7a765629fcc65d6b72d8cb..e87f083fb1ad283190ba74aee77b48ce966bcb60 100644 (file)
@@ -10,9 +10,13 @@ package org.opendaylight.controller.cluster.datastore;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import java.io.File;
+import java.io.IOException;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
+import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
 import org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeXMLOutput;
 import org.opendaylight.controller.cluster.raft.RaftActorRecoveryCohort;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot.State;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -34,7 +38,8 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
 
     private boolean open;
 
-    ShardRecoveryCoordinator(final ShardDataTree store,  final byte[] restoreFromSnapshot, final String shardName, final Logger log) {
+    ShardRecoveryCoordinator(final ShardDataTree store,  final byte[] restoreFromSnapshot, final String shardName,
+            final Logger log) {
         this.store = Preconditions.checkNotNull(store);
         this.shardName = Preconditions.checkNotNull(shardName);
         this.log = Preconditions.checkNotNull(log);
@@ -49,6 +54,7 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void appendRecoveredLogEntry(final Payload payload) {
         Preconditions.checkState(open, "call startLogRecovery before calling appendRecoveredLogEntry");
 
@@ -72,7 +78,7 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
 
     private File writeRoot(final String kind, final NormalizedNode<?, ?> node) {
         final File file = new File(System.getProperty("karaf.data", "."),
-            "failed-" + kind + "-snapshot-" + shardName + ".xml");
+            "failed-recovery-" + kind + "-" + shardName + ".xml");
         NormalizedNodeXMLOutput.toFile(file, node);
         return file;
     }
@@ -83,25 +89,22 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
      * @param snapshotBytes the serialized snapshot
      */
     @Override
-    public void applyRecoverySnapshot(final byte[] snapshotBytes) {
-        log.debug("{}: Applying recovered snapshot", shardName);
-
-        final ShardDataTreeSnapshot snapshot;
-        try {
-            snapshot = ShardDataTreeSnapshot.deserialize(snapshotBytes);
-        } catch (Exception e) {
-            log.error("{}: failed to deserialize snapshot", shardName, e);
-            throw Throwables.propagate(e);
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public void applyRecoverySnapshot(final Snapshot.State snapshotState) {
+        if (!(snapshotState instanceof ShardSnapshotState)) {
+            log.debug("{}: applyRecoverySnapshot ignoring snapshot: {}", snapshotState);
         }
 
+        log.debug("{}: Applying recovered snapshot", shardName);
+
+        ShardDataTreeSnapshot shardSnapshot = ((ShardSnapshotState)snapshotState).getSnapshot();
         try {
-            store.applyRecoverySnapshot(snapshot);
+            store.applyRecoverySnapshot(shardSnapshot);
         } catch (Exception e) {
-            log.error("{}: failed to apply snapshot {}", shardName, snapshot, e);
-
-            final File f = writeRoot("recovery", snapshot.getRootNode().orElse(null));
+            final File f = writeRoot("snapshot", shardSnapshot.getRootNode().orElse(null));
             throw new IllegalStateException(String.format(
-                    "%s: Failed to apply recovery snapshot. Node data was written to file %s", shardName, f), e);
+                    "%s: Failed to apply recovery snapshot %s. Node data was written to file %s",
+                    shardName, shardSnapshot, f), e);
         }
     }
 
@@ -109,4 +112,15 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
     public byte[] getRestoreFromSnapshot() {
         return restoreFromSnapshot;
     }
+
+    @Override
+    @Deprecated
+    public State deserializePreCarbonSnapshot(byte[] from) {
+        try {
+            return new ShardSnapshotState(ShardDataTreeSnapshot.deserialize(from));
+        } catch (IOException e) {
+            log.error("{}: failed to deserialize snapshot", shardName, e);
+            throw Throwables.propagate(e);
+        }
+    }
 }