From a4b4ae2880afda94538e0edea05310cd6ace2f4a Mon Sep 17 00:00:00 2001 From: Moiz Raja Date: Mon, 4 Aug 2014 18:07:13 -0700 Subject: [PATCH] Fixed issue where a shard for a defined module is not found Change-Id: I5f6c82ce39f900a55519ec04a739a83ccb834e59 Signed-off-by: Moiz Raja --- .../shardstrategy/ModuleShardStrategy.java | 9 ++++++- .../shardstrategy/ShardStrategy.java | 3 +++ .../ModuleShardStrategyTest.java | 24 +++++++++++++++++-- .../src/test/resources/modules.conf | 6 +++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java index 6f4b65a6f3..fc7ebd94dd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java @@ -11,6 +11,8 @@ package org.opendaylight.controller.cluster.datastore.shardstrategy; import org.opendaylight.controller.cluster.datastore.Configuration; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import java.util.List; + public class ModuleShardStrategy implements ShardStrategy { public static final String NAME = "module"; @@ -25,6 +27,11 @@ public class ModuleShardStrategy implements ShardStrategy { } @Override public String findShard(YangInstanceIdentifier path) { - return configuration.getShardNamesFromModuleName(moduleName).get(0); + List shardNames = + configuration.getShardNamesFromModuleName(moduleName); + if(shardNames.size() == 0){ + return DefaultShardStrategy.DEFAULT_SHARD; + } + return shardNames.get(0); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategy.java index 2df945edd5..9a05c381ea 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategy.java @@ -16,6 +16,9 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public interface ShardStrategy { /** * Find the name of the shard in which the data pointed to by the specified path belongs in + *

+ * Should return the name of the default shard DefaultShardStrategy.DEFAULT_SHARD + * if no matching shard was found * * @param path The location of the data in the logical tree * @return diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java index 88753e4b0a..3394cdc959 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java @@ -1,6 +1,5 @@ package org.opendaylight.controller.cluster.datastore.shardstrategy; -import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -8,6 +7,10 @@ import org.junit.rules.ExpectedException; import org.opendaylight.controller.cluster.datastore.Configuration; import org.opendaylight.controller.cluster.datastore.ConfigurationImpl; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; + +import static junit.framework.Assert.assertEquals; public class ModuleShardStrategyTest { @Rule @@ -28,6 +31,23 @@ public class ModuleShardStrategyTest { String shard = moduleShardStrategy.findShard(CarsModel.BASE_PATH); - Assert.assertEquals("cars-1", shard); + assertEquals("cars-1", shard); + } + + @Test + public void testFindShardWhenModuleConfigurationPresentInModulesButMissingInModuleShards() { + + final QName BASE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:missing", "2014-03-13", + "missing"); + + final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME); + + ModuleShardStrategy moduleShardStrategy = + new ModuleShardStrategy("missing", configuration); + + String shard = moduleShardStrategy.findShard(BASE_PATH); + + assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shard); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/modules.conf b/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/modules.conf index 22854cb11a..f4919e7895 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/modules.conf +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/modules.conf @@ -15,4 +15,10 @@ modules = [ shard-strategy = "module" } + { + name = "missing" + namespace = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:missing" + shard-strategy = "module" + } + ] -- 2.36.6