Pass in EntityOwnerSelectionStrategyConfig when constructing DistributedEntityOwnersh... 04/29404/5
authorMoiz Raja <moraja@cisco.com>
Sun, 11 Oct 2015 01:56:55 +0000 (18:56 -0700)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 12 Nov 2015 21:08:06 +0000 (16:08 -0500)
Change-Id: Iad1014db726a06de9a89a9987216ca4c96981122
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipService.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_entity_ownership_service/DistributedEntityOwnershipServiceProviderModule.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java

index f782fc2..f1d9b43 100644 (file)
@@ -62,12 +62,14 @@ public class DistributedEntityOwnershipService implements EntityOwnershipService
     private static final Timeout MESSAGE_TIMEOUT = new Timeout(1, TimeUnit.MINUTES);
 
     private final DistributedDataStore datastore;
+    private final EntityOwnerSelectionStrategyConfig strategyConfig;
     private final ConcurrentMap<Entity, Entity> registeredEntities = new ConcurrentHashMap<>();
     private volatile ActorRef localEntityOwnershipShard;
     private volatile DataTree localEntityOwnershipShardDataTree;
 
-    public DistributedEntityOwnershipService(DistributedDataStore datastore) {
-        this.datastore = datastore;
+    public DistributedEntityOwnershipService(DistributedDataStore datastore, EntityOwnerSelectionStrategyConfig strategyConfig) {
+        this.datastore = Preconditions.checkNotNull(datastore);
+        this.strategyConfig = Preconditions.checkNotNull(strategyConfig);
     }
 
     public void start() {
@@ -220,7 +222,7 @@ public class DistributedEntityOwnershipService implements EntityOwnershipService
 
     protected EntityOwnershipShard.Builder newShardBuilder() {
         return EntityOwnershipShard.newBuilder().localMemberName(datastore.getActorContext().getCurrentMemberName())
-                .ownerSelectionStrategyConfig(EntityOwnerSelectionStrategyConfig.newBuilder().build());
+                .ownerSelectionStrategyConfig(this.strategyConfig);
     }
 
     @VisibleForTesting
index fd2f6a8..679f067 100644 (file)
@@ -3,6 +3,7 @@ package org.opendaylight.controller.config.yang.config.distributed_entity_owners
 import com.google.common.base.Preconditions;
 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
 import org.opendaylight.controller.cluster.datastore.entityownership.DistributedEntityOwnershipService;
+import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig;
 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
 
 
@@ -30,7 +31,7 @@ public class DistributedEntityOwnershipServiceProviderModule extends org.openday
         DOMStore dataStore = getDataStoreDependency();
         Preconditions.checkArgument(dataStore instanceof DistributedDataStore,
                 "Injected DOMStore must be an instance of DistributedDataStore");
-        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService((DistributedDataStore)dataStore);
+        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService((DistributedDataStore)dataStore, EntityOwnerSelectionStrategyConfig.newBuilder().build());
         service.start();
         return service;
     }
index 6025e01..634b92c 100644 (file)
@@ -38,6 +38,7 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
 import org.opendaylight.controller.cluster.datastore.IntegrationTestKit;
+import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig;
 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
@@ -136,13 +137,13 @@ public class DistributedEntityOwnershipIntegrationTest {
         follower1DistributedDataStore.waitTillReady();
         follower2DistributedDataStore.waitTillReady();
 
-        leaderEntityOwnershipService = new DistributedEntityOwnershipService(leaderDistributedDataStore);
+        leaderEntityOwnershipService = new DistributedEntityOwnershipService(leaderDistributedDataStore, EntityOwnerSelectionStrategyConfig.newBuilder().build());
         leaderEntityOwnershipService.start();
 
-        follower1EntityOwnershipService = new DistributedEntityOwnershipService(follower1DistributedDataStore);
+        follower1EntityOwnershipService = new DistributedEntityOwnershipService(follower1DistributedDataStore, EntityOwnerSelectionStrategyConfig.newBuilder().build());
         follower1EntityOwnershipService.start();
 
-        follower2EntityOwnershipService = new DistributedEntityOwnershipService(follower2DistributedDataStore);
+        follower2EntityOwnershipService = new DistributedEntityOwnershipService(follower2DistributedDataStore, EntityOwnerSelectionStrategyConfig.newBuilder().build());
         follower2EntityOwnershipService.start();
 
         leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(),
index 17eb1f6..084c5e7 100644 (file)
@@ -108,7 +108,8 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
 
     @Test
     public void testEntityOwnershipShardCreated() throws Exception {
-        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore);
+        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore,
+                EntityOwnerSelectionStrategyConfig.newBuilder().build());
         service.start();
 
         Future<ActorRef> future = dataStore.getActorContext().findLocalShardAsync(
@@ -122,7 +123,8 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
     @Test
     public void testRegisterCandidate() throws Exception {
         final TestShardBuilder shardBuilder = new TestShardBuilder();
-        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore) {
+        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore,
+                EntityOwnerSelectionStrategyConfig.newBuilder().build()) {
             @Override
             protected EntityOwnershipShard.Builder newShardBuilder() {
                 return shardBuilder;
@@ -171,7 +173,8 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
     @Test
     public void testCloseCandidateRegistration() throws Exception {
         final TestShardBuilder shardBuilder = new TestShardBuilder();
-        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore) {
+        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore,
+                EntityOwnerSelectionStrategyConfig.newBuilder().build()) {
             @Override
             protected EntityOwnershipShard.Builder newShardBuilder() {
                 return shardBuilder;
@@ -210,7 +213,8 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
     @Test
     public void testListenerRegistration() {
         final TestShardBuilder shardBuilder = new TestShardBuilder();
-        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore) {
+        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore,
+                EntityOwnerSelectionStrategyConfig.newBuilder().build()) {
             @Override
             protected EntityOwnershipShard.Builder newShardBuilder() {
                 return shardBuilder;
@@ -249,7 +253,8 @@ public class DistributedEntityOwnershipServiceTest extends AbstractEntityOwnersh
     @Test
     public void testGetOwnershipState() throws Exception {
         final TestShardBuilder shardBuilder = new TestShardBuilder();
-        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore) {
+        DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore,
+                EntityOwnerSelectionStrategyConfig.newBuilder().build()) {
             @Override
             protected EntityOwnershipShard.Builder newShardBuilder() {
                 return shardBuilder;