dynamic settings validation to allow for simple match patterns

This commit is contained in:
Shay Banon 2011-09-06 22:01:25 +03:00
parent 6a78cc2b72
commit 60a73c475f
4 changed files with 23 additions and 3 deletions

View File

@ -72,7 +72,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
ImmutableSettings.Builder transientSettings = ImmutableSettings.settingsBuilder();
transientSettings.put(currentState.metaData().transientSettings());
for (Map.Entry<String, String> entry : request.transientSettings().getAsMap().entrySet()) {
if (MetaData.dynamicSettings().contains(entry.getKey()) || entry.getKey().startsWith("logger.")) {
if (MetaData.hasDynamicSetting(entry.getKey()) || entry.getKey().startsWith("logger.")) {
transientSettings.put(entry.getKey(), entry.getValue());
changed = true;
} else {
@ -83,7 +83,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
ImmutableSettings.Builder persistentSettings = ImmutableSettings.settingsBuilder();
persistentSettings.put(currentState.metaData().persistentSettings());
for (Map.Entry<String, String> entry : request.persistentSettings().getAsMap().entrySet()) {
if (MetaData.dynamicSettings().contains(entry.getKey()) || entry.getKey().startsWith("logger.")) {
if (MetaData.hasDynamicSetting(entry.getKey()) || entry.getKey().startsWith("logger.")) {
changed = true;
persistentSettings.put(entry.getKey(), entry.getValue());
} else {

View File

@ -26,6 +26,7 @@ import org.elasticsearch.common.collect.ImmutableSet;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.Immutable;
@ -56,6 +57,15 @@ public class IndexMetaData {
return dynamicSettings;
}
public static boolean hasDynamicSetting(String key) {
for (String dynamicSetting : dynamicSettings) {
if (Regex.simpleMatch(dynamicSetting, key)) {
return true;
}
}
return false;
}
public static synchronized void addDynamicSettings(String... settings) {
HashSet<String> updatedSettings = new HashSet<String>(dynamicSettings);
updatedSettings.addAll(Arrays.asList(settings));

View File

@ -30,6 +30,7 @@ import org.elasticsearch.common.collect.Sets;
import org.elasticsearch.common.collect.UnmodifiableIterator;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.trove.set.hash.THashSet;
@ -68,6 +69,15 @@ public class MetaData implements Iterable<IndexMetaData> {
return dynamicSettings;
}
public static boolean hasDynamicSetting(String key) {
for (String dynamicSetting : dynamicSettings) {
if (Regex.simpleMatch(dynamicSetting, key)) {
return true;
}
}
return false;
}
public static synchronized void addDynamicSettings(String... settings) {
HashSet<String> updatedSettings = new HashSet<String>(dynamicSettings);
updatedSettings.addAll(Arrays.asList(settings));

View File

@ -137,7 +137,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
final Set<String> removedSettings = Sets.newHashSet();
for (String key : updatedSettingsBuilder.internalMap().keySet()) {
if (!IndexMetaData.dynamicSettings().contains(key)) {
if (!IndexMetaData.hasDynamicSetting(key)) {
removedSettings.add(key);
}
}