X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreSnapshotRestore.java;h=e29de0f13f976840b0f90f1cb540bda08351eb76;hb=583f30d1c7a8199b401c9393745c62fe27b5ced8;hp=52ab3030bff528b4d44027e58757e0d5d3a63e26;hpb=35a26b477f05ddf7448013c4a8b7a70174772ca3;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java index 52ab3030bf..e29de0f13f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java @@ -16,8 +16,8 @@ import java.io.ObjectInputStream; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; -import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot; -import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshotList; +import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot; +import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,19 +46,21 @@ public class DatastoreSnapshotRestore { // synchronize this method so that, in case of concurrent access to getAndRemove(), // no one ends up with partially initialized data + @SuppressWarnings("checkstyle:IllegalCatch") private synchronized void initialize() { File restoreDirectoryFile = new File(restoreDirectoryPath); String[] files = restoreDirectoryFile.list(); - if(files == null || files.length == 0) { + if (files == null || files.length == 0) { LOG.debug("Restore directory {} does not exist or is empty", restoreDirectoryFile); return; } - if(files.length > 1) { - LOG.error("Found {} files in clustered datastore restore directory {} - expected 1. No restore will be attempted", - files.length, restoreDirectoryFile); + if (files.length > 1) { + LOG.error( + "Found {} files in clustered datastore restore directory {} - expected 1. No restore will be attempted", + files.length, restoreDirectoryFile); return; } @@ -66,24 +68,25 @@ public class DatastoreSnapshotRestore { LOG.info("Clustered datastore will be restored from file {}", restoreFile); - try(FileInputStream fis = new FileInputStream(restoreFile)) { + try (FileInputStream fis = new FileInputStream(restoreFile)) { DatastoreSnapshotList snapshots = deserialize(fis); LOG.debug("Deserialized {} snapshots", snapshots.size()); - for(DatastoreSnapshot snapshot: snapshots) { + for (DatastoreSnapshot snapshot: snapshots) { datastoreSnapshots.put(snapshot.getType(), snapshot); } - } catch (Exception e) { + } catch (ClassNotFoundException | IOException e) { LOG.error("Error reading clustered datastore restore file {}", restoreFile, e); } finally { - if(!restoreFile.delete()) { + if (!restoreFile.delete()) { LOG.error("Could not delete clustered datastore restore file {}", restoreFile); } } } - private static DatastoreSnapshotList deserialize(InputStream inputStream) throws IOException, ClassNotFoundException { - try(ObjectInputStream ois = new ObjectInputStream(inputStream)) { + private static DatastoreSnapshotList deserialize(InputStream inputStream) + throws IOException, ClassNotFoundException { + try (ObjectInputStream ois = new ObjectInputStream(inputStream)) { return (DatastoreSnapshotList) ois.readObject(); } }