From 75d179c7b26f2b7b4b209684db99e2c1dc4f375b Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Tue, 3 May 2022 14:57:35 -0400 Subject: [PATCH 01/16] Implement faster GET _cluster/settings API The existing API to retrieve the cluster settings relies on pulling in the full cluster state, which can be very expensive. This change adds a dedicated cluster settings API, avoiding serializing the full cluster state. Closes #82342 --- .../elasticsearch/action/ActionModule.java | 5 +- .../settings/ClusterGetSettingsAction.java | 92 +++++++++++++++++++ .../TransportClusterGetSettingsAction.java | 64 +++++++++++++ .../cluster/RestClusterGetSettingsAction.java | 26 +++++- 4 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java create mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 5329c56ba19d3..5383f9451ccd0 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -58,7 +58,9 @@ import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryAction; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteAction; import org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; +import org.elasticsearch.action.admin.cluster.settings.TransportClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; import org.elasticsearch.action.admin.cluster.shards.TransportClusterSearchShardsAction; @@ -546,6 +548,7 @@ public void reg actions.register(ClusterStateAction.INSTANCE, TransportClusterStateAction.class); actions.register(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class); actions.register(ClusterUpdateSettingsAction.INSTANCE, TransportClusterUpdateSettingsAction.class); + actions.register(ClusterGetSettingsAction.INSTANCE, TransportClusterGetSettingsAction.class); actions.register(ClusterRerouteAction.INSTANCE, TransportClusterRerouteAction.class); actions.register(ClusterSearchShardsAction.INSTANCE, TransportClusterSearchShardsAction.class); actions.register(PendingClusterTasksAction.INSTANCE, TransportPendingClusterTasksAction.class); @@ -707,7 +710,7 @@ public void initRestHandlers(Supplier nodesInCluster) { registerHandler.accept(new RestClusterStateAction(settingsFilter, threadPool)); registerHandler.accept(new RestClusterHealthAction()); registerHandler.accept(new RestClusterUpdateSettingsAction()); - registerHandler.accept(new RestClusterGetSettingsAction(settings, clusterSettings, settingsFilter)); + registerHandler.accept(new RestClusterGetSettingsAction(settings, clusterSettings, settingsFilter, nodesInCluster)); registerHandler.accept(new RestClusterRerouteAction(settingsFilter)); registerHandler.accept(new RestClusterSearchShardsAction()); registerHandler.accept(new RestPendingClusterTasksAction()); 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..50565f28fe758 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java @@ -0,0 +1,92 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.action.admin.cluster.settings; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.support.master.MasterNodeReadRequest; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xcontent.ToXContentObject; +import org.elasticsearch.xcontent.XContentBuilder; + +import java.io.IOException; +import java.util.Objects; + +import static org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse.PERSISTENT_FIELD; +import static org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse.TRANSIENT_FIELD; + +public class ClusterGetSettingsAction extends ActionType { + + public static final ClusterGetSettingsAction INSTANCE = new ClusterGetSettingsAction(); + public static final String NAME = "cluster:admin/settings/get"; + + public ClusterGetSettingsAction() { + super(NAME, Response::new); + } + + /** + * Request to retrieve the cluster settings + */ + public static class Request extends MasterNodeReadRequest { + public Request() {} + + public Request(StreamInput in) throws IOException { + super(in); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + } + + /** + * Response for cluster settings + */ + public static class Response extends ActionResponse implements ToXContentObject { + private final Settings persistentSettings; + private final Settings transientSettings; + + public Response(StreamInput in) throws IOException { + super(in); + persistentSettings = Settings.readSettingsFromStream(in); + transientSettings = Settings.readSettingsFromStream(in); + } + + public Response(Settings persistentSettings, Settings transientSettings) { + this.persistentSettings = Objects.requireNonNullElse(persistentSettings, Settings.EMPTY); + this.transientSettings = Objects.requireNonNullElse(transientSettings, Settings.EMPTY); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + + builder.startObject(PERSISTENT_FIELD); + persistentSettings.toXContent(builder, params); + builder.endObject(); + + builder.startObject(TRANSIENT_FIELD); + transientSettings.toXContent(builder, params); + builder.endObject(); + + builder.endObject(); + return builder; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + Settings.writeSettingsToStream(persistentSettings, out); + Settings.writeSettingsToStream(transientSettings, out); + } + } +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java new file mode 100644 index 0000000000000..f912453e811db --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java @@ -0,0 +1,64 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.action.admin.cluster.settings; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +public class TransportClusterGetSettingsAction extends TransportMasterNodeReadAction< + ClusterGetSettingsAction.Request, + ClusterGetSettingsAction.Response> { + + @Inject + public TransportClusterGetSettingsAction( + TransportService transportService, + ClusterService clusterService, + ThreadPool threadPool, + ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver + ) { + super( + ClusterGetSettingsAction.NAME, + transportService, + clusterService, + threadPool, + actionFilters, + ClusterGetSettingsAction.Request::new, + indexNameExpressionResolver, + ClusterGetSettingsAction.Response::new, + ThreadPool.Names.SAME + ); + } + + @Override + protected void masterOperation( + Task task, + ClusterGetSettingsAction.Request request, + ClusterState state, + ActionListener listener + ) throws Exception { + Metadata metadata = state.metadata(); + listener.onResponse(new ClusterGetSettingsAction.Response(metadata.persistentSettings(), metadata.transientSettings())); + } + + @Override + protected ClusterBlockException checkBlock(ClusterGetSettingsAction.Request request, ClusterState state) { + return null; + } +} diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index f71ba965e60be..d578233d1f996 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -8,11 +8,14 @@ package org.elasticsearch.rest.action.admin.cluster; +import org.elasticsearch.Version; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.client.internal.Requests; import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; @@ -23,6 +26,7 @@ import java.io.IOException; import java.util.List; import java.util.Set; +import java.util.function.Supplier; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -31,11 +35,18 @@ public class RestClusterGetSettingsAction extends BaseRestHandler { private final Settings settings; private final ClusterSettings clusterSettings; private final SettingsFilter settingsFilter; + private final Supplier nodesInCluster; - public RestClusterGetSettingsAction(Settings settings, ClusterSettings clusterSettings, SettingsFilter settingsFilter) { + public RestClusterGetSettingsAction( + Settings settings, + ClusterSettings clusterSettings, + SettingsFilter settingsFilter, + Supplier nodesInCluster + ) { this.settings = settings; this.clusterSettings = clusterSettings; this.settingsFilter = settingsFilter; + this.nodesInCluster = nodesInCluster; } @Override @@ -50,6 +61,19 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if (nodesInCluster.get().getMinNodeVersion().onOrAfter(Version.V_8_3_0) == false) { + return prepareLegacyRequest(request, client); + } + + ClusterGetSettingsAction.Request clusterSettingsRequest = new ClusterGetSettingsAction.Request(); + + clusterSettingsRequest.local(request.paramAsBoolean("local", clusterSettingsRequest.local())); + clusterSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterSettingsRequest.masterNodeTimeout())); + + return channel -> client.execute(ClusterGetSettingsAction.INSTANCE, clusterSettingsRequest, new RestToXContentListener<>(channel)); + } + + private RestChannelConsumer prepareLegacyRequest(final RestRequest request, final NodeClient client) { ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().routingTable(false).nodes(false); final boolean renderDefaults = request.paramAsBoolean("include_defaults", false); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); From 8a888271323ce7af4c4981bf296f940a321d551a Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Tue, 3 May 2022 15:29:25 -0400 Subject: [PATCH 02/16] Reuse filtering logic --- .../settings/ClusterGetSettingsAction.java | 12 +++++ .../cluster/RestClusterGetSettingsAction.java | 51 ++++++++++++++----- .../RestClusterGetSettingsActionTests.java | 5 +- 3 files changed, 53 insertions(+), 15 deletions(-) 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 50565f28fe758..cb3ece851253e 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 @@ -88,5 +88,17 @@ public void writeTo(StreamOutput out) throws IOException { Settings.writeSettingsToStream(persistentSettings, out); Settings.writeSettingsToStream(transientSettings, out); } + + public Settings persistentSettings() { + return persistentSettings; + } + + public Settings transientSettings() { + return transientSettings; + } + + public Settings settings() { + return Settings.builder().put(persistentSettings).put(transientSettings).build(); + } } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index d578233d1f996..8fa16b4fa7b35 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -61,8 +61,10 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + final boolean renderDefaults = request.paramAsBoolean("include_defaults", false); + if (nodesInCluster.get().getMinNodeVersion().onOrAfter(Version.V_8_3_0) == false) { - return prepareLegacyRequest(request, client); + return prepareLegacyRequest(request, client, renderDefaults); } ClusterGetSettingsAction.Request clusterSettingsRequest = new ClusterGetSettingsAction.Request(); @@ -70,22 +72,41 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC clusterSettingsRequest.local(request.paramAsBoolean("local", clusterSettingsRequest.local())); clusterSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterSettingsRequest.masterNodeTimeout())); - return channel -> client.execute(ClusterGetSettingsAction.INSTANCE, clusterSettingsRequest, new RestToXContentListener<>(channel)); + return channel -> client.execute( + ClusterGetSettingsAction.INSTANCE, + clusterSettingsRequest, + new RestToXContentListener(channel).map( + response -> response( + response.persistentSettings(), + response.transientSettings(), + response.settings(), + renderDefaults, + settingsFilter, + clusterSettings, + settings + ) + ) + ); } - private RestChannelConsumer prepareLegacyRequest(final RestRequest request, final NodeClient client) { + private RestChannelConsumer prepareLegacyRequest(final RestRequest request, final NodeClient client, final boolean renderDefaults) { ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().routingTable(false).nodes(false); - final boolean renderDefaults = request.paramAsBoolean("include_defaults", false); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); return channel -> client.admin() .cluster() - .state( - clusterStateRequest, - new RestToXContentListener(channel).map( - response -> response(response.getState(), renderDefaults, settingsFilter, clusterSettings, settings) - ) - ); + .state(clusterStateRequest, new RestToXContentListener(channel).map(response -> { + ClusterState state = response.getState(); + return response( + state.metadata().persistentSettings(), + state.metadata().transientSettings(), + state.metadata().settings(), + renderDefaults, + settingsFilter, + clusterSettings, + settings + ); + })); } @Override @@ -99,16 +120,18 @@ public boolean canTripCircuitBreaker() { } static RestClusterGetSettingsResponse response( - final ClusterState state, + final Settings persistentSettings, + final Settings transientSettings, + final Settings allSettings, final boolean renderDefaults, final SettingsFilter settingsFilter, final ClusterSettings clusterSettings, final Settings settings ) { return new RestClusterGetSettingsResponse( - settingsFilter.filter(state.metadata().persistentSettings()), - settingsFilter.filter(state.metadata().transientSettings()), - renderDefaults ? settingsFilter.filter(clusterSettings.diff(state.metadata().settings(), settings)) : Settings.EMPTY + settingsFilter.filter(persistentSettings), + settingsFilter.filter(transientSettings), + renderDefaults ? settingsFilter.filter(clusterSettings.diff(allSettings, settings)) : Settings.EMPTY ); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java index c5d17f22f860f..514cdf1db0f98 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java @@ -52,8 +52,11 @@ private void runTestFilterSettingsTest( ) ).collect(Collectors.toSet()); final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet); + final ClusterState clusterState = builder.build(); final RestClusterGetSettingsResponse response = RestClusterGetSettingsAction.response( - builder.build(), + clusterState.metadata().persistentSettings(), + clusterState.metadata().transientSettings(), + clusterState.metadata().settings(), randomBoolean(), filter, clusterSettings, From 25f0240da7c23110a9832bfcde1f8a4ab17d3c8a Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Tue, 3 May 2022 15:38:40 -0400 Subject: [PATCH 03/16] Update docs/changelog/86405.yaml --- docs/changelog/86405.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/86405.yaml diff --git a/docs/changelog/86405.yaml b/docs/changelog/86405.yaml new file mode 100644 index 0000000000000..37953eeb4e535 --- /dev/null +++ b/docs/changelog/86405.yaml @@ -0,0 +1,6 @@ +pr: 86405 +summary: Faster GET _cluster/settings API +area: Infra/Core +type: enhancement +issues: + - 82342 From 022864bf759759c945b07ec80a3fd3cb27fe3719 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Tue, 3 May 2022 19:07:22 -0400 Subject: [PATCH 04/16] Fix privileges --- .../settings/ClusterGetSettingsAction.java | 12 ++++++++ .../client/internal/ClusterAdminClient.java | 23 +++++++++++++++ .../internal/support/AbstractClient.java | 16 ++++++++++ .../cluster/RestClusterGetSettingsAction.java | 29 ++++++++++--------- .../privilege/ClusterPrivilegeResolver.java | 4 ++- .../authz/privilege/SystemPrivilege.java | 4 ++- 6 files changed, 72 insertions(+), 16 deletions(-) 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 cb3ece851253e..ddea899e06acd 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 @@ -11,7 +11,9 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.action.support.master.MasterNodeReadRequest; +import org.elasticsearch.client.internal.ElasticsearchClient; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; @@ -49,6 +51,16 @@ public ActionRequestValidationException validate() { } } + /** + * Cluster get settings request builder + */ + public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder { + + public RequestBuilder(ElasticsearchClient client, ClusterGetSettingsAction action) { + super(client, action, new Request()); + } + } + /** * Response for cluster settings */ diff --git a/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java index 02c8200a751c9..566fd2566f737 100644 --- a/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java @@ -54,6 +54,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.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; @@ -756,4 +757,26 @@ public interface ClusterAdminClient extends ElasticsearchClient { * Delete specified dangling indices. */ ActionFuture deleteDanglingIndex(DeleteDanglingIndexRequest request); + + /** + * The cluster settings. + * + * @param request The cluster settings request + * @return The result future + */ + ActionFuture clusterSettings(ClusterGetSettingsAction.Request request); + + /** + * The health of the cluster. + * + * @param request The cluster state request + * @param listener A listener to be notified with a result + */ + void clusterSettings(ClusterGetSettingsAction.Request request, ActionListener listener); + + /** + * The health of the cluster. + */ + ClusterGetSettingsAction.RequestBuilder prepareClusterSettings(); + } diff --git a/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java index 07cd9a3f3044a..eb3a0b52680b3 100644 --- a/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java @@ -75,6 +75,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.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; @@ -1194,6 +1195,21 @@ public ActionFuture deleteDanglingIndex(DeleteDanglingInde return execute(DeleteDanglingIndexAction.INSTANCE, request); } + @Override + public ActionFuture clusterSettings(ClusterGetSettingsAction.Request request) { + return execute(ClusterGetSettingsAction.INSTANCE, request); + } + + @Override + public void clusterSettings(ClusterGetSettingsAction.Request request, ActionListener listener) { + execute(ClusterGetSettingsAction.INSTANCE, request, listener); + } + + @Override + public ClusterGetSettingsAction.RequestBuilder prepareClusterSettings() { + return new ClusterGetSettingsAction.RequestBuilder(this, ClusterGetSettingsAction.INSTANCE); + } + @Override public void deleteDanglingIndex(DeleteDanglingIndexRequest request, ActionListener listener) { execute(DeleteDanglingIndexAction.INSTANCE, request, listener); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index 8fa16b4fa7b35..a6f2cbdf7cd91 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -72,21 +72,22 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC clusterSettingsRequest.local(request.paramAsBoolean("local", clusterSettingsRequest.local())); clusterSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterSettingsRequest.masterNodeTimeout())); - return channel -> client.execute( - ClusterGetSettingsAction.INSTANCE, - clusterSettingsRequest, - new RestToXContentListener(channel).map( - response -> response( - response.persistentSettings(), - response.transientSettings(), - response.settings(), - renderDefaults, - settingsFilter, - clusterSettings, - settings + return channel -> client.admin() + .cluster() + .clusterSettings( + clusterSettingsRequest, + new RestToXContentListener(channel).map( + response -> response( + response.persistentSettings(), + response.transientSettings(), + response.settings(), + renderDefaults, + settingsFilter, + clusterSettings, + settings + ) ) - ) - ); + ); } private RestChannelConsumer prepareLegacyRequest(final RestRequest request, final NodeClient client, final boolean renderDefaults) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java index 7a66e6c1d476d..5644c6ec43e62 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksAction; import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction; import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction; @@ -71,7 +72,8 @@ public class ClusterPrivilegeResolver { "cluster:monitor/*", GetIndexTemplatesAction.NAME, GetComponentTemplateAction.NAME, - GetComposableIndexTemplateAction.NAME + GetComposableIndexTemplateAction.NAME, + ClusterGetSettingsAction.NAME ); private static final Set MONITOR_ML_PATTERN = Set.of("cluster:monitor/xpack/ml/*"); private static final Set MONITOR_TEXT_STRUCTURE_PATTERN = Set.of("cluster:monitor/text_structure/*"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java index acc387d42bf97..1f97f7d53a721 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java @@ -6,6 +6,7 @@ */ package org.elasticsearch.xpack.core.security.authz.privilege; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.index.seqno.RetentionLeaseActions; import org.elasticsearch.index.seqno.RetentionLeaseBackgroundSyncAction; import org.elasticsearch.index.seqno.RetentionLeaseSyncAction; @@ -40,7 +41,8 @@ public final class SystemPrivilege extends Privilege { "indices:data/write/*", // needed for SystemIndexMigrator "indices:data/read/*", // needed for SystemIndexMigrator "indices:admin/refresh", // needed for SystemIndexMigrator - "indices:admin/aliases" // needed for SystemIndexMigrator + "indices:admin/aliases", // needed for SystemIndexMigrator + ClusterGetSettingsAction.NAME // needed for the faster cluster get settings ); private static final Predicate PREDICATE = (action) -> { From 68394fd0aa2615694b397af5530c19eccdd8e1e4 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Tue, 3 May 2022 20:29:04 -0400 Subject: [PATCH 05/16] More security fixes --- .../xpack/core/security/authz/privilege/SystemPrivilege.java | 4 +--- .../org/elasticsearch/xpack/security/operator/Constants.java | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java index 1f97f7d53a721..acc387d42bf97 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/SystemPrivilege.java @@ -6,7 +6,6 @@ */ package org.elasticsearch.xpack.core.security.authz.privilege; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.index.seqno.RetentionLeaseActions; import org.elasticsearch.index.seqno.RetentionLeaseBackgroundSyncAction; import org.elasticsearch.index.seqno.RetentionLeaseSyncAction; @@ -41,8 +40,7 @@ public final class SystemPrivilege extends Privilege { "indices:data/write/*", // needed for SystemIndexMigrator "indices:data/read/*", // needed for SystemIndexMigrator "indices:admin/refresh", // needed for SystemIndexMigrator - "indices:admin/aliases", // needed for SystemIndexMigrator - ClusterGetSettingsAction.NAME // needed for the faster cluster get settings + "indices:admin/aliases" // needed for SystemIndexMigrator ); private static final Predicate PREDICATE = (action) -> { diff --git a/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java b/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java index 0914484b12264..ef3233f0794e5 100644 --- a/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java +++ b/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java @@ -65,6 +65,7 @@ public class Constants { "cluster:admin/script_language/get", "cluster:admin/scripts/painless/context", "cluster:admin/scripts/painless/execute", + "cluster:admin/settings/get", "cluster:admin/settings/update", "cluster:admin/slm/delete", "cluster:admin/slm/execute", From 7d918581b608191b8286723afcdd9ebb7173b3ae Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Wed, 4 May 2022 10:33:04 -0400 Subject: [PATCH 06/16] Update server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java disable circuit breakers Co-authored-by: David Turner --- .../cluster/settings/TransportClusterGetSettingsAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java index f912453e811db..9098cd6407f4b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java @@ -35,6 +35,7 @@ public TransportClusterGetSettingsAction( ) { super( ClusterGetSettingsAction.NAME, + false, transportService, clusterService, threadPool, From 5fce1b31e65254acdadf6eba1708afb352c87e01 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Wed, 4 May 2022 10:35:32 -0400 Subject: [PATCH 07/16] Update server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java Change onOrAfter to before. Co-authored-by: David Turner --- .../rest/action/admin/cluster/RestClusterGetSettingsAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index a6f2cbdf7cd91..99a7e87321dcb 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -63,7 +63,7 @@ public String getName() { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final boolean renderDefaults = request.paramAsBoolean("include_defaults", false); - if (nodesInCluster.get().getMinNodeVersion().onOrAfter(Version.V_8_3_0) == false) { + if (nodesInCluster.get().getMinNodeVersion().before(Version.V_8_3_0)) { return prepareLegacyRequest(request, client, renderDefaults); } From 49f2703c3c4f5a8687c6fc960d678540ae096fff Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Wed, 4 May 2022 10:39:01 -0400 Subject: [PATCH 08/16] Apply review suggestions --- .../settings/ClusterGetSettingsAction.java | 55 ++++++------------- .../client/internal/ClusterAdminClient.java | 22 -------- .../internal/support/AbstractClient.java | 16 ------ .../cluster/RestClusterGetSettingsAction.java | 29 +++++----- .../privilege/ClusterPrivilegeResolver.java | 4 +- .../xpack/security/operator/Constants.java | 2 +- 6 files changed, 34 insertions(+), 94 deletions(-) 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 ddea899e06acd..72990fba1c421 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 @@ -8,28 +8,22 @@ package org.elasticsearch.action.admin.cluster.settings; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; -import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.action.support.master.MasterNodeReadRequest; -import org.elasticsearch.client.internal.ElasticsearchClient; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; import java.util.Objects; -import static org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse.PERSISTENT_FIELD; -import static org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse.TRANSIENT_FIELD; - public class ClusterGetSettingsAction extends ActionType { public static final ClusterGetSettingsAction INSTANCE = new ClusterGetSettingsAction(); - public static final String NAME = "cluster:admin/settings/get"; + public static final String NAME = "cluster:monitor/settings"; public ClusterGetSettingsAction() { super(NAME, Response::new); @@ -43,62 +37,49 @@ public Request() {} public Request(StreamInput in) throws IOException { super(in); + assert in.getVersion().onOrAfter(Version.V_8_3_0); } @Override - public ActionRequestValidationException validate() { - return null; + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + assert out.getVersion().onOrAfter(Version.V_8_3_0); } - } - /** - * Cluster get settings request builder - */ - public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder { - - public RequestBuilder(ElasticsearchClient client, ClusterGetSettingsAction action) { - super(client, action, new Request()); + @Override + public ActionRequestValidationException validate() { + return null; } } /** * Response for cluster settings */ - public static class Response extends ActionResponse implements ToXContentObject { + public static class Response extends ActionResponse { private final Settings persistentSettings; private final Settings transientSettings; + private final Settings settings; public Response(StreamInput in) throws IOException { super(in); + assert in.getVersion().onOrAfter(Version.V_8_3_0); persistentSettings = Settings.readSettingsFromStream(in); transientSettings = Settings.readSettingsFromStream(in); + settings = Settings.readSettingsFromStream(in); } - public Response(Settings persistentSettings, Settings transientSettings) { + public Response(Settings persistentSettings, Settings transientSettings, Settings settings) { this.persistentSettings = Objects.requireNonNullElse(persistentSettings, Settings.EMPTY); this.transientSettings = Objects.requireNonNullElse(transientSettings, Settings.EMPTY); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - - builder.startObject(PERSISTENT_FIELD); - persistentSettings.toXContent(builder, params); - builder.endObject(); - - builder.startObject(TRANSIENT_FIELD); - transientSettings.toXContent(builder, params); - builder.endObject(); - - builder.endObject(); - return builder; + this.settings = Objects.requireNonNullElse(settings, Settings.EMPTY); } @Override public void writeTo(StreamOutput out) throws IOException { + assert out.getVersion().onOrAfter(Version.V_8_3_0); Settings.writeSettingsToStream(persistentSettings, out); Settings.writeSettingsToStream(transientSettings, out); + Settings.writeSettingsToStream(settings, out); } public Settings persistentSettings() { @@ -110,7 +91,7 @@ public Settings transientSettings() { } public Settings settings() { - return Settings.builder().put(persistentSettings).put(transientSettings).build(); + return settings; } } } diff --git a/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java index 566fd2566f737..a30efafcc93d9 100644 --- a/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java @@ -54,7 +54,6 @@ 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.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; @@ -758,25 +757,4 @@ public interface ClusterAdminClient extends ElasticsearchClient { */ ActionFuture deleteDanglingIndex(DeleteDanglingIndexRequest request); - /** - * The cluster settings. - * - * @param request The cluster settings request - * @return The result future - */ - ActionFuture clusterSettings(ClusterGetSettingsAction.Request request); - - /** - * The health of the cluster. - * - * @param request The cluster state request - * @param listener A listener to be notified with a result - */ - void clusterSettings(ClusterGetSettingsAction.Request request, ActionListener listener); - - /** - * The health of the cluster. - */ - ClusterGetSettingsAction.RequestBuilder prepareClusterSettings(); - } diff --git a/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java index eb3a0b52680b3..07cd9a3f3044a 100644 --- a/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/internal/support/AbstractClient.java @@ -75,7 +75,6 @@ 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.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; @@ -1195,21 +1194,6 @@ public ActionFuture deleteDanglingIndex(DeleteDanglingInde return execute(DeleteDanglingIndexAction.INSTANCE, request); } - @Override - public ActionFuture clusterSettings(ClusterGetSettingsAction.Request request) { - return execute(ClusterGetSettingsAction.INSTANCE, request); - } - - @Override - public void clusterSettings(ClusterGetSettingsAction.Request request, ActionListener listener) { - execute(ClusterGetSettingsAction.INSTANCE, request, listener); - } - - @Override - public ClusterGetSettingsAction.RequestBuilder prepareClusterSettings() { - return new ClusterGetSettingsAction.RequestBuilder(this, ClusterGetSettingsAction.INSTANCE); - } - @Override public void deleteDanglingIndex(DeleteDanglingIndexRequest request, ActionListener listener) { execute(DeleteDanglingIndexAction.INSTANCE, request, listener); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index a6f2cbdf7cd91..8fa16b4fa7b35 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -72,22 +72,21 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC clusterSettingsRequest.local(request.paramAsBoolean("local", clusterSettingsRequest.local())); clusterSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterSettingsRequest.masterNodeTimeout())); - return channel -> client.admin() - .cluster() - .clusterSettings( - clusterSettingsRequest, - new RestToXContentListener(channel).map( - response -> response( - response.persistentSettings(), - response.transientSettings(), - response.settings(), - renderDefaults, - settingsFilter, - clusterSettings, - settings - ) + return channel -> client.execute( + ClusterGetSettingsAction.INSTANCE, + clusterSettingsRequest, + new RestToXContentListener(channel).map( + response -> response( + response.persistentSettings(), + response.transientSettings(), + response.settings(), + renderDefaults, + settingsFilter, + clusterSettings, + settings ) - ); + ) + ); } private RestChannelConsumer prepareLegacyRequest(final RestRequest request, final NodeClient client, final boolean renderDefaults) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java index 5644c6ec43e62..7a66e6c1d476d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java @@ -11,7 +11,6 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksAction; import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction; -import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction; import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction; @@ -72,8 +71,7 @@ public class ClusterPrivilegeResolver { "cluster:monitor/*", GetIndexTemplatesAction.NAME, GetComponentTemplateAction.NAME, - GetComposableIndexTemplateAction.NAME, - ClusterGetSettingsAction.NAME + GetComposableIndexTemplateAction.NAME ); private static final Set MONITOR_ML_PATTERN = Set.of("cluster:monitor/xpack/ml/*"); private static final Set MONITOR_TEXT_STRUCTURE_PATTERN = Set.of("cluster:monitor/text_structure/*"); diff --git a/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java b/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java index ef3233f0794e5..2ca59c924b03f 100644 --- a/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java +++ b/x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java @@ -65,7 +65,6 @@ public class Constants { "cluster:admin/script_language/get", "cluster:admin/scripts/painless/context", "cluster:admin/scripts/painless/execute", - "cluster:admin/settings/get", "cluster:admin/settings/update", "cluster:admin/slm/delete", "cluster:admin/slm/execute", @@ -263,6 +262,7 @@ public class Constants { "cluster:monitor/nodes/stats", "cluster:monitor/nodes/usage", "cluster:monitor/remote/info", + "cluster:monitor/settings", "cluster:monitor/state", "cluster:monitor/stats", "cluster:monitor/task", From 0499aab209c20e15000ca994a89c6c17f29c7451 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Wed, 4 May 2022 11:40:12 -0400 Subject: [PATCH 09/16] Review changes --- .../TransportClusterGetSettingsAction.java | 4 +- .../cluster/RestClusterGetSettingsAction.java | 49 ++++++++----------- .../RestClusterGetSettingsActionTests.java | 9 ++-- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java index 9098cd6407f4b..d9862c7f00943 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java @@ -55,7 +55,9 @@ protected void masterOperation( ActionListener listener ) throws Exception { Metadata metadata = state.metadata(); - listener.onResponse(new ClusterGetSettingsAction.Response(metadata.persistentSettings(), metadata.transientSettings())); + listener.onResponse( + new ClusterGetSettingsAction.Response(metadata.persistentSettings(), metadata.transientSettings(), metadata.settings()) + ); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index 8f15f28153f37..b148be17480b7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.client.internal.Requests; import org.elasticsearch.client.internal.node.NodeClient; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; @@ -76,15 +75,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC ClusterGetSettingsAction.INSTANCE, clusterSettingsRequest, new RestToXContentListener(channel).map( - response -> response( - response.persistentSettings(), - response.transientSettings(), - response.settings(), - renderDefaults, - settingsFilter, - clusterSettings, - settings - ) + r -> response(r, renderDefaults, settingsFilter, clusterSettings, settings) ) ); } @@ -95,18 +86,22 @@ private RestChannelConsumer prepareLegacyRequest(final RestRequest request, fina clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); return channel -> client.admin() .cluster() - .state(clusterStateRequest, new RestToXContentListener(channel).map(response -> { - ClusterState state = response.getState(); - return response( - state.metadata().persistentSettings(), - state.metadata().transientSettings(), - state.metadata().settings(), - renderDefaults, - settingsFilter, - clusterSettings, - settings - ); - })); + .state( + clusterStateRequest, + new RestToXContentListener(channel).map( + r -> response( + new ClusterGetSettingsAction.Response( + r.getState().metadata().persistentSettings(), + r.getState().metadata().transientSettings(), + r.getState().metadata().settings() + ), + renderDefaults, + settingsFilter, + clusterSettings, + settings + ) + ) + ); } @Override @@ -120,18 +115,16 @@ public boolean canTripCircuitBreaker() { } static RestClusterGetSettingsResponse response( - final Settings persistentSettings, - final Settings transientSettings, - final Settings allSettings, + final ClusterGetSettingsAction.Response response, final boolean renderDefaults, final SettingsFilter settingsFilter, final ClusterSettings clusterSettings, final Settings settings ) { return new RestClusterGetSettingsResponse( - settingsFilter.filter(persistentSettings), - settingsFilter.filter(transientSettings), - renderDefaults ? settingsFilter.filter(clusterSettings.diff(allSettings, settings)) : Settings.EMPTY + settingsFilter.filter(response.persistentSettings()), + settingsFilter.filter(response.transientSettings()), + renderDefaults ? settingsFilter.filter(clusterSettings.diff(response.settings(), settings)) : Settings.EMPTY ); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java index 514cdf1db0f98..2edc50e9dc90c 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.rest.action.admin.cluster; +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; @@ -54,9 +55,11 @@ private void runTestFilterSettingsTest( final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet); final ClusterState clusterState = builder.build(); final RestClusterGetSettingsResponse response = RestClusterGetSettingsAction.response( - clusterState.metadata().persistentSettings(), - clusterState.metadata().transientSettings(), - clusterState.metadata().settings(), + new ClusterGetSettingsAction.Response( + clusterState.metadata().persistentSettings(), + clusterState.metadata().transientSettings(), + clusterState.metadata().settings() + ), randomBoolean(), filter, clusterSettings, From 8ff26f3657d0fb03285b41963d49a53e046f4329 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Wed, 4 May 2022 11:53:21 -0400 Subject: [PATCH 10/16] Move assert earlier --- .../action/admin/cluster/settings/ClusterGetSettingsAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 72990fba1c421..474782c7e56df 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 @@ -42,8 +42,8 @@ public Request(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); assert out.getVersion().onOrAfter(Version.V_8_3_0); + super.writeTo(out); } @Override From 8a13ecdc4ab02630e7a37aba2cc21efd48c848f4 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Thu, 5 May 2022 11:05:16 -0400 Subject: [PATCH 11/16] Add settings filters --- .../settings/TransportClusterGetSettingsAction.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java index d9862c7f00943..2ef9ad7def5ee 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -25,11 +26,14 @@ public class TransportClusterGetSettingsAction extends TransportMasterNodeReadAc ClusterGetSettingsAction.Request, ClusterGetSettingsAction.Response> { + private final SettingsFilter settingsFilter; + @Inject public TransportClusterGetSettingsAction( TransportService transportService, ClusterService clusterService, ThreadPool threadPool, + SettingsFilter settingsFilter, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver ) { @@ -45,6 +49,8 @@ public TransportClusterGetSettingsAction( ClusterGetSettingsAction.Response::new, ThreadPool.Names.SAME ); + + this.settingsFilter = settingsFilter; } @Override @@ -56,7 +62,11 @@ protected void masterOperation( ) throws Exception { Metadata metadata = state.metadata(); listener.onResponse( - new ClusterGetSettingsAction.Response(metadata.persistentSettings(), metadata.transientSettings(), metadata.settings()) + new ClusterGetSettingsAction.Response( + settingsFilter.filter(metadata.persistentSettings()), + settingsFilter.filter(metadata.transientSettings()), + settingsFilter.filter(metadata.settings()) + ) ); } From fad4113d62d81a915ab158ba02d321511f80b928 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Thu, 5 May 2022 12:00:12 -0400 Subject: [PATCH 12/16] Basic tests --- .../settings/ClusterGetSettingsTests.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java new file mode 100644 index 0000000000000..72ce81c3685a9 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java @@ -0,0 +1,88 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.action.admin.cluster.settings; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +import java.util.List; + +import static org.mockito.Mockito.mock; + +public class ClusterGetSettingsTests extends ESTestCase { + + public void testRequestConstruction() { + final Settings persistentSettings = Settings.builder() + .put("persistent.foo.filtered", "bar") + .put("persistent.foo.non_filtered", "baz") + .build(); + + final Settings transientSettings = Settings.builder() + .put("transient.foo.filtered", "bar") + .put("transient.foo.non_filtered", "baz") + .build(); + + ClusterGetSettingsAction.Response response = new ClusterGetSettingsAction.Response(persistentSettings, transientSettings, null); + + assertEquals(persistentSettings, response.persistentSettings()); + assertEquals(transientSettings, response.transientSettings()); + assertEquals(Settings.EMPTY, response.settings()); + } + + public void testTransportFilters() throws Exception { + final SettingsFilter filter = new SettingsFilter(List.of("persistent.foo.filtered", "transient.foo.filtered")); + + TransportClusterGetSettingsAction action = new TransportClusterGetSettingsAction( + mock(TransportService.class), + mock(ClusterService.class), + mock(ThreadPool.class), + filter, + mock(ActionFilters.class), + mock(IndexNameExpressionResolver.class) + ); + + final Settings persistentSettings = Settings.builder() + .put("persistent.foo.filtered", "bar") + .put("persistent.foo.non_filtered", "baz") + .build(); + + final Settings transientSettings = Settings.builder() + .put("transient.foo.filtered", "bar") + .put("transient.foo.non_filtered", "baz") + .build(); + + final Metadata metadata = Metadata.builder().persistentSettings(persistentSettings).transientSettings(transientSettings).build(); + final ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(metadata).build(); + + action.masterOperation(null, null, clusterState, new ActionListener<>() { + @Override + public void onResponse(ClusterGetSettingsAction.Response response) { + assertFalse(response.persistentSettings().hasValue("persistent.foo.filtered")); + assertTrue(response.persistentSettings().hasValue("persistent.foo.non_filtered")); + + assertFalse(response.transientSettings().hasValue("transient.foo.filtered")); + assertTrue(response.transientSettings().hasValue("transient.foo.non_filtered")); + } + + @Override + public void onFailure(Exception e) { + fail("Shouldn't reach here"); + } + }); + } +} From 8aac2dfca999a682372df998cd6186a6428206dd Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Thu, 5 May 2022 17:46:01 -0400 Subject: [PATCH 13/16] Add wire serialization test --- .../settings/ClusterGetSettingsAction.java | 15 ++++++ .../ClusterGetSettingsSerializationTests.java | 48 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsSerializationTests.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 index 474782c7e56df..71767728e57bc 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 @@ -60,6 +60,21 @@ public static class Response extends ActionResponse { private final Settings transientSettings; private final Settings settings; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Response response = (Response) o; + return Objects.equals(persistentSettings, response.persistentSettings) + && Objects.equals(transientSettings, response.transientSettings) + && Objects.equals(settings, response.settings); + } + + @Override + public int hashCode() { + return Objects.hash(persistentSettings, transientSettings, settings); + } + public Response(StreamInput in) throws IOException { super(in); assert in.getVersion().onOrAfter(Version.V_8_3_0); diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsSerializationTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsSerializationTests.java new file mode 100644 index 0000000000000..2f53e713d6fca --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsSerializationTests.java @@ -0,0 +1,48 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.action.admin.cluster.settings; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class ClusterGetSettingsSerializationTests extends AbstractWireSerializingTestCase { + @Override + protected Writeable.Reader instanceReader() { + return ClusterGetSettingsAction.Response::new; + } + + @Override + protected ClusterGetSettingsAction.Response createTestInstance() { + final Settings persistentSettings = Settings.builder() + .put("persistent.foo.filtered", "bar") + .put("persistent.foo.non_filtered", "baz") + .build(); + + final Settings transientSettings = Settings.builder() + .put("transient.foo.filtered", "bar") + .put("transient.foo.non_filtered", "baz") + .build(); + + final Settings allSettings = Settings.builder().put(persistentSettings).put(transientSettings).build(); + + return new ClusterGetSettingsAction.Response(persistentSettings, transientSettings, allSettings); + } + + @Override + protected ClusterGetSettingsAction.Response mutateInstance(ClusterGetSettingsAction.Response instance) { + final Settings otherSettings = Settings.builder().put("random.setting", randomAlphaOfLength(randomIntBetween(1, 12))).build(); + return switch (between(0, 2)) { + case 0 -> new ClusterGetSettingsAction.Response(otherSettings, instance.transientSettings(), instance.settings()); + case 1 -> new ClusterGetSettingsAction.Response(instance.persistentSettings(), otherSettings, instance.settings()); + case 2 -> new ClusterGetSettingsAction.Response(instance.persistentSettings(), instance.transientSettings(), otherSettings); + default -> throw new IllegalStateException("Unexpected switch value"); + }; + } +} From 70192073aecf9757e80cca2994264105bf2ff7f4 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Mon, 9 May 2022 10:56:36 +0200 Subject: [PATCH 14/16] Update server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java Co-authored-by: David Turner --- .../settings/ClusterGetSettingsTests.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java index 72ce81c3685a9..539fd5692b565 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java @@ -69,20 +69,15 @@ public void testTransportFilters() throws Exception { final Metadata metadata = Metadata.builder().persistentSettings(persistentSettings).transientSettings(transientSettings).build(); final ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(metadata).build(); - action.masterOperation(null, null, clusterState, new ActionListener<>() { - @Override - public void onResponse(ClusterGetSettingsAction.Response response) { - assertFalse(response.persistentSettings().hasValue("persistent.foo.filtered")); - assertTrue(response.persistentSettings().hasValue("persistent.foo.non_filtered")); - - assertFalse(response.transientSettings().hasValue("transient.foo.filtered")); - assertTrue(response.transientSettings().hasValue("transient.foo.non_filtered")); - } - - @Override - public void onFailure(Exception e) { - fail("Shouldn't reach here"); - } - }); - } + final PlainActionFuture future = new PlainActionFuture<>(); + action.masterOperation(null, null, clusterState, future); + assertTrue(future.isDone()); + + final ClusterGetSettingsAction.Response response = future.get(); + + assertFalse(response.persistentSettings().hasValue("persistent.foo.filtered")); + assertTrue(response.persistentSettings().hasValue("persistent.foo.non_filtered")); + + assertFalse(response.transientSettings().hasValue("transient.foo.filtered")); + assertTrue(response.transientSettings().hasValue("transient.foo.non_filtered")); } From c87040859b2dd383b2efd8a805659f6c28b07a08 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 9 May 2022 11:00:22 +0200 Subject: [PATCH 15/16] Resolve compile error --- .../action/admin/cluster/settings/ClusterGetSettingsTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java index 539fd5692b565..9e757894bcdda 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsTests.java @@ -8,8 +8,8 @@ package org.elasticsearch.action.admin.cluster.settings; -import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; @@ -80,4 +80,5 @@ public void testTransportFilters() throws Exception { assertFalse(response.transientSettings().hasValue("transient.foo.filtered")); assertTrue(response.transientSettings().hasValue("transient.foo.non_filtered")); + } } From 4d32a3f3a22bd155072e38f6d3caeb85bef280ef Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 9 May 2022 11:46:50 +0200 Subject: [PATCH 16/16] Review suggestions --- .../client/internal/ClusterAdminClient.java | 1 - .../admin/cluster/RestClusterGetSettingsAction.java | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java index a30efafcc93d9..02c8200a751c9 100644 --- a/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/internal/ClusterAdminClient.java @@ -756,5 +756,4 @@ public interface ClusterAdminClient extends ElasticsearchClient { * Delete specified dangling indices. */ ActionFuture deleteDanglingIndex(DeleteDanglingIndexRequest request); - } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index b148be17480b7..14a18ffeb04ab 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -12,6 +12,7 @@ import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction; import org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; +import org.elasticsearch.action.support.master.MasterNodeReadRequest; import org.elasticsearch.client.internal.Requests; import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -58,6 +59,11 @@ public String getName() { return "cluster_get_settings_action"; } + private void setUpRequestParams(MasterNodeReadRequest clusterRequest, RestRequest request) { + clusterRequest.local(request.paramAsBoolean("local", clusterRequest.local())); + clusterRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterRequest.masterNodeTimeout())); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final boolean renderDefaults = request.paramAsBoolean("include_defaults", false); @@ -68,8 +74,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC ClusterGetSettingsAction.Request clusterSettingsRequest = new ClusterGetSettingsAction.Request(); - clusterSettingsRequest.local(request.paramAsBoolean("local", clusterSettingsRequest.local())); - clusterSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterSettingsRequest.masterNodeTimeout())); + setUpRequestParams(clusterSettingsRequest, request); return channel -> client.execute( ClusterGetSettingsAction.INSTANCE, @@ -82,8 +87,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC private RestChannelConsumer prepareLegacyRequest(final RestRequest request, final NodeClient client, final boolean renderDefaults) { ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().routingTable(false).nodes(false); - clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); - clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); + setUpRequestParams(clusterStateRequest, request); return channel -> client.admin() .cluster() .state(