From 62d28fba8eb7cb2e4e4ae8798e0eed0ffa3415ea Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 14 Sep 2018 14:47:53 -0700 Subject: [PATCH 01/12] WIP --- .../ClusterGetSettingsRequestBuilder.java | 101 ++++++++++++++++++ .../client/support/AbstractClient.java | 5 + .../cluster/ClusterStatsCollector.java | 6 +- 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java new file mode 100644 index 0000000000000..b3d3b31581222 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.cluster.settings; + +import org.elasticsearch.action.support.master.MasterNodeReadRequestBuilder; +import org.elasticsearch.client.ElasticsearchClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; + +import java.util.Map; + +/** + * Builder for a cluster get settings request + */ +public class ClusterGetSettingsRequestBuilder extends MasterNodeReadOperationRequestBuilder { + + public ClusterGetSettingsRequestBuilder(ElasticsearchClient client, ClusterGetSettingsAction action) { + super(client, action, new ClusterGetSettingsRequest()); + } + + /** + * Sets the transient settings to be updated. They will not survive a full cluster restart + */ + public ClusterGetSettingsRequestBuilder setTransientSettings(Settings settings) { + request.transientSettings(settings); + return this; + } + + /** + * Sets the transient settings to be updated. They will not survive a full cluster restart + */ + public ClusterGetSettingsRequestBuilder setTransientSettings(Settings.Builder settings) { + request.transientSettings(settings); + return this; + } + + /** + * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart + */ + public ClusterGetSettingsRequestBuilder setTransientSettings(String settings, XContentType xContentType) { + request.transientSettings(settings, xContentType); + return this; + } + + /** + * Sets the transient settings to be updated. They will not survive a full cluster restart + */ + public ClusterGetSettingsRequestBuilder setTransientSettings(Map settings) { + request.transientSettings(settings); + return this; + } + + /** + * Sets the persistent settings to be updated. They will get applied cross restarts + */ + public ClusterGetSettingsRequestBuilder setPersistentSettings(Settings settings) { + request.persistentSettings(settings); + return this; + } + + /** + * Sets the persistent settings to be updated. They will get applied cross restarts + */ + public ClusterGetSettingsRequestBuilder setPersistentSettings(Settings.Builder settings) { + request.persistentSettings(settings); + return this; + } + + /** + * Sets the source containing the persistent settings to be updated. They will get applied cross restarts + */ + public ClusterGetSettingsRequestBuilder setPersistentSettings(String settings, XContentType xContentType) { + request.persistentSettings(settings, xContentType); + return this; + } + + /** + * Sets the persistent settings to be updated. They will get applied cross restarts + */ + public ClusterGetSettingsRequestBuilder setPersistentSettings(Map settings) { + request.persistentSettings(settings); + return this; + } +} diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 553c92e6de86e..f14cf1e6103cd 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -761,6 +761,11 @@ public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { return new ClusterUpdateSettingsRequestBuilder(this, ClusterUpdateSettingsAction.INSTANCE); } + @Override + public ClusterGetSettingsRequestBuilder prepareGetSettings() { + return new ClusterGetSettingsRequestBuilder(this, ClusterGetSettingsAction.INSTANCE); + } + @Override public NodesReloadSecureSettingsRequestBuilder prepareReloadSecureSettings() { return new NodesReloadSecureSettingsRequestBuilder(this, NodesReloadSecureSettingsAction.INSTANCE); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java index 1a05b03436495..93cbc1f8210a6 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java @@ -92,10 +92,13 @@ protected Collection doCollect(final MonitoringDoc.Node node, final ClusterState clusterState) throws Exception { final Supplier clusterStatsSupplier = () -> client.admin().cluster().prepareClusterStats().get(getCollectionTimeout()); + final Supplier clusterGetSettingsSupplier = + () -> client.admin().cluster().prepareGetSettings().get(getCollectionTimeout()); final Supplier> usageSupplier = () -> new XPackUsageRequestBuilder(client).get().getUsages(); final ClusterStatsResponse clusterStats = clusterStatsSupplier.get(); + final ClusterGetSettingsResponse clusterSettings = clusterGetSettingsSupplier.get(); final String clusterName = clusterService.getClusterName().value(); final String clusterUuid = clusterUuid(clusterState); @@ -112,7 +115,8 @@ protected Collection doCollect(final MonitoringDoc.Node node, // Adds a cluster stats document return Collections.singleton( new ClusterStatsMonitoringDoc(clusterUuid, timestamp(), interval, node, clusterName, version, clusterStats.getStatus(), - license, apmIndicesExist, xpackUsage, clusterStats, clusterState, clusterNeedsTLSEnabled)); + license, apmIndicesExist, xpackUsage, clusterStats, clusterState, clusterSettings, + clusterNeedsTLSEnabled)); } boolean doAPMIndicesExist(final ClusterState clusterState) { From c5fdc9b861110fc35068ff9f019051268a600672 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 06:42:01 -0700 Subject: [PATCH 02/12] Adding cluster metadata to cluster stats monitoring doc --- .../settings/ClusterGetSettingsAction.java | 17 +++++ .../ClusterGetSettingsRequestBuilder.java | 66 +------------------ .../settings/ClusterGetSettingsResponse.java | 6 ++ .../client/ClusterAdminClient.java | 19 +++++- .../client/support/AbstractClient.java | 15 +++-- .../cluster/ClusterStatsCollector.java | 1 + .../cluster/ClusterStatsMonitoringDoc.java | 35 ++++++++++ 7 files changed, 87 insertions(+), 72 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java new file mode 100644 index 0000000000000..e4b56d650e3ca --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java @@ -0,0 +1,17 @@ +package org.elasticsearch.action.admin.cluster.settings; + +import org.elasticsearch.action.Action; + +public class ClusterGetSettingsAction extends Action { + public static final ClusterGetSettingsAction INSTANCE = new ClusterGetSettingsAction(); + public static final String NAME = "cluster:admin/settings/get"; + + private ClusterGetSettingsAction() { + super(NAME); + } + + @Override + public ClusterGetSettingsResponse newResponse() { + return new ClusterGetSettingsResponse(); + } +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java index b3d3b31581222..a0bb71ee5d6c1 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.admin.cluster.settings; -import org.elasticsearch.action.support.master.MasterNodeReadRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentType; @@ -34,68 +34,4 @@ public class ClusterGetSettingsRequestBuilder extends MasterNodeReadOperationReq public ClusterGetSettingsRequestBuilder(ElasticsearchClient client, ClusterGetSettingsAction action) { super(client, action, new ClusterGetSettingsRequest()); } - - /** - * Sets the transient settings to be updated. They will not survive a full cluster restart - */ - public ClusterGetSettingsRequestBuilder setTransientSettings(Settings settings) { - request.transientSettings(settings); - return this; - } - - /** - * Sets the transient settings to be updated. They will not survive a full cluster restart - */ - public ClusterGetSettingsRequestBuilder setTransientSettings(Settings.Builder settings) { - request.transientSettings(settings); - return this; - } - - /** - * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart - */ - public ClusterGetSettingsRequestBuilder setTransientSettings(String settings, XContentType xContentType) { - request.transientSettings(settings, xContentType); - return this; - } - - /** - * Sets the transient settings to be updated. They will not survive a full cluster restart - */ - public ClusterGetSettingsRequestBuilder setTransientSettings(Map settings) { - request.transientSettings(settings); - return this; - } - - /** - * Sets the persistent settings to be updated. They will get applied cross restarts - */ - public ClusterGetSettingsRequestBuilder setPersistentSettings(Settings settings) { - request.persistentSettings(settings); - return this; - } - - /** - * Sets the persistent settings to be updated. They will get applied cross restarts - */ - public ClusterGetSettingsRequestBuilder setPersistentSettings(Settings.Builder settings) { - request.persistentSettings(settings); - return this; - } - - /** - * Sets the source containing the persistent settings to be updated. They will get applied cross restarts - */ - public ClusterGetSettingsRequestBuilder setPersistentSettings(String settings, XContentType xContentType) { - request.persistentSettings(settings, xContentType); - return this; - } - - /** - * Sets the persistent settings to be updated. They will get applied cross restarts - */ - public ClusterGetSettingsRequestBuilder setPersistentSettings(Map settings) { - request.persistentSettings(settings); - return this; - } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java index 173a44b67cdfc..b6e206ceefee5 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java @@ -63,6 +63,12 @@ public class ClusterGetSettingsResponse extends ActionResponse implements ToXCon PARSER.declareObject(optionalConstructorArg(), (p, c) -> Settings.fromXContent(p), new ParseField(DEFAULTS_FIELD)); } + public ClusterGetSettingsResponse() { + this.persistentSettings = Settings.EMPTY; + this.transientSettings = Settings.EMPTY; + this.defaultSettings = Settings.EMPTY; + } + public ClusterGetSettingsResponse(Settings persistentSettings, Settings transientSettings, Settings defaultSettings) { if (persistentSettings != null) { this.persistentSettings = persistentSettings; diff --git a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 624c79996371a..320fbed21a436 100644 --- a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -62,9 +62,7 @@ import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.cluster.settings.*; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; @@ -181,6 +179,21 @@ public interface ClusterAdminClient extends ElasticsearchClient { */ ClusterUpdateSettingsRequestBuilder prepareUpdateSettings(); + /** + * Get settings from cluster + */ + ActionFuture getSettings(ClusterGetSettingsRequest request); + + /** + * Get settings from cluster + */ + void getSettings(ClusterGetSettingsRequest request, ActionListener listener); + + /** + * Get settings from cluster + */ + ClusterGetSettingsRequestBuilder prepareGetSettings(); + /** * Re initialize each cluster node and pass them the secret store password. */ diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index f14cf1e6103cd..69865cecd8de9 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -80,10 +80,7 @@ import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.cluster.settings.*; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; @@ -761,6 +758,16 @@ public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { return new ClusterUpdateSettingsRequestBuilder(this, ClusterUpdateSettingsAction.INSTANCE); } + @Override + public ActionFuture getSettings(final ClusterGetSettingsRequest request) { + return execute(ClusterGetSettingsAction.INSTANCE, request); + } + + @Override + public void getSettings(final ClusterGetSettingsRequest request, final ActionListener listener) { + execute(ClusterGetSettingsAction.INSTANCE, request, listener); + } + @Override public ClusterGetSettingsRequestBuilder prepareGetSettings() { return new ClusterGetSettingsRequestBuilder(this, ClusterGetSettingsAction.INSTANCE); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java index 93cbc1f8210a6..6d9c2b6be20e8 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.util.Supplier; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.Version; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java index 414945c2a151b..97f8b4686f02f 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.monitoring.collector.cluster; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; @@ -12,6 +13,8 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.MapBuilder; +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.License; @@ -45,6 +48,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { ClusterState.Metric.NODES)); public static final String TYPE = "cluster_stats"; + protected static final String SETTING_CLUSTER_METADATA = "cluster.metadata"; private final String clusterName; private final String version; @@ -53,6 +57,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { private final List usages; private final ClusterStatsResponse clusterStats; private final ClusterState clusterState; + private final ClusterGetSettingsResponse clusterSettings; private final ClusterHealthStatus status; private final boolean clusterNeedsTLSEnabled; @@ -68,6 +73,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { @Nullable final List usages, @Nullable final ClusterStatsResponse clusterStats, @Nullable final ClusterState clusterState, + @Nullable final ClusterGetSettingsResponse clusterSettings, final boolean clusterNeedsTLSEnabled) { super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null); @@ -79,6 +85,7 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { this.usages = usages; this.clusterStats = clusterStats; this.clusterState = clusterState; + this.clusterSettings = clusterSettings; this.clusterNeedsTLSEnabled = clusterNeedsTLSEnabled; } @@ -118,6 +125,25 @@ boolean getClusterNeedsTLSEnabled() { return clusterNeedsTLSEnabled; } + Settings getClusterMetadata() { + Settings persistentSettings = clusterSettings.getPersistentSettings(); + if (persistentSettings.hasValue(SETTING_CLUSTER_METADATA)) { + return persistentSettings.getAsSettings(SETTING_CLUSTER_METADATA); + } + + Settings transientSettings = clusterSettings.getTransientSettings(); + if (transientSettings.hasValue(SETTING_CLUSTER_METADATA)) { + return transientSettings.getAsSettings(SETTING_CLUSTER_METADATA); + } + + Settings defaultSettings = clusterSettings.getDefaultSettings(); + if (defaultSettings.hasValue(SETTING_CLUSTER_METADATA)) { + return defaultSettings.getAsSettings(SETTING_CLUSTER_METADATA); + } + + return null; + } + @Override protected void innerToXContent(XContentBuilder builder, Params params) throws IOException { builder.field("cluster_name", clusterName); @@ -156,6 +182,15 @@ protected void innerToXContent(XContentBuilder builder, Params params) throws IO builder.endObject(); } + Settings clusterMetadata = getClusterMetadata(); + if (clusterMetadata != null) { + builder.startObject("cluster_metadata"); + { + clusterMetadata.toXContent(builder, params); + } + builder.endObject(); + } + builder.startObject("stack_stats"); { // in the future, it may be useful to pass in an object that represents APM (and others), but for now this From 295185a2bec6cba718ca6825b6dace9bbce2c5a7 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 07:46:31 -0700 Subject: [PATCH 03/12] Fixing checkstyle errors --- .../settings/ClusterGetSettingsRequestBuilder.java | 7 ++----- .../org/elasticsearch/client/ClusterAdminClient.java | 7 ++++++- .../org/elasticsearch/client/support/AbstractClient.java | 9 ++++++++- .../collector/cluster/ClusterStatsMonitoringDoc.java | 1 - 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java index a0bb71ee5d6c1..3e5ee50c9be22 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java @@ -21,15 +21,12 @@ import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentType; - -import java.util.Map; /** * Builder for a cluster get settings request */ -public class ClusterGetSettingsRequestBuilder extends MasterNodeReadOperationRequestBuilder { +public class ClusterGetSettingsRequestBuilder extends + MasterNodeReadOperationRequestBuilder { public ClusterGetSettingsRequestBuilder(ElasticsearchClient client, ClusterGetSettingsAction action) { super(client, action, new ClusterGetSettingsRequest()); diff --git a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 320fbed21a436..5ad9a55659f1f 100644 --- a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -62,7 +62,12 @@ import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; -import org.elasticsearch.action.admin.cluster.settings.*; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequestBuilder; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 69865cecd8de9..adbe3b3a86457 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -80,7 +80,14 @@ import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; -import org.elasticsearch.action.admin.cluster.settings.*; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequestBuilder; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java index 97f8b4686f02f..238af40a2f69f 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java @@ -13,7 +13,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; From 74953bbec438a431e9f67986de7af8f278fc3adb Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 07:54:59 -0700 Subject: [PATCH 04/12] Adding missing license header --- .../settings/ClusterGetSettingsAction.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java index e4b56d650e3ca..f7e46ae27522b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java @@ -1,3 +1,22 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.elasticsearch.action.admin.cluster.settings; import org.elasticsearch.action.Action; From cb62a8a44835b118db658dc0a2aa4a7fcd5b4a55 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 08:41:16 -0700 Subject: [PATCH 05/12] Updating tests --- .../cluster/ClusterStatsMonitoringDocTests.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index 61224ac0fd735..3fd4c67ddfde3 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodeResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.indices.stats.CommonStats; @@ -75,6 +76,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase usages; private ClusterStatsResponse clusterStats; private ClusterState clusterState; + private ClusterGetSettingsResponse clusterSettings; private License license; private final boolean needToEnableTLS = randomBoolean(); private final boolean apmIndicesExist = randomBoolean(); @@ -89,6 +91,7 @@ public void setUp() throws Exception { usages = emptyList(); clusterStats = mock(ClusterStatsResponse.class); clusterState = mock(ClusterState.class); + clusterSettings = mock(ClusterGetSettingsResponse.class); license = License.builder() .uid(randomAlphaOfLength(5)) .type(randomFrom(License.OperationMode.values()).name()) @@ -115,7 +118,7 @@ protected ClusterStatsMonitoringDoc createMonitoringDoc(String cluster, long tim return new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, clusterName, version, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - needToEnableTLS); + clusterSettings, needToEnableTLS); } @Override @@ -138,21 +141,21 @@ public void testConstructorClusterNameMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, null, version, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - needToEnableTLS)); + clusterSettings, needToEnableTLS)); } public void testConstructorVersionMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, clusterName, null, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - needToEnableTLS)); + clusterSettings, needToEnableTLS)); } public void testConstructorClusterHealthStatusMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, clusterName, version, null, license, apmIndicesExist, usages, clusterStats, clusterState, - needToEnableTLS)); + clusterSettings, needToEnableTLS)); } public void testNodesHash() { @@ -322,6 +325,7 @@ public void testToXContent() throws IOException { usages, clusterStats, clusterState, + clusterSettings, needToEnableTLS); final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, false); From a11010b92e0cebc6f5cbb7aceac8074987ff96da Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 12:51:32 -0700 Subject: [PATCH 06/12] Getting cluster settings from cluster state --- .../settings/ClusterGetSettingsAction.java | 36 ------------------- .../ClusterGetSettingsRequestBuilder.java | 34 ------------------ .../settings/ClusterGetSettingsResponse.java | 6 ---- .../client/ClusterAdminClient.java | 18 ---------- .../client/support/AbstractClient.java | 19 ---------- .../cluster/ClusterStatsCollector.java | 6 +--- .../cluster/ClusterStatsMonitoringDoc.java | 31 ++++------------ .../ClusterStatsMonitoringDocTests.java | 11 +++--- 8 files changed, 11 insertions(+), 150 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java delete mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java deleted file mode 100644 index f7e46ae27522b..0000000000000 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.admin.cluster.settings; - -import org.elasticsearch.action.Action; - -public class ClusterGetSettingsAction extends Action { - public static final ClusterGetSettingsAction INSTANCE = new ClusterGetSettingsAction(); - public static final String NAME = "cluster:admin/settings/get"; - - private ClusterGetSettingsAction() { - super(NAME); - } - - @Override - public ClusterGetSettingsResponse newResponse() { - return new ClusterGetSettingsResponse(); - } -} diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java deleted file mode 100644 index 3e5ee50c9be22..0000000000000 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsRequestBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.admin.cluster.settings; - -import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; -import org.elasticsearch.client.ElasticsearchClient; - -/** - * Builder for a cluster get settings request - */ -public class ClusterGetSettingsRequestBuilder extends - MasterNodeReadOperationRequestBuilder { - - public ClusterGetSettingsRequestBuilder(ElasticsearchClient client, ClusterGetSettingsAction action) { - super(client, action, new ClusterGetSettingsRequest()); - } -} diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java index b6e206ceefee5..173a44b67cdfc 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsResponse.java @@ -63,12 +63,6 @@ public class ClusterGetSettingsResponse extends ActionResponse implements ToXCon PARSER.declareObject(optionalConstructorArg(), (p, c) -> Settings.fromXContent(p), new ParseField(DEFAULTS_FIELD)); } - public ClusterGetSettingsResponse() { - this.persistentSettings = Settings.EMPTY; - this.transientSettings = Settings.EMPTY; - this.defaultSettings = Settings.EMPTY; - } - public ClusterGetSettingsResponse(Settings persistentSettings, Settings transientSettings, Settings defaultSettings) { if (persistentSettings != null) { this.persistentSettings = persistentSettings; diff --git a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 5ad9a55659f1f..624c79996371a 100644 --- a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -65,9 +65,6 @@ import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequestBuilder; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; @@ -184,21 +181,6 @@ public interface ClusterAdminClient extends ElasticsearchClient { */ ClusterUpdateSettingsRequestBuilder prepareUpdateSettings(); - /** - * Get settings from cluster - */ - ActionFuture getSettings(ClusterGetSettingsRequest request); - - /** - * Get settings from cluster - */ - void getSettings(ClusterGetSettingsRequest request, ActionListener listener); - - /** - * Get settings from cluster - */ - ClusterGetSettingsRequestBuilder prepareGetSettings(); - /** * Re initialize each cluster node and pass them the secret store password. */ diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index adbe3b3a86457..553c92e6de86e 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -84,10 +84,6 @@ import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequestBuilder; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; @@ -765,21 +761,6 @@ public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { return new ClusterUpdateSettingsRequestBuilder(this, ClusterUpdateSettingsAction.INSTANCE); } - @Override - public ActionFuture getSettings(final ClusterGetSettingsRequest request) { - return execute(ClusterGetSettingsAction.INSTANCE, request); - } - - @Override - public void getSettings(final ClusterGetSettingsRequest request, final ActionListener listener) { - execute(ClusterGetSettingsAction.INSTANCE, request, listener); - } - - @Override - public ClusterGetSettingsRequestBuilder prepareGetSettings() { - return new ClusterGetSettingsRequestBuilder(this, ClusterGetSettingsAction.INSTANCE); - } - @Override public NodesReloadSecureSettingsRequestBuilder prepareReloadSecureSettings() { return new NodesReloadSecureSettingsRequestBuilder(this, NodesReloadSecureSettingsAction.INSTANCE); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java index 6d9c2b6be20e8..23fe4d465435e 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollector.java @@ -9,7 +9,6 @@ import org.apache.logging.log4j.util.Supplier; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.Version; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; @@ -93,13 +92,10 @@ protected Collection doCollect(final MonitoringDoc.Node node, final ClusterState clusterState) throws Exception { final Supplier clusterStatsSupplier = () -> client.admin().cluster().prepareClusterStats().get(getCollectionTimeout()); - final Supplier clusterGetSettingsSupplier = - () -> client.admin().cluster().prepareGetSettings().get(getCollectionTimeout()); final Supplier> usageSupplier = () -> new XPackUsageRequestBuilder(client).get().getUsages(); final ClusterStatsResponse clusterStats = clusterStatsSupplier.get(); - final ClusterGetSettingsResponse clusterSettings = clusterGetSettingsSupplier.get(); final String clusterName = clusterService.getClusterName().value(); final String clusterUuid = clusterUuid(clusterState); @@ -116,7 +112,7 @@ protected Collection doCollect(final MonitoringDoc.Node node, // Adds a cluster stats document return Collections.singleton( new ClusterStatsMonitoringDoc(clusterUuid, timestamp(), interval, node, clusterName, version, clusterStats.getStatus(), - license, apmIndicesExist, xpackUsage, clusterStats, clusterState, clusterSettings, + license, apmIndicesExist, xpackUsage, clusterStats, clusterState, clusterNeedsTLSEnabled)); } diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java index 238af40a2f69f..526d1124a4ef9 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.monitoring.collector.cluster; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; @@ -56,7 +55,6 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { private final List usages; private final ClusterStatsResponse clusterStats; private final ClusterState clusterState; - private final ClusterGetSettingsResponse clusterSettings; private final ClusterHealthStatus status; private final boolean clusterNeedsTLSEnabled; @@ -72,7 +70,6 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { @Nullable final List usages, @Nullable final ClusterStatsResponse clusterStats, @Nullable final ClusterState clusterState, - @Nullable final ClusterGetSettingsResponse clusterSettings, final boolean clusterNeedsTLSEnabled) { super(cluster, timestamp, intervalMillis, node, MonitoredSystem.ES, TYPE, null); @@ -84,7 +81,6 @@ public class ClusterStatsMonitoringDoc extends MonitoringDoc { this.usages = usages; this.clusterStats = clusterStats; this.clusterState = clusterState; - this.clusterSettings = clusterSettings; this.clusterNeedsTLSEnabled = clusterNeedsTLSEnabled; } @@ -124,23 +120,8 @@ boolean getClusterNeedsTLSEnabled() { return clusterNeedsTLSEnabled; } - Settings getClusterMetadata() { - Settings persistentSettings = clusterSettings.getPersistentSettings(); - if (persistentSettings.hasValue(SETTING_CLUSTER_METADATA)) { - return persistentSettings.getAsSettings(SETTING_CLUSTER_METADATA); - } - - Settings transientSettings = clusterSettings.getTransientSettings(); - if (transientSettings.hasValue(SETTING_CLUSTER_METADATA)) { - return transientSettings.getAsSettings(SETTING_CLUSTER_METADATA); - } - - Settings defaultSettings = clusterSettings.getDefaultSettings(); - if (defaultSettings.hasValue(SETTING_CLUSTER_METADATA)) { - return defaultSettings.getAsSettings(SETTING_CLUSTER_METADATA); - } - - return null; + Settings getClusterSettings() { + return this.clusterState.getMetaData().settings(); } @Override @@ -181,11 +162,11 @@ protected void innerToXContent(XContentBuilder builder, Params params) throws IO builder.endObject(); } - Settings clusterMetadata = getClusterMetadata(); - if (clusterMetadata != null) { - builder.startObject("cluster_metadata"); + Settings clusterSettings = getClusterSettings(); + if (clusterSettings != null) { + builder.startObject("cluster_settings"); { - clusterMetadata.toXContent(builder, params); + clusterSettings.toXContent(builder, params); } builder.endObject(); } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index 3fd4c67ddfde3..cf0255073d33c 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodeResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.indices.stats.CommonStats; @@ -76,7 +75,6 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase usages; private ClusterStatsResponse clusterStats; private ClusterState clusterState; - private ClusterGetSettingsResponse clusterSettings; private License license; private final boolean needToEnableTLS = randomBoolean(); private final boolean apmIndicesExist = randomBoolean(); @@ -91,7 +89,6 @@ public void setUp() throws Exception { usages = emptyList(); clusterStats = mock(ClusterStatsResponse.class); clusterState = mock(ClusterState.class); - clusterSettings = mock(ClusterGetSettingsResponse.class); license = License.builder() .uid(randomAlphaOfLength(5)) .type(randomFrom(License.OperationMode.values()).name()) @@ -118,7 +115,7 @@ protected ClusterStatsMonitoringDoc createMonitoringDoc(String cluster, long tim return new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, clusterName, version, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - clusterSettings, needToEnableTLS); + needToEnableTLS); } @Override @@ -141,21 +138,21 @@ public void testConstructorClusterNameMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, null, version, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - clusterSettings, needToEnableTLS)); + needToEnableTLS)); } public void testConstructorVersionMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, clusterName, null, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - clusterSettings, needToEnableTLS)); + needToEnableTLS)); } public void testConstructorClusterHealthStatusMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, clusterName, version, null, license, apmIndicesExist, usages, clusterStats, clusterState, - clusterSettings, needToEnableTLS)); + needToEnableTLS)); } public void testNodesHash() { From 6b7d1c3236f46f3d7c47ea84c85844341ae98d28 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 12:54:26 -0700 Subject: [PATCH 07/12] Removing more unnecessary changes --- .../collector/cluster/ClusterStatsMonitoringDocTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index cf0255073d33c..61224ac0fd735 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -138,7 +138,7 @@ public void testConstructorClusterNameMustNotBeNull() { expectThrows(NullPointerException.class, () -> new ClusterStatsMonitoringDoc(cluster, timestamp, interval, node, null, version, clusterStatus, license, apmIndicesExist, usages, clusterStats, clusterState, - needToEnableTLS)); + needToEnableTLS)); } public void testConstructorVersionMustNotBeNull() { @@ -322,7 +322,6 @@ public void testToXContent() throws IOException { usages, clusterStats, clusterState, - clusterSettings, needToEnableTLS); final BytesReference xContent = XContentHelper.toXContent(doc, XContentType.JSON, false); From f9eb8c6330e7aaaed4013465c6780a0b188fe362 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 19 Sep 2018 13:32:55 -0700 Subject: [PATCH 08/12] Adding cluster metadata settings to cluster_stats docs --- .../cluster/ClusterStatsMonitoringDoc.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java index 526d1124a4ef9..d0732156e868e 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java @@ -120,8 +120,8 @@ boolean getClusterNeedsTLSEnabled() { return clusterNeedsTLSEnabled; } - Settings getClusterSettings() { - return this.clusterState.getMetaData().settings(); + Settings getClusterMetaDataSettings() { + return this.clusterState.getMetaData().settings().getAsSettings(SETTING_CLUSTER_METADATA); } @Override @@ -162,11 +162,21 @@ protected void innerToXContent(XContentBuilder builder, Params params) throws IO builder.endObject(); } - Settings clusterSettings = getClusterSettings(); - if (clusterSettings != null) { + Settings clusterMetaDataSettings = getClusterMetaDataSettings(); + if (clusterMetaDataSettings != null) { builder.startObject("cluster_settings"); { - clusterSettings.toXContent(builder, params); + if (clusterMetaDataSettings.size() > 0) { + builder.startObject("cluster"); + { + builder.startObject("metadata"); + { + clusterMetaDataSettings.toXContent(builder, params); + } + builder.endObject(); + } + builder.endObject(); + } } builder.endObject(); } From aaad1cfaf503a78e38b39ee136f1fd8a881bf5f9 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 20 Sep 2018 12:56:13 -0700 Subject: [PATCH 09/12] Updating test to include cluster metadata --- .../cluster/ClusterStatsMonitoringDocTests.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index 61224ac0fd735..cba05047d588b 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -203,7 +203,10 @@ public void testToXContent() throws IOException { Version.V_6_0_0_beta1); final ClusterState clusterState = ClusterState.builder(clusterName) - .metaData(MetaData.builder().clusterUUID(clusterUuid).build()) + .metaData(MetaData.builder() + .clusterUUID(clusterUuid) + .transientSettings(Settings.builder().put("cluster.metadata.display_name", "my_prod_cluster").build()) + .build()) .stateUUID("_state_uuid") .version(12L) .nodes(DiscoveryNodes.builder() @@ -532,6 +535,12 @@ public void testToXContent() throws IOException { + "\"collection_enabled\":false" + "}" + "}" + + "}," + + "\"cluster_settings\":{" + + "\"cluster\":{" + + "\"metadata\":{" + + "\"display_name\":\"my_prod_cluster\"" + + "}" + "}" + "}" , xContent.utf8ToString()); } From f5d204ef6d7f38c306620a5176951769b3ac6066 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 20 Sep 2018 13:17:21 -0700 Subject: [PATCH 10/12] Fixing checkstyle --- .../collector/cluster/ClusterStatsMonitoringDocTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index cba05047d588b..d4d18856f3aa7 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -205,7 +205,9 @@ public void testToXContent() throws IOException { final ClusterState clusterState = ClusterState.builder(clusterName) .metaData(MetaData.builder() .clusterUUID(clusterUuid) - .transientSettings(Settings.builder().put("cluster.metadata.display_name", "my_prod_cluster").build()) + .transientSettings(Settings.builder() + .put("cluster.metadata.display_name", "my_prod_cluster") + .build()) .build()) .stateUUID("_state_uuid") .version(12L) From c50df4c08e7d9e0bb1bbdad36ea3d357f3c1a7a5 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 24 Sep 2018 15:54:34 -0700 Subject: [PATCH 11/12] Guarding against NPE --- .../collector/cluster/ClusterStatsMonitoringDoc.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java index d0732156e868e..75c0ba6b81c7d 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDoc.java @@ -8,6 +8,7 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Nullable; @@ -121,7 +122,11 @@ boolean getClusterNeedsTLSEnabled() { } Settings getClusterMetaDataSettings() { - return this.clusterState.getMetaData().settings().getAsSettings(SETTING_CLUSTER_METADATA); + MetaData metaData = this.clusterState.getMetaData(); + if (metaData == null) { + return Settings.EMPTY; + } + return metaData.settings().getAsSettings(SETTING_CLUSTER_METADATA); } @Override From 287ab7e2540149896d510191a0721e593f212896 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 24 Sep 2018 15:54:52 -0700 Subject: [PATCH 12/12] Updating test fixture --- .../cluster/ClusterStatsMonitoringDocTests.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index d4d18856f3aa7..bc531bb2d6b44 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -526,6 +526,13 @@ public void testToXContent() throws IOException { + "}" + "}" + "}," + + "\"cluster_settings\":{" + + "\"cluster\":{" + + "\"metadata\":{" + + "\"display_name\":\"my_prod_cluster\"" + + "}" + + "}" + + "}," + "\"stack_stats\":{" + "\"apm\":{" + "\"found\":" + apmIndicesExist @@ -537,12 +544,6 @@ public void testToXContent() throws IOException { + "\"collection_enabled\":false" + "}" + "}" - + "}," - + "\"cluster_settings\":{" - + "\"cluster\":{" - + "\"metadata\":{" - + "\"display_name\":\"my_prod_cluster\"" - + "}" + "}" + "}" , xContent.utf8ToString()); }