Create DatastoreSnapshotRestore instance via blueprint 13/36913/13
authorTom Pantelis <tpanteli@brocade.com>
Tue, 29 Mar 2016 22:11:18 +0000 (18:11 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 10 Jun 2016 18:30:05 +0000 (18:30 +0000)
The DatastoreSnapshotRestore instance was created via a bundle Activator
in order to make it available to both data store instances w/o having to
create a config yang for it and having it advertised as a service and
injected into the data store Modules.

Now that the data store instances are created via blueprint, we no
longer need the Activator and the DatastoreSnapshotRestore instance is now
created via blueprint.

Change-Id: I8299823787fff6b03934e2b0069d77b0d9981d81
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/pom.xml
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestore.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/osgi/Activator.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/main/resources/org/opendaylight/blueprint/clustered-datastore.xml
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestoreTest.java

index 7eef556..59d42a3 100644 (file)
         <configuration>
           <instructions>
             <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
-            <Bundle-Activator>org.opendaylight.controller.cluster.datastore.osgi.Activator</Bundle-Activator>
             <Export-Package>
                 org.opendaylight.controller.cluster.datastore;
                 org.opendaylight.controller.cluster.datastore.config;
index 5908a86..52ab303 100644 (file)
@@ -35,24 +35,16 @@ public class DatastoreSnapshotRestore {
     private final String restoreDirectoryPath;
     private final Map<String, DatastoreSnapshot> datastoreSnapshots = new ConcurrentHashMap<>();
 
-    public static void createInstance(String restoreDirectoryPath) {
+    public static DatastoreSnapshotRestore instance(String restoreDirectoryPath) {
         instance.compareAndSet(null, new DatastoreSnapshotRestore(restoreDirectoryPath));
-    }
-
-    public static void removeInstance() {
-        instance.set(null);
-    }
-
-    public static DatastoreSnapshotRestore instance() {
-        DatastoreSnapshotRestore localInstance = instance.get();
-        return Preconditions.checkNotNull(localInstance, "DatastoreSnapshotRestore instance was not created");
+        return instance.get();
     }
 
     private DatastoreSnapshotRestore(String restoreDirectoryPath) {
         this.restoreDirectoryPath = Preconditions.checkNotNull(restoreDirectoryPath);
     }
 
-    // sychronize this method so that, in case of concurrent access to getAndRemove(),
+    // synchronize this method so that, in case of concurrent access to getAndRemove(),
     // no one ends up with partially initialized data
     private synchronized void initialize() {
 
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/osgi/Activator.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/osgi/Activator.java
deleted file mode 100644 (file)
index afbf34e..0000000
+++ /dev/null
@@ -1,31 +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.osgi;
-
-import org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * Activator for the bundle.
- *
- * @author Thomas Pantelis
- */
-public class Activator implements BundleActivator {
-    private static final String RESTORE_DIRECTORY_PATH = "./clustered-datastore-restore";
-
-    @Override
-    public void start(BundleContext context) {
-        DatastoreSnapshotRestore.createInstance(RESTORE_DIRECTORY_PATH);
-    }
-
-    @Override
-    public void stop(BundleContext context) {
-        DatastoreSnapshotRestore.removeInstance();
-    }
-}
index cd2ee2d..4fa0af1 100644 (file)
@@ -24,7 +24,9 @@
   <!-- Distributed Config Datastore -->
 
   <bean id="datastoreSnapshotRestore" class="org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore"
-          factory-method="instance" />
+          factory-method="instance">
+    <argument value="./clustered-datastore-restore"/>
+  </bean>
 
   <bean id="configDatastoreContext" class="org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule"
           factory-method="newDatastoreContext" />
index 7adc93c..9f0b1b5 100644 (file)
@@ -65,19 +65,18 @@ public class DatastoreSnapshotRestoreTest {
             SerializationUtils.serialize(snapshotList, fos);
         }
 
-        DatastoreSnapshotRestore.createInstance(restoreDirectoryPath);
+        DatastoreSnapshotRestore instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
 
-        verifySnapshot(configSnapshot, DatastoreSnapshotRestore.instance().getAndRemove("config"));
-        verifySnapshot(operSnapshot, DatastoreSnapshotRestore.instance().getAndRemove("oper"));
+        verifySnapshot(configSnapshot, instance.getAndRemove("config"));
+        verifySnapshot(operSnapshot, instance.getAndRemove("oper"));
 
-        assertNull("DatastoreSnapshot was not removed", DatastoreSnapshotRestore.instance().getAndRemove("config"));
+        assertNull("DatastoreSnapshot was not removed", instance.getAndRemove("config"));
 
         assertFalse(backupFile + " was not deleted", backupFile.exists());
 
-        DatastoreSnapshotRestore.removeInstance();
-        DatastoreSnapshotRestore.createInstance("target/does-not-exist");
-        assertNull("Expected null DatastoreSnapshot", DatastoreSnapshotRestore.instance().getAndRemove("config"));
-        assertNull("Expected null DatastoreSnapshot", DatastoreSnapshotRestore.instance().getAndRemove("oper"));
+        instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
+        assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("config"));
+        assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("oper"));
     }
 
     private static void verifySnapshot(DatastoreSnapshot expected, DatastoreSnapshot 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.