From 6013234560e3b321b6f5a4f996c8be0a30cb25aa Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 27 Sep 2016 20:25:03 -0400 Subject: [PATCH] Include complex settings in settings requests Today when getting setting via an API like the cluster settings API, complex settings are excluded (e.g., discovery.zen.ping.unicast.hosts). This commit adds these settings to the output of such APIs. Relates #20622 --- .../settings/AbstractScopedSettings.java | 5 ++++ .../common/settings/ScopedSettingsTests.java | 24 ++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java index 787fa950bea..9a392860096 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java @@ -375,6 +375,11 @@ public abstract class AbstractScopedSettings extends AbstractComponent { builder.put(setting.getKey(), setting.getRaw(defaultSettings)); } } + for (Setting setting : complexMatchers.values()) { + if (setting.exists(source) == false) { + builder.put(setting.getKey(), setting.getRaw(defaultSettings)); + } + } return builder.build(); } diff --git a/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java b/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java index bd6cb530b2b..635c00c1860 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java @@ -41,6 +41,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; +import static org.hamcrest.CoreMatchers.equalTo; + public class ScopedSettingsTests extends ESTestCase { public void testAddConsumer() { @@ -156,16 +158,22 @@ public class ScopedSettingsTests extends ESTestCase { } public void testDiff() throws IOException { - Setting foobarbaz = Setting.intSetting("foo.bar.baz", 1, Property.NodeScope); - Setting foobar = Setting.intSetting("foo.bar", 1, Property.Dynamic, Property.NodeScope); - ClusterSettings settings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(foobar, foobarbaz))); + Setting fooBarBaz = Setting.intSetting("foo.bar.baz", 1, Property.NodeScope); + Setting fooBar = Setting.intSetting("foo.bar", 1, Property.Dynamic, Property.NodeScope); + Setting> foorBarQuux = + Setting.listSetting("foo.bar.quux", Arrays.asList("a", "b", "c"), Function.identity(), Property.NodeScope); + ClusterSettings settings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(fooBar, fooBarBaz, foorBarQuux))); Settings diff = settings.diff(Settings.builder().put("foo.bar", 5).build(), Settings.EMPTY); - assertEquals(diff.getAsMap().size(), 1); - assertEquals(diff.getAsInt("foo.bar.baz", null), Integer.valueOf(1)); + assertThat(diff.getAsMap().size(), equalTo(2)); + assertThat(diff.getAsInt("foo.bar.baz", null), equalTo(1)); + assertThat(diff.get("foo.bar.quux", null), equalTo("[\"a\",\"b\",\"c\"]")); - diff = settings.diff(Settings.builder().put("foo.bar", 5).build(), Settings.builder().put("foo.bar.baz", 17).build()); - assertEquals(diff.getAsMap().size(), 1); - assertEquals(diff.getAsInt("foo.bar.baz", null), Integer.valueOf(17)); + diff = settings.diff( + Settings.builder().put("foo.bar", 5).build(), + Settings.builder().put("foo.bar.baz", 17).put("foo.bar.quux", "d,e,f").build()); + assertThat(diff.getAsMap().size(), equalTo(2)); + assertThat(diff.getAsInt("foo.bar.baz", null), equalTo(17)); + assertThat(diff.get("foo.bar.quux", null), equalTo("[\"d\",\"e\",\"f\"]")); } public void testUpdateTracer() {