Bug 4105: Add method to get all unique member names 26/26726/3
authorTom Pantelis <tpanteli@brocade.com>
Wed, 5 Aug 2015 22:15:42 +0000 (18:15 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 10 Sep 2015 19:47:58 +0000 (19:47 +0000)
Added a method to Configuration to get all unique members names
configured for all shards.

Change-Id: I09993541ad7e5963e9eef9cb58b4376daa8f09e8
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
(cherry picked from commit c3ba770fd6e9ba6e6227717bdba11ccc9f468f05)

opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Configuration.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ConfigurationImplTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/MockConfiguration.java

index b264606..c57d2d4 100644 (file)
@@ -9,11 +9,11 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import com.google.common.base.Optional;
-import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy;
-
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy;
 
 public interface Configuration {
 
@@ -59,4 +59,9 @@ public interface Configuration {
      * @return
      */
     Set<String> getAllShardNames();
+
+    /**
+     * Returns a unique set of all member names configured for all shards.
+     */
+    Collection<String> getUniqueMemberNamesForAllShards();
 }
index 0541e3a..4d83dea 100644 (file)
@@ -21,8 +21,10 @@ import com.typesafe.config.ConfigFactory;
 import com.typesafe.config.ConfigObject;
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -198,6 +200,16 @@ public class ConfigurationImpl implements Configuration {
         return allShardNames;
     }
 
+    @Override
+    public Collection<String> getUniqueMemberNamesForAllShards() {
+        Set<String> allNames = new HashSet<>();
+        for(String shardName: allShardNames) {
+            allNames.addAll(getMembersFromShardName(shardName));
+        }
+
+        return allNames;
+    }
+
     private List<Module> readModules(final Config modulesConfig) {
         List<? extends ConfigObject> modulesConfigObjectList =
             modulesConfig.getObjectList("modules");
index 4e0089e..53c3a89 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.cluster.datastore;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import com.google.common.collect.Sets;
 import com.typesafe.config.ConfigFactory;
 import java.io.File;
 import java.util.List;
@@ -101,4 +102,10 @@ public class ConfigurationImplTest {
         assertTrue(allShardNames.contains("cars-1"));
         assertTrue(allShardNames.contains("test-1"));
     }
+
+    @Test
+    public void testGetUniqueMemberNamesForAllShards() {
+        assertEquals("getUniqueMemberNamesForAllShards", Sets.newHashSet("member-1", "member-2", "member-3"),
+                configuration.getUniqueMemberNamesForAllShards());
+    }
 }
index 0bc561f..6b0f962 100644 (file)
@@ -12,7 +12,9 @@ import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -65,4 +67,14 @@ public class MockConfiguration implements Configuration{
     @Override public Set<String> getAllShardNames() {
         return Collections.emptySet();
     }
+
+    @Override
+    public Collection<String> getUniqueMemberNamesForAllShards() {
+        Set<String> allNames = new HashSet<>();
+        for(List<String> l: shardMembers.values()) {
+            allNames.addAll(l);
+        }
+
+        return allNames;
+    }
 }