diff --git a/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java b/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java index 2f6b79bff0e..05eb9e89ca0 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java @@ -7,6 +7,7 @@ package org.elasticsearch.marvel; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterModule; +import org.elasticsearch.cluster.settings.Validator; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.ESLogger; @@ -18,7 +19,6 @@ import org.elasticsearch.marvel.agent.exporter.ExporterModule; import org.elasticsearch.marvel.agent.exporter.Exporters; import org.elasticsearch.marvel.agent.renderer.RendererModule; import org.elasticsearch.marvel.agent.settings.MarvelModule; -import org.elasticsearch.marvel.agent.settings.MarvelSetting; import org.elasticsearch.marvel.agent.settings.MarvelSettings; import org.elasticsearch.marvel.license.LicenseModule; import org.elasticsearch.marvel.license.LicenseService; @@ -32,6 +32,7 @@ import org.elasticsearch.tribe.TribeService; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Map; public class MarvelPlugin extends Plugin { @@ -110,9 +111,8 @@ public class MarvelPlugin extends Plugin { public void onModule(ClusterModule module) { Exporters.registerDynamicSettings(module); - // MarvelSettingsService - for (MarvelSetting setting : MarvelSettings.dynamicSettings()) { - module.registerClusterDynamicSetting(setting.dynamicSettingName(), setting.dynamicValidator()); + for (Map.Entry setting : MarvelSettings.dynamicSettings().entrySet()) { + module.registerClusterDynamicSetting(setting.getKey(), setting.getValue()); } } } diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSetting.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSetting.java index 7519330af1c..ea9562a906f 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSetting.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSetting.java @@ -6,7 +6,6 @@ package org.elasticsearch.marvel.agent.settings; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.cluster.settings.Validator; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -17,15 +16,15 @@ public abstract class MarvelSetting { private final String name; private final String description; - private final boolean dynamic; + private final V defaultValue; private volatile V value; - MarvelSetting(String name, String description, V defaultValue, boolean dynamic) { + MarvelSetting(String name, String description, V defaultValue) { this.name = name; this.description = description; + this.defaultValue = defaultValue; this.value = defaultValue; - this.dynamic = dynamic; } abstract boolean onRefresh(Settings settings); @@ -42,6 +41,10 @@ public abstract class MarvelSetting { return value; } + public V getDefaultValue() { + return defaultValue; + } + public synchronized void setValue(V value) { this.value = value; } @@ -50,47 +53,35 @@ public abstract class MarvelSetting { return getValue() != null ? getValue().toString() : "null"; } - public boolean isDynamic() { - return dynamic; - } - - public String dynamicSettingName() { - return getName(); - } - - public Validator dynamicValidator() { - return Validator.EMPTY; - } - @Override public String toString() { return "marvel setting [" + getName() + " : " + getValueAsString() + "]"; } - public static BooleanSetting booleanSetting(String name, Boolean defaultValue, String description, boolean dynamic) { - return new BooleanSetting(name, description, defaultValue, dynamic); + public static BooleanSetting booleanSetting(String name, Boolean defaultValue, String description) { + return new BooleanSetting(name, description, defaultValue); } - public static StringSetting stringSetting(String name, String defaultValue, String description, boolean dynamic) { - return new StringSetting(name, description, defaultValue, dynamic); + public static StringSetting stringSetting(String name, String defaultValue, String description) { + return new StringSetting(name, description, defaultValue); } - public static StringArraySetting arraySetting(String name, String[] defaultValue, String description, boolean dynamic) { - return new StringArraySetting(name, description, defaultValue, dynamic); + public static StringArraySetting arraySetting(String name, String[] defaultValue, String description) { + return new StringArraySetting(name, description, defaultValue); } - public static TimeValueSetting timeSetting(String name, TimeValue defaultValue, String description, boolean dynamic) { - return new TimeValueSetting(name, description, defaultValue, dynamic); + public static TimeValueSetting timeSetting(String name, TimeValue defaultValue, String description) { + return new TimeValueSetting(name, description, defaultValue); } - public static TimeoutValueSetting timeoutSetting(String name, TimeValue defaultTimeoutValue, String description, boolean dynamic) { - return new TimeoutValueSetting(name, description, defaultTimeoutValue, dynamic); + public static TimeoutValueSetting timeoutSetting(String name, TimeValue defaultTimeoutValue, String description) { + return new TimeoutValueSetting(name, description, defaultTimeoutValue); } static class BooleanSetting extends MarvelSetting { - BooleanSetting(String name, String description, Boolean defaultValue, boolean dynamic) { - super(name, description, defaultValue, dynamic); + BooleanSetting(String name, String description, Boolean defaultValue) { + super(name, description, defaultValue); } @Override @@ -102,17 +93,12 @@ public abstract class MarvelSetting { } return false; } - - @Override - public Validator dynamicValidator() { - return Validator.BOOLEAN; - } } static class StringSetting extends MarvelSetting { - StringSetting(String name, String description, String defaultValue, boolean dynamic) { - super(name, description, defaultValue, dynamic); + StringSetting(String name, String description, String defaultValue) { + super(name, description, defaultValue); } @Override @@ -128,8 +114,8 @@ public abstract class MarvelSetting { static class StringArraySetting extends MarvelSetting { - StringArraySetting(String name, String description, String[] defaultValue, boolean dynamic) { - super(name, description, defaultValue, dynamic); + StringArraySetting(String name, String description, String[] defaultValue) { + super(name, description, defaultValue); } @Override @@ -142,12 +128,6 @@ public abstract class MarvelSetting { return false; } - @Override - public String dynamicSettingName() { - // array settings - return super.dynamicSettingName() + ".*"; - } - @Override public String getValueAsString() { return Strings.arrayToCommaDelimitedString(getValue()); @@ -156,8 +136,8 @@ public abstract class MarvelSetting { static class TimeValueSetting extends MarvelSetting { - TimeValueSetting(String name, String description, TimeValue defaultValue, boolean dynamic) { - super(name, description, defaultValue, dynamic); + TimeValueSetting(String name, String description, TimeValue defaultValue) { + super(name, description, defaultValue); } @Override @@ -184,22 +164,12 @@ public abstract class MarvelSetting { } return null; } - - @Override - public Validator dynamicValidator() { - return Validator.TIME; - } } static class TimeoutValueSetting extends TimeValueSetting { - TimeoutValueSetting(String name, String description, TimeValue defaultValue, boolean dynamic) { - super(name, description, defaultValue, dynamic); - } - - @Override - public Validator dynamicValidator() { - return Validator.TIMEOUT; + TimeoutValueSetting(String name, String description, TimeValue defaultValue) { + super(name, description, defaultValue); } } } diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettings.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettings.java index 2c72fc6ea21..7e14bc567d3 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettings.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettings.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.marvel.agent.settings; +import org.elasticsearch.cluster.settings.Validator; import org.elasticsearch.common.Strings; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; @@ -13,7 +14,10 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.marvel.MarvelPlugin; import org.elasticsearch.node.settings.NodeSettingsService; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import static org.elasticsearch.marvel.agent.settings.MarvelSetting.*; @@ -37,60 +41,74 @@ public class MarvelSettings extends AbstractComponent implements NodeSettingsSer public static final String COLLECTORS = PREFIX + "collectors"; public static final String LICENSE_GRACE_PERIOD = PREFIX + "license.grace.period"; - private static Map MARVEL_SETTINGS = Collections.EMPTY_MAP; - - static { - Map map = new HashMap<>(); - map.put(INTERVAL, timeSetting(INTERVAL, TimeValue.timeValueSeconds(10), - "Sampling interval between two collections (default to 10s)", true)); - map.put(STARTUP_DELAY, timeSetting(STARTUP_DELAY, null, - "Waiting time before the agent start to collect data (default to sampling interval)", false)); - map.put(INDEX_STATS_TIMEOUT, timeoutSetting(INDEX_STATS_TIMEOUT, TimeValue.timeValueMinutes(10), - "Timeout value when collecting index statistics (default to 10m)", true)); - map.put(INDICES_STATS_TIMEOUT, timeoutSetting(INDICES_STATS_TIMEOUT, TimeValue.timeValueMinutes(10), - "Timeout value when collecting total indices statistics (default to 10m)", true)); - map.put(INDICES, arraySetting(INDICES, Strings.EMPTY_ARRAY, - "List of indices names whose stats will be exported (default to all indices)", true)); - map.put(CLUSTER_STATE_TIMEOUT, timeoutSetting(CLUSTER_STATE_TIMEOUT, TimeValue.timeValueMinutes(10), - "Timeout value when collecting the cluster state (default to 10m)", true)); - map.put(CLUSTER_STATS_TIMEOUT, timeoutSetting(CLUSTER_STATS_TIMEOUT, TimeValue.timeValueMinutes(10), - "Timeout value when collecting the cluster statistics (default to 10m)", true)); - map.put(INDEX_RECOVERY_TIMEOUT, timeoutSetting(INDEX_RECOVERY_TIMEOUT, TimeValue.timeValueMinutes(10), - "Timeout value when collecting the recovery information (default to 10m)", true)); - map.put(INDEX_RECOVERY_ACTIVE_ONLY, booleanSetting(INDEX_RECOVERY_ACTIVE_ONLY, Boolean.FALSE, - "Flag to indicate if only active recoveries should be collected (default to false: all recoveries are collected)", true)); - map.put(COLLECTORS, arraySetting(COLLECTORS, Strings.EMPTY_ARRAY, - "List of collectors allowed to collect data (default to all)", false)); - map.put(LICENSE_GRACE_PERIOD, timeSetting(LICENSE_GRACE_PERIOD, MAX_LICENSE_GRACE_PERIOD, - "Period during which the agent continues to collect data even if the license is expired (default to 7 days, cannot be greater than 7 days)", false)); - MARVEL_SETTINGS = Collections.unmodifiableMap(map); - } + private Map settings = Collections.EMPTY_MAP; @Inject public MarvelSettings(Settings clusterSettings, NodeSettingsService nodeSettingsService) { super(clusterSettings); - logger.trace("initializing marvel settings:"); - updateSettings(clusterSettings, false); + logger.trace("initializing marvel settings"); + this.settings = defaultSettings(); + + logger.trace("updating marvel settings with cluster settings"); + updateSettings(clusterSettings); logger.trace("registering the service as a node settings listener"); nodeSettingsService.addListener(this); } + private Map defaultSettings() { + Map map = new HashMap<>(); + map.put(INTERVAL, timeSetting(INTERVAL, TimeValue.timeValueSeconds(10), + "Sampling interval between two collections (default to 10s)")); + map.put(STARTUP_DELAY, timeSetting(STARTUP_DELAY, null, + "Waiting time before the agent start to collect data (default to sampling interval)")); + map.put(INDEX_STATS_TIMEOUT, timeoutSetting(INDEX_STATS_TIMEOUT, TimeValue.timeValueMinutes(10), + "Timeout value when collecting index statistics (default to 10m)")); + map.put(INDICES_STATS_TIMEOUT, timeoutSetting(INDICES_STATS_TIMEOUT, TimeValue.timeValueMinutes(10), + "Timeout value when collecting total indices statistics (default to 10m)")); + map.put(INDICES, arraySetting(INDICES, Strings.EMPTY_ARRAY, + "List of indices names whose stats will be exported (default to all indices)")); + map.put(CLUSTER_STATE_TIMEOUT, timeoutSetting(CLUSTER_STATE_TIMEOUT, TimeValue.timeValueMinutes(10), + "Timeout value when collecting the cluster state (default to 10m)")); + map.put(CLUSTER_STATS_TIMEOUT, timeoutSetting(CLUSTER_STATS_TIMEOUT, TimeValue.timeValueMinutes(10), + "Timeout value when collecting the cluster statistics (default to 10m)")); + map.put(INDEX_RECOVERY_TIMEOUT, timeoutSetting(INDEX_RECOVERY_TIMEOUT, TimeValue.timeValueMinutes(10), + "Timeout value when collecting the recovery information (default to 10m)")); + map.put(INDEX_RECOVERY_ACTIVE_ONLY, booleanSetting(INDEX_RECOVERY_ACTIVE_ONLY, Boolean.FALSE, + "Flag to indicate if only active recoveries should be collected (default to false: all recoveries are collected)")); + map.put(COLLECTORS, arraySetting(COLLECTORS, Strings.EMPTY_ARRAY, + "List of collectors allowed to collect data (default to all)")); + map.put(LICENSE_GRACE_PERIOD, timeSetting(LICENSE_GRACE_PERIOD, MAX_LICENSE_GRACE_PERIOD, + "Period during which the agent continues to collect data even if the license is expired (default to 7 days, cannot be greater than 7 days)")); + return Collections.unmodifiableMap(map); + } + + public static Map dynamicSettings() { + Map dynamics = new HashMap<>(); + dynamics.put(INTERVAL, Validator.TIME); + dynamics.put(INDEX_STATS_TIMEOUT, Validator.TIMEOUT); + dynamics.put(INDICES_STATS_TIMEOUT, Validator.TIMEOUT); + dynamics.put(INDICES + ".*", Validator.EMPTY); + dynamics.put(CLUSTER_STATE_TIMEOUT, Validator.TIMEOUT); + dynamics.put(CLUSTER_STATS_TIMEOUT, Validator.TIMEOUT); + dynamics.put(INDEX_RECOVERY_TIMEOUT, Validator.TIMEOUT); + dynamics.put(INDEX_RECOVERY_ACTIVE_ONLY, Validator.BOOLEAN); + return dynamics; + } + @Override public void onRefreshSettings(Settings clusterSettings) { if (clusterSettings.names() == null || clusterSettings.names().isEmpty()) { return; } - updateSettings(clusterSettings, true); + updateSettings(clusterSettings); } - private synchronized void updateSettings(Settings clusterSettings, boolean dynamicOnly) { - for (MarvelSetting setting : settings()) { - if (!dynamicOnly || setting.isDynamic()) { - if (setting.onRefresh(clusterSettings)) { - logger.info("{} updated", setting); - } + private void updateSettings(Settings clusterSettings) { + for (MarvelSetting setting : settings.values()) { + if (setting.onRefresh(clusterSettings)) { + logger.info("{} updated", setting); } } } @@ -101,8 +119,8 @@ public class MarvelSettings extends AbstractComponent implements NodeSettingsSer * @param name The given name * @return The associated setting, null if not found */ - synchronized MarvelSetting getSetting(String name) { - MarvelSetting setting = MARVEL_SETTINGS.get(name); + MarvelSetting getSetting(String name) { + MarvelSetting setting = settings.get(name); if (setting == null) { throw new IllegalArgumentException("no marvel setting initialized for [" + name + "]"); } @@ -123,18 +141,8 @@ public class MarvelSettings extends AbstractComponent implements NodeSettingsSer return (T) setting.getValue(); } - public static Collection settings() { - return MARVEL_SETTINGS.values(); - } - - public static synchronized Collection dynamicSettings() { - List list = new ArrayList<>(); - for (MarvelSetting setting : settings()) { - if (setting.isDynamic()) { - list.add(setting); - } - } - return list; + Collection settings() { + return settings.values(); } public TimeValue interval() { diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingTests.java index 10a6dbdb298..e367537b095 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingTests.java @@ -23,9 +23,8 @@ public class MarvelSettingTests extends ESTestCase { if (randomBoolean()) { defaultValue = randomBoolean(); } - boolean dynamic = randomBoolean(); - MarvelSetting.BooleanSetting setting = MarvelSetting.booleanSetting(name, defaultValue, description, dynamic); + MarvelSetting.BooleanSetting setting = MarvelSetting.booleanSetting(name, defaultValue, description); assertThat(setting.getName(), equalTo(name)); assertThat(setting.getDescription(), equalTo(description)); assertThat(setting.getValue(), equalTo(defaultValue)); @@ -43,11 +42,10 @@ public class MarvelSettingTests extends ESTestCase { String description = randomAsciiOfLength(20); TimeValue defaultValue = null; if (randomBoolean()) { - defaultValue = randomParsedTimeValue(); + defaultValue = newRandomTimeValue(); } - boolean dynamic = randomBoolean(); - MarvelSetting.TimeValueSetting setting = MarvelSetting.timeSetting(name, defaultValue, description, dynamic); + MarvelSetting.TimeValueSetting setting = MarvelSetting.timeSetting(name, defaultValue, description); assertThat(setting.getName(), equalTo(name)); assertThat(setting.getDescription(), equalTo(description)); if (defaultValue == null) { @@ -59,11 +57,11 @@ public class MarvelSettingTests extends ESTestCase { setting.onRefresh(settingsBuilder().put(name, 15000L).build()); assertThat(setting.getValue().millis(), equalTo(15000L)); - TimeValue updated = randomParsedTimeValue(); + TimeValue updated = newRandomTimeValue(); setting.onRefresh(settingsBuilder().put(name, updated.toString()).build()); assertThat(setting.getValue().millis(), equalTo(updated.millis())); - updated = randomParsedTimeValue(); + updated = newRandomTimeValue(); setting.onRefresh(settingsBuilder().put(name, updated.toString()).build()); assertThat(setting.getValue().millis(), equalTo(updated.millis())); } @@ -76,9 +74,8 @@ public class MarvelSettingTests extends ESTestCase { if (randomBoolean()) { defaultValue = randomAsciiOfLength(15); } - boolean dynamic = randomBoolean(); - MarvelSetting.StringSetting setting = MarvelSetting.stringSetting(name, defaultValue, description, dynamic); + MarvelSetting.StringSetting setting = MarvelSetting.stringSetting(name, defaultValue, description); assertThat(setting.getName(), equalTo(name)); assertThat(setting.getDescription(), equalTo(description)); if (defaultValue == null) { @@ -107,9 +104,8 @@ public class MarvelSettingTests extends ESTestCase { if (randomBoolean()) { defaultValue = randomStringArray(); } - boolean dynamic = randomBoolean(); - MarvelSetting.StringArraySetting setting = MarvelSetting.arraySetting(name, defaultValue, description, dynamic); + MarvelSetting.StringArraySetting setting = MarvelSetting.arraySetting(name, defaultValue, description); assertThat(setting.getName(), equalTo(name)); assertThat(setting.getDescription(), equalTo(description)); if (defaultValue == null) { @@ -130,7 +126,7 @@ public class MarvelSettingTests extends ESTestCase { assertArrayEquals(setting.getValue(), updated); } - private TimeValue randomParsedTimeValue() { + private TimeValue newRandomTimeValue() { return TimeValue.parseTimeValue(randomFrom("10ms", "1.5s", "1.5m", "1.5h", "1.5d", "1000d"), null, getClass().getSimpleName() + ".unit"); } diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java index c963bd40a95..0a597b7b220 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsTests.java @@ -8,30 +8,24 @@ package org.elasticsearch.marvel.agent.settings; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.license.plugin.LicensePlugin; -import org.elasticsearch.marvel.MarvelPlugin; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.node.Node; -import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; -import java.util.Arrays; -import java.util.Collection; - import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.*; @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1) public class MarvelSettingsTests extends MarvelIntegTestCase { - private final TimeValue startUp = randomParsedTimeValue(); - private final TimeValue interval = randomParsedTimeValue(); - private final TimeValue indexStatsTimeout = randomParsedTimeValue(); + private final TimeValue startUp = newRandomTimeValue(); + private final TimeValue interval = newRandomTimeValue(); + private final TimeValue indexStatsTimeout = newRandomTimeValue(); private final String[] indices = randomStringArray(); - private final TimeValue clusterStateTimeout = randomParsedTimeValue(); - private final TimeValue clusterStatsTimeout = randomParsedTimeValue(); - private final TimeValue recoveryTimeout = randomParsedTimeValue(); + private final TimeValue clusterStateTimeout = newRandomTimeValue(); + private final TimeValue clusterStatsTimeout = newRandomTimeValue(); + private final TimeValue recoveryTimeout = newRandomTimeValue(); private final Boolean recoveryActiveOnly = randomBoolean(); private final String[] collectors = randomStringArray(); private final TimeValue licenseGracePeriod = randomExpirationDelay(); @@ -61,12 +55,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { } @Test - public void testMarvelSettingService() throws Exception { - logger.info("--> printing marvel settings values"); - for (MarvelSetting setting : MarvelSettings.settings()) { - logger.info("\t{}", setting); - } - + public void testMarvelSettings() throws Exception { logger.info("--> testing marvel settings service initialization"); for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) { assertThat(marvelSettings.startUpDelay().millis(), equalTo(startUp.millis())); @@ -79,31 +68,37 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { assertThat(marvelSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly)); assertArrayEquals(marvelSettings.collectors(), collectors); assertThat(marvelSettings.licenseExpirationGracePeriod().millis(), allOf(greaterThanOrEqualTo(0L), lessThanOrEqualTo(MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis()))); - - for (final MarvelSetting setting : MarvelSettings.dynamicSettings()) { - assertThat(marvelSettings.getSettingValue(setting.getName()), equalTo(setting.getValue())); - } } logger.info("--> testing marvel dynamic settings update"); - for (final MarvelSetting setting : MarvelSettings.dynamicSettings()) { + for (String setting : MarvelSettings.dynamicSettings().keySet()) { Object updated = null; Settings.Builder transientSettings = Settings.builder(); - if (setting instanceof MarvelSetting.TimeValueSetting) { - updated = randomParsedTimeValue(); - transientSettings.put(setting.getName(), updated); - } else if (setting instanceof MarvelSetting.BooleanSetting) { - updated = randomBoolean(); - transientSettings.put(setting.getName(), updated); + if (setting.endsWith(".*")) { + setting = setting.substring(0, setting.lastIndexOf('.')); + } - } else if (setting instanceof MarvelSetting.StringSetting) { - updated = randomAsciiOfLength(10); - transientSettings.put(setting.getName(), updated); - - } else if (setting instanceof MarvelSetting.StringArraySetting) { - updated = randomStringArray(); - transientSettings.putArray(setting.getName(), (String[]) updated); + switch (setting) { + case MarvelSettings.INTERVAL: + case MarvelSettings.INDEX_STATS_TIMEOUT: + case MarvelSettings.INDICES_STATS_TIMEOUT: + case MarvelSettings.CLUSTER_STATE_TIMEOUT: + case MarvelSettings.CLUSTER_STATS_TIMEOUT: + case MarvelSettings.INDEX_RECOVERY_TIMEOUT: + updated = newRandomTimeValue(); + transientSettings.put(setting, updated); + break; + case MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY: + updated = randomBoolean(); + transientSettings.put(setting, updated); + break; + case MarvelSettings.INDICES: + updated = randomStringArray(); + transientSettings.putArray(setting, (String[]) updated); + break; + default: + fail("unknown dynamic setting [" + setting +"]"); } logger.info("--> updating {} to value [{}]", setting, updated); @@ -111,25 +106,28 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { // checking that the value has been correctly updated on all marvel settings services final Object expected = updated; + final String finalSetting = setting; assertBusy(new Runnable() { @Override public void run() { for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) { - MarvelSetting current = marvelSettings.getSetting(setting.getName()); + MarvelSetting current = marvelSettings.getSetting(finalSetting); Object value = current.getValue(); logger.info("--> {} in {}", current, marvelSettings); - if (setting instanceof MarvelSetting.TimeValueSetting) { + if (current instanceof MarvelSetting.TimeValueSetting) { assertThat(((TimeValue) value).millis(), equalTo(((TimeValue) expected).millis())); - } else if (setting instanceof MarvelSetting.BooleanSetting) { + } else if (current instanceof MarvelSetting.BooleanSetting) { assertThat((Boolean) value, equalTo((Boolean) expected)); - } else if (setting instanceof MarvelSetting.StringSetting) { + } else if (current instanceof MarvelSetting.StringSetting) { assertThat((String) value, equalTo((String) expected)); - } else if (setting instanceof MarvelSetting.StringArraySetting) { + } else if (current instanceof MarvelSetting.StringArraySetting) { assertArrayEquals((String[]) value, (String[]) expected); + } else { + fail("unable to check value for unknown dynamic setting [" + finalSetting + "]"); } } } @@ -147,7 +145,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { return requestBuilder; } - private TimeValue randomParsedTimeValue() { + private TimeValue newRandomTimeValue() { return TimeValue.parseTimeValue(randomFrom("30m", "1h", "3h", "5h", "7h", "10h", "1d"), null, getClass().getSimpleName()); } @@ -162,6 +160,6 @@ public class MarvelSettingsTests extends MarvelIntegTestCase { } private TimeValue randomExpirationDelay() { - return randomBoolean() ? randomParsedTimeValue() : TimeValue.timeValueHours(randomIntBetween(-10, 10) * 24); + return randomBoolean() ? newRandomTimeValue() : TimeValue.timeValueHours(randomIntBetween(-10, 10) * 24); } }