move setting registration into settings module - this stuff needs to be present for transport clients as well.

This commit is contained in:
Simon Willnauer 2015-12-09 10:30:18 +01:00
parent d4e7bd2cc3
commit 3d946871e8
4 changed files with 33 additions and 34 deletions

View File

@ -108,7 +108,6 @@ public class ClusterModule extends AbstractModule {
SnapshotInProgressAllocationDecider.class));
private final Settings settings;
private final Map<String, Setting<?>> clusterDynamicSettings = new HashMap<>();
private final DynamicSettings.Builder indexDynamicSettings = new DynamicSettings.Builder();
private final ExtensionPoint.SelectedType<ShardsAllocator> shardsAllocators = new ExtensionPoint.SelectedType<>("shards_allocator", ShardsAllocator.class);
private final ExtensionPoint.ClassSet<AllocationDecider> allocationDeciders = new ExtensionPoint.ClassSet<>("allocation_decider", AllocationDecider.class, AllocationDeciders.class);
@ -120,7 +119,6 @@ public class ClusterModule extends AbstractModule {
public ClusterModule(Settings settings) {
this.settings = settings;
registerBuiltinClusterSettings();
registerBuiltinIndexSettings();
for (Class<? extends AllocationDecider> decider : ClusterModule.DEFAULT_ALLOCATION_DECIDERS) {
@ -130,12 +128,6 @@ public class ClusterModule extends AbstractModule {
registerShardsAllocator(ClusterModule.EVEN_SHARD_COUNT_ALLOCATOR, BalancedShardsAllocator.class);
}
private void registerBuiltinClusterSettings() {
for (Setting<?> setting : ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) {
registerSetting(setting);
}
}
private void registerBuiltinIndexSettings() {
registerIndexDynamicSetting(IndexStore.INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, Validator.BYTES_SIZE);
registerIndexDynamicSetting(IndexStore.INDEX_STORE_THROTTLE_TYPE, Validator.EMPTY);
@ -204,18 +196,6 @@ public class ClusterModule extends AbstractModule {
indexDynamicSettings.addSetting(setting, validator);
}
public void registerSetting(Setting<?> setting) {
switch (setting.getScope()) {
case Cluster:
if (clusterDynamicSettings.containsKey(setting.getKey())) {
throw new IllegalArgumentException("Cannot register setting [" + setting.getKey() + "] twice");
}
clusterDynamicSettings.put(setting.getKey(), setting);
break;
case Index:
throw new UnsupportedOperationException("not yet implemented");
}
}
public void registerAllocationDecider(Class<? extends AllocationDecider> allocationDecider) {
allocationDeciders.registerExtension(allocationDecider);
@ -261,9 +241,5 @@ public class ClusterModule extends AbstractModule {
bind(NodeIndexDeletedAction.class).asEagerSingleton();
bind(NodeMappingRefreshAction.class).asEagerSingleton();
bind(MappingUpdatedAction.class).asEagerSingleton();
final ClusterSettings clusterSettings = new ClusterSettings(settings, new HashSet<>(clusterDynamicSettings.values()));
bind(ClusterSettings.class).toInstance(clusterSettings);
}
}

View File

@ -21,13 +21,11 @@ package org.elasticsearch.common.settings;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLoggerFactory;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
/**
* A basic setting service that can be used for per-index and per-cluster settings.
@ -152,7 +150,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
/**
* Adds a settings consumer with a predicate that is only evaluated at update time.
* <p>
* Note: Only settings registered in {@link org.elasticsearch.cluster.ClusterModule} can be changed dynamically.
* Note: Only settings registered in {@link SettingsModule} can be changed dynamically.
* </p>
*/
public synchronized <T> void addSettingsUpdateConsumer(Setting<T> setting, Consumer<T> consumer, Consumer<T> predicate) {
@ -165,7 +163,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
/**
* Adds a settings consumer that accepts the values for two settings. The consumer if only notified if one or both settings change.
* <p>
* Note: Only settings registered in {@link org.elasticsearch.cluster.ClusterModule} can be changed dynamically.
* Note: Only settings registered in {@link SettingsModule} can be changed dynamically.
* </p>
* This method registers a compound updater that is useful if two settings are depending on each other. The consumer is always provided
* with both values even if only one of the two changes.

View File

@ -21,6 +21,10 @@ package org.elasticsearch.common.settings;
import org.elasticsearch.common.inject.AbstractModule;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
/**
* A module that binds the provided settings to the {@link Settings} interface.
*
@ -30,15 +34,36 @@ public class SettingsModule extends AbstractModule {
private final Settings settings;
private final SettingsFilter settingsFilter;
private final Map<String, Setting<?>> clusterDynamicSettings = new HashMap<>();
public SettingsModule(Settings settings, SettingsFilter settingsFilter) {
this.settings = settings;
this.settingsFilter = settingsFilter;
for (Setting<?> setting : ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) {
registerSetting(setting);
}
}
@Override
protected void configure() {
bind(Settings.class).toInstance(settings);
bind(SettingsFilter.class).toInstance(settingsFilter);
final ClusterSettings clusterSettings = new ClusterSettings(settings, new HashSet<>(clusterDynamicSettings.values()));
bind(ClusterSettings.class).toInstance(clusterSettings);
}
}
public void registerSetting(Setting<?> setting) {
switch (setting.getScope()) {
case Cluster:
if (clusterDynamicSettings.containsKey(setting.getKey())) {
throw new IllegalArgumentException("Cannot register setting [" + setting.getKey() + "] twice");
}
clusterDynamicSettings.put(setting.getKey(), setting);
break;
case Index:
throw new UnsupportedOperationException("not yet implemented");
}
}
}

View File

@ -34,9 +34,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDeci
import org.elasticsearch.cluster.settings.DynamicSettings;
import org.elasticsearch.cluster.settings.Validator;
import org.elasticsearch.common.inject.ModuleTestCase;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.*;
import org.elasticsearch.index.settings.IndexDynamicSettings;
public class ClusterModuleTests extends ModuleTestCase {
@ -74,7 +72,8 @@ public class ClusterModuleTests extends ModuleTestCase {
}
public void testRegisterClusterDynamicSettingDuplicate() {
ClusterModule module = new ClusterModule(Settings.EMPTY);
final SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY);
SettingsModule module = new SettingsModule(Settings.EMPTY, settingsFilter);
try {
module.registerSetting(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING);
} catch (IllegalArgumentException e) {
@ -83,7 +82,8 @@ public class ClusterModuleTests extends ModuleTestCase {
}
public void testRegisterClusterDynamicSetting() {
ClusterModule module = new ClusterModule(Settings.EMPTY);
final SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY);
SettingsModule module = new SettingsModule(Settings.EMPTY, settingsFilter);
module.registerSetting(Setting.boolSetting("foo.bar", false, true, Setting.Scope.Cluster));
assertInstanceBinding(module, ClusterSettings.class, service -> service.hasDynamicSetting("foo.bar"));
}