include default settigns
This commit is contained in:
parent
dfb8bf658b
commit
5d7f4ef394
|
@ -48,10 +48,8 @@ public final class ClusterSettings {
|
|||
|
||||
private final Map<String, Setting<?>> groupSettings = new HashMap<>();
|
||||
private final Map<String, Setting<?>> keySettings = new HashMap<>();
|
||||
private final Settings defaults;
|
||||
|
||||
public ClusterSettings(Set<Setting<?>> settingsSet) {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
for (Setting<?> entry : settingsSet) {
|
||||
if (entry.getScope() != Setting.Scope.Cluster) {
|
||||
throw new IllegalArgumentException("Setting must be a cluster setting but was: " + entry.getScope());
|
||||
|
@ -61,9 +59,7 @@ public final class ClusterSettings {
|
|||
} else {
|
||||
keySettings.put(entry.getKey(), entry);
|
||||
}
|
||||
builder.put(entry.getKey(), entry.getDefault(Settings.EMPTY));
|
||||
}
|
||||
this.defaults = builder.build();
|
||||
}
|
||||
|
||||
public ClusterSettings() {
|
||||
|
@ -102,22 +98,16 @@ public final class ClusterSettings {
|
|||
return key.startsWith("logger.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cluster settings defaults
|
||||
*/
|
||||
public Settings getDefaults() {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a settings object that contains all clustersettings that are not
|
||||
* already set in the given source.
|
||||
* already set in the given source. The diff contains either the default value for each
|
||||
* setting or the settings value in the given default settings.
|
||||
*/
|
||||
public Settings diff(Settings source) {
|
||||
public Settings diff(Settings source, Settings defaultSettings) {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
for (Setting<?> setting : keySettings.values()) {
|
||||
if (setting.exists(source) == false) {
|
||||
builder.put(setting.getKey(), setting.getRaw(source));
|
||||
builder.put(setting.getKey(), setting.getRaw(defaultSettings));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
|
|
|
@ -57,12 +57,12 @@ public class RestClusterGetSettingsAction extends BaseRestHandler {
|
|||
client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
|
||||
return new BytesRestResponse(RestStatus.OK, renderResponse(clusterSettings, response.getState(), renderDefaults, builder, request));
|
||||
return new BytesRestResponse(RestStatus.OK, renderResponse(response.getState(), renderDefaults, builder, request));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static XContentBuilder renderResponse(ClusterSettings settings, ClusterState state, boolean renderDefaults, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
private XContentBuilder renderResponse(ClusterState state, boolean renderDefaults, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
||||
builder.startObject("persistent");
|
||||
|
@ -75,7 +75,7 @@ public class RestClusterGetSettingsAction extends BaseRestHandler {
|
|||
|
||||
if (renderDefaults) {
|
||||
builder.startObject("defaults");
|
||||
settings.diff(state.metaData().settings()).toXContent(builder, params);
|
||||
clusterSettings.diff(state.metaData().settings(), this.settings).toXContent(builder, params);
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
|
|
|
@ -50,8 +50,12 @@ public class ClusterSettingsTests extends ESTestCase {
|
|||
Setting<Integer> foobarbaz = Setting.intSetting("foo.bar.baz", 1, false, Setting.Scope.Cluster);
|
||||
Setting<Integer> foobar = Setting.intSetting("foo.bar", 1, true, Setting.Scope.Cluster);
|
||||
ClusterSettings settings = new ClusterSettings(new HashSet<>(Arrays.asList(foobar, foobarbaz)));
|
||||
Settings diff = settings.diff(Settings.builder().put("foo.bar", 5).build());
|
||||
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));
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue