X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fconfig%2FConfigurationImpl.java;h=ab52385893a7fb43f00db90cdada2b464a980315;hb=HEAD;hp=8e132f26d19a2e4ccdc0ed683a7dadb5df6f6751;hpb=abaef4a5ae37f27542155457fe7306a4662b1eeb;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java index 8e132f26d1..d0e8d875f6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImpl.java @@ -11,10 +11,9 @@ import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import java.util.AbstractMap.SimpleEntry; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -22,20 +21,13 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.opendaylight.controller.cluster.access.concepts.MemberName; -import org.opendaylight.controller.cluster.datastore.shardstrategy.PrefixShardStrategy; import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy; import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory; -import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils; -import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -// TODO clean this up once we get rid of module based configuration, prefix one should be alot simpler +// FIXME: Non-final for testing public class ConfigurationImpl implements Configuration { private volatile Map moduleConfigMap; - // TODO should this be initialized with something? on restart we should restore the shards from configuration? - private volatile Map prefixConfigMap = Collections.emptyMap(); - // Look up maps to speed things up private volatile Map namespaceToModuleName; @@ -45,16 +37,17 @@ public class ConfigurationImpl implements Configuration { this(new FileModuleShardConfigProvider(moduleShardsConfigPath, modulesConfigPath)); } + @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Subclassed for testing") public ConfigurationImpl(final ModuleShardConfigProvider provider) { ImmutableMap.Builder mapBuilder = ImmutableMap.builder(); - for (Map.Entry e: provider.retrieveModuleConfigs(this).entrySet()) { + for (Entry e: provider.retrieveModuleConfigs(this).entrySet()) { mapBuilder.put(e.getKey(), e.getValue().build()); } - this.moduleConfigMap = mapBuilder.build(); + moduleConfigMap = mapBuilder.build(); - this.allShardNames = createAllShardNames(moduleConfigMap.values()); - this.namespaceToModuleName = createNamespaceToModuleName(moduleConfigMap.values()); + allShardNames = createAllShardNames(moduleConfigMap.values()); + namespaceToModuleName = createNamespaceToModuleName(moduleConfigMap.values()); } private static Set createAllShardNames(final Iterable moduleConfigs) { @@ -120,24 +113,6 @@ public class ConfigurationImpl implements Configuration { return moduleConfigMap.get(requireNonNull(moduleName, "moduleName should not be null")); } - @Override - public String getShardNameForPrefix(final DOMDataTreeIdentifier prefix) { - requireNonNull(prefix, "prefix should not be null"); - - Entry bestMatchEntry = new SimpleEntry<>( - new DOMDataTreeIdentifier(prefix.getDatastoreType(), YangInstanceIdentifier.empty()), null); - - for (Entry entry : prefixConfigMap.entrySet()) { - if (entry.getKey().contains(prefix) && entry.getKey().getRootIdentifier().getPathArguments().size() - > bestMatchEntry.getKey().getRootIdentifier().getPathArguments().size()) { - bestMatchEntry = entry; - } - } - - //TODO we really should have mapping based on prefix instead of Strings - return ClusterUtils.getCleanShardName(bestMatchEntry.getKey().getRootIdentifier()); - } - @Override public Collection getMembersFromShardName(final String shardName) { checkNotNullShardName(shardName); @@ -149,13 +124,7 @@ public class ConfigurationImpl implements Configuration { } } - for (final PrefixShardConfiguration prefixConfig : prefixConfigMap.values()) { - if (shardName.equals(ClusterUtils.getCleanShardName(prefixConfig.getPrefix().getRootIdentifier()))) { - return prefixConfig.getShardMemberNames(); - } - } - - return Collections.emptyList(); + return List.of(); } private static void checkNotNullShardName(final String shardName) { @@ -193,40 +162,6 @@ public class ConfigurationImpl implements Configuration { allShardNames = ImmutableSet.builder().addAll(allShardNames).add(config.getShardName()).build(); } - @Override - public void addPrefixShardConfiguration(final PrefixShardConfiguration config) { - addPrefixConfig(requireNonNull(config, "PrefixShardConfiguration cannot be null")); - allShardNames = ImmutableSet.builder().addAll(allShardNames) - .add(ClusterUtils.getCleanShardName(config.getPrefix().getRootIdentifier())).build(); - } - - @Override - public void removePrefixShardConfiguration(final DOMDataTreeIdentifier prefix) { - removePrefixConfig(requireNonNull(prefix, "Prefix cannot be null")); - - final HashSet temp = new HashSet<>(allShardNames); - temp.remove(ClusterUtils.getCleanShardName(prefix.getRootIdentifier())); - - allShardNames = ImmutableSet.copyOf(temp); - } - - @Override - public Map getAllPrefixShardConfigurations() { - return ImmutableMap.copyOf(prefixConfigMap); - } - - private void addPrefixConfig(final PrefixShardConfiguration config) { - final Map newPrefixConfigMap = new HashMap<>(prefixConfigMap); - newPrefixConfigMap.put(config.getPrefix(), config); - prefixConfigMap = ImmutableMap.copyOf(newPrefixConfigMap); - } - - private void removePrefixConfig(final DOMDataTreeIdentifier prefix) { - final Map newPrefixConfigMap = new HashMap<>(prefixConfigMap); - newPrefixConfigMap.remove(prefix); - prefixConfigMap = ImmutableMap.copyOf(newPrefixConfigMap); - } - private ShardStrategy createShardStrategy(final String moduleName, final String shardStrategyName) { return ShardStrategyFactory.newShardStrategyInstance(moduleName, shardStrategyName, this); } @@ -269,28 +204,6 @@ public class ConfigurationImpl implements Configuration { } } - @Override - public ShardStrategy getStrategyForPrefix(final DOMDataTreeIdentifier prefix) { - requireNonNull(prefix, "Prefix cannot be null"); - // FIXME using prefix tables like in mdsal will be better - Entry bestMatchEntry = new SimpleEntry<>( - new DOMDataTreeIdentifier(prefix.getDatastoreType(), YangInstanceIdentifier.empty()), null); - - for (Entry entry : prefixConfigMap.entrySet()) { - if (entry.getKey().contains(prefix) && entry.getKey().getRootIdentifier().getPathArguments().size() - > bestMatchEntry.getKey().getRootIdentifier().getPathArguments().size()) { - bestMatchEntry = entry; - } - } - - if (bestMatchEntry.getValue() == null) { - return null; - } - return new PrefixShardStrategy(ClusterUtils - .getCleanShardName(bestMatchEntry.getKey().getRootIdentifier()), - bestMatchEntry.getKey().getRootIdentifier()); - } - private void updateModuleConfigMap(final ModuleConfig moduleConfig) { final Map newModuleConfigMap = new HashMap<>(moduleConfigMap); newModuleConfigMap.put(moduleConfig.getName(), moduleConfig);