Bail faster on not found module 77/85977/4 master
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Nov 2019 14:31:49 +0000 (15:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Nov 2019 14:39:39 +0000 (15:39 +0100)
If we fail to find config for a particular module, we can bail
directly without going through another empty check.

Change-Id: I47dc844d51ecbe1ca3f22fd355532539e07f798b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java

index fcfa615..ab52385 100644 (file)
@@ -95,27 +95,29 @@ public class ConfigurationImpl implements Configuration {
 
     @Override
     public String getModuleNameFromNameSpace(final String nameSpace) {
-        requireNonNull(nameSpace, "nameSpace should not be null");
-
-        return namespaceToModuleName.get(nameSpace);
+        return namespaceToModuleName.get(requireNonNull(nameSpace, "nameSpace should not be null"));
     }
 
     @Override
     public ShardStrategy getStrategyForModule(final String moduleName) {
-        requireNonNull(moduleName, "moduleName should not be null");
-
-        ModuleConfig moduleConfig = moduleConfigMap.get(moduleName);
+        ModuleConfig moduleConfig = getModuleConfig(moduleName);
         return moduleConfig != null ? moduleConfig.getShardStrategy() : null;
     }
 
     @Override
     public String getShardNameForModule(final String moduleName) {
-        requireNonNull(moduleName, "moduleName should not be null");
+        ModuleConfig moduleConfig = getModuleConfig(moduleName);
+        if (moduleConfig != null) {
+            Collection<ShardConfig> shardConfigs = moduleConfig.getShardConfigs();
+            if (!shardConfigs.isEmpty()) {
+                return shardConfigs.iterator().next().getName();
+            }
+        }
+        return null;
+    }
 
-        ModuleConfig moduleConfig = moduleConfigMap.get(moduleName);
-        Collection<ShardConfig> shardConfigs = moduleConfig != null ? moduleConfig.getShardConfigs() :
-            Collections.<ShardConfig>emptySet();
-        return !shardConfigs.isEmpty() ? shardConfigs.iterator().next().getName() : null;
+    private ModuleConfig getModuleConfig(final String moduleName) {
+        return moduleConfigMap.get(requireNonNull(moduleName, "moduleName should not be null"));
     }
 
     @Override

©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.