From 65e4ec129c9f330bfc902cbe1bb254267f593f5f Mon Sep 17 00:00:00 2001 From: Niels Bauman <33722607+nielsbauman@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:00:31 +1000 Subject: [PATCH] Run `TransportGetComposableIndexTemplate` on local node (#119830) This action solely needs the cluster state, it can run on any node. Additionally, it needs to be cancellable to avoid doing unnecessary work after a client failure or timeout. As a drive-by, this removes another usage of the trappy default master node timeout. --- docs/changelog/119830.yaml | 5 ++ .../indices/get-index-template.asciidoc | 2 +- .../datastreams/DataStreamIT.java | 2 +- .../http/RestActionCancellationIT.java | 5 ++ .../api/indices.exists_template.json | 3 +- .../api/indices.get_index_template.json | 3 +- .../indices.get_index_template/10_basic.yml | 34 +++++++++ .../ComponentTemplatesFileSettingsIT.java | 4 +- .../get/GetComposableIndexTemplateAction.java | 51 +++++++------- ...sportGetComposableIndexTemplateAction.java | 40 +++++++---- .../RestGetComposableIndexTemplateAction.java | 25 ++++--- .../rest/action/cat/RestTemplatesAction.java | 8 +-- ...etComposableIndexTemplateRequestTests.java | 30 -------- ...tComposableIndexTemplateResponseTests.java | 69 ------------------- .../org/elasticsearch/test/TestCluster.java | 6 +- .../AbstractWatcherIntegrationTestCase.java | 2 +- 16 files changed, 129 insertions(+), 160 deletions(-) create mode 100644 docs/changelog/119830.yaml delete mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateRequestTests.java delete mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateResponseTests.java diff --git a/docs/changelog/119830.yaml b/docs/changelog/119830.yaml new file mode 100644 index 0000000000000..cf852ae03c1db --- /dev/null +++ b/docs/changelog/119830.yaml @@ -0,0 +1,5 @@ +pr: 119830 +summary: Run `TransportGetComposableIndexTemplate` on local node +area: Indices APIs +type: enhancement +issues: [] diff --git a/docs/reference/indices/get-index-template.asciidoc b/docs/reference/indices/get-index-template.asciidoc index 9d27bf5b2b2a4..4cbf2b313f9de 100644 --- a/docs/reference/indices/get-index-template.asciidoc +++ b/docs/reference/indices/get-index-template.asciidoc @@ -65,7 +65,7 @@ expressions. If omitted, all templates are returned. include::{docdir}/rest-api/common-parms.asciidoc[tag=flat-settings] -include::{docdir}/rest-api/common-parms.asciidoc[tag=local] +include::{docdir}/rest-api/common-parms.asciidoc[tag=local-deprecated-9.0.0] include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout] diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java index dd0c93bfc6dfc..4a3dfac36d4ec 100644 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java @@ -722,7 +722,7 @@ public void testCannotDeleteComposableTemplateUsedByDataStream() throws Exceptio TransportDeleteComposableIndexTemplateAction.Request deleteRequest = new TransportDeleteComposableIndexTemplateAction.Request("id"); client().execute(TransportDeleteComposableIndexTemplateAction.TYPE, deleteRequest).get(); - GetComposableIndexTemplateAction.Request getReq = new GetComposableIndexTemplateAction.Request("id"); + GetComposableIndexTemplateAction.Request getReq = new GetComposableIndexTemplateAction.Request(TEST_REQUEST_TIMEOUT, "id"); Exception e3 = expectThrows(Exception.class, client().execute(GetComposableIndexTemplateAction.INSTANCE, getReq)); maybeE = ExceptionsHelper.unwrapCausesAndSuppressed(e3, err -> err.getMessage().contains("index template matching [id] not found")); assertTrue(maybeE.isPresent()); diff --git a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/RestActionCancellationIT.java b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/RestActionCancellationIT.java index c47eeef6101ff..641ca0be47ee5 100644 --- a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/RestActionCancellationIT.java +++ b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/RestActionCancellationIT.java @@ -16,6 +16,7 @@ import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction; import org.elasticsearch.action.admin.indices.recovery.RecoveryAction; import org.elasticsearch.action.admin.indices.template.get.GetComponentTemplateAction; +import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction; import org.elasticsearch.action.support.CancellableActionTestPlugin; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.action.support.RefCountingListener; @@ -71,6 +72,10 @@ public void testGetComponentTemplateCancellation() { runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_component_template"), GetComponentTemplateAction.NAME); } + public void testGetComposableTemplateCancellation() { + runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_index_template"), GetComposableIndexTemplateAction.NAME); + } + private void runRestActionCancellationTest(Request request, String actionName) { final var node = usually() ? internalCluster().getRandomNodeName() : internalCluster().startCoordinatingOnlyNode(Settings.EMPTY); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists_template.json index 77cb62b022515..a7f272af5b307 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists_template.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists_template.json @@ -32,9 +32,10 @@ }, "master_timeout":{ "type":"time", - "description":"Explicit operation timeout for connection to master node" + "description":"Timeout for waiting for new cluster state in case it is blocked" }, "local":{ + "deprecated":true, "type":"boolean", "description":"Return local information, do not retrieve the state from master node (default: false)" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_index_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_index_template.json index 4ed82c3bbc5eb..f0351ce8cfe94 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_index_template.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_index_template.json @@ -38,9 +38,10 @@ }, "master_timeout":{ "type":"time", - "description":"Explicit operation timeout for connection to master node" + "description":"Timeout for waiting for new cluster state in case it is blocked" }, "local":{ + "deprecated":true, "type":"boolean", "description":"Return local information, do not retrieve the state from master node (default: false)" }, diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml index c47df413df9e7..afb3b0d1ff83c 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml @@ -82,14 +82,48 @@ setup: --- "Get index template with local flag": + - requires: + test_runner_features: ["allowed_warnings"] - do: indices.get_index_template: name: test local: true + allowed_warnings: + - "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version" - match: {index_templates.0.name: test} +--- +"Deprecated local parameter": + - requires: + capabilities: + - method: GET + path: /_get_index_template + capabilities: ["local_param_deprecated"] + test_runner_features: ["capabilities", "warnings"] + reason: Deprecation was implemented with capability + + - do: + indices.get_index_template: + local: true + warnings: + - "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version" + +--- +"Deprecated local parameter works in v8 compat mode": + - requires: + test_runner_features: ["headers"] + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=8" + Accept: "application/vnd.elasticsearch+json;compatible-with=8" + indices.get_index_template: + local: true + + - exists: index_templates + --- "Add data stream lifecycle": - requires: diff --git a/server/src/internalClusterTest/java/org/elasticsearch/reservedstate/service/ComponentTemplatesFileSettingsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/reservedstate/service/ComponentTemplatesFileSettingsIT.java index 5325a17a7b7d6..c4c19dd8748a6 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/reservedstate/service/ComponentTemplatesFileSettingsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/reservedstate/service/ComponentTemplatesFileSettingsIT.java @@ -456,7 +456,7 @@ private void assertComponentAndIndexTemplateDelete(CountDownLatch savedClusterSt final var response = client().execute( GetComposableIndexTemplateAction.INSTANCE, - new GetComposableIndexTemplateAction.Request("template*") + new GetComposableIndexTemplateAction.Request(TEST_REQUEST_TIMEOUT, "template*") ).get(); assertThat(response.indexTemplates().keySet().stream().collect(Collectors.toSet()), containsInAnyOrder("template_1", "template_2")); @@ -594,7 +594,7 @@ private void assertClusterStateNotSaved(CountDownLatch savedClusterState, Atomic final var response = client().execute( GetComposableIndexTemplateAction.INSTANCE, - new GetComposableIndexTemplateAction.Request("err*") + new GetComposableIndexTemplateAction.Request(TEST_REQUEST_TIMEOUT, "err*") ).get(); assertTrue(response.indexTemplates().isEmpty()); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateAction.java index 67f87476ea6a5..5d322bba17c5e 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateAction.java @@ -14,12 +14,17 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration; -import org.elasticsearch.action.support.master.MasterNodeReadRequest; +import org.elasticsearch.action.support.local.LocalClusterStateRequest; import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.core.Nullable; +import org.elasticsearch.core.TimeValue; +import org.elasticsearch.core.UpdateForV10; +import org.elasticsearch.tasks.CancellableTask; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xcontent.XContentBuilder; @@ -40,17 +45,18 @@ private GetComposableIndexTemplateAction() { /** * Request that to retrieve one or more index templates */ - public static class Request extends MasterNodeReadRequest { + public static class Request extends LocalClusterStateRequest { @Nullable private final String name; private boolean includeDefaults; /** + * @param masterTimeout Timeout for waiting for new cluster state in case it is blocked. * @param name A template name or pattern, or {@code null} to retrieve all templates. */ - public Request(@Nullable String name) { - super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT); + public Request(TimeValue masterTimeout, @Nullable String name) { + super(masterTimeout); if (name != null && name.contains(",")) { throw new IllegalArgumentException("template name may not contain ','"); } @@ -58,6 +64,11 @@ public Request(@Nullable String name) { this.includeDefaults = false; } + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to read these requests until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) public Request(StreamInput in) throws IOException { super(in); name = in.readOptionalString(); @@ -68,15 +79,6 @@ public Request(StreamInput in) throws IOException { } } - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeOptionalString(name); - if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_9_X)) { - out.writeBoolean(includeDefaults); - } - } - public void includeDefaults(boolean includeDefaults) { this.includeDefaults = includeDefaults; } @@ -90,6 +92,11 @@ public ActionRequestValidationException validate() { return null; } + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId, Map headers) { + return new CancellableTask(id, type, action, "", parentTaskId, headers); + } + /** * The name of the index templates. */ @@ -124,19 +131,6 @@ public static class Response extends ActionResponse implements ToXContentObject @Nullable private final RolloverConfiguration rolloverConfiguration; - public Response(StreamInput in) throws IOException { - super(in); - indexTemplates = in.readMap(ComposableIndexTemplate::new); - if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_9_X)) { - rolloverConfiguration = in.readOptionalWriteable(RolloverConfiguration::new); - } else { - rolloverConfiguration = null; - } - if (in.getTransportVersion().between(TransportVersions.V_8_14_0, TransportVersions.V_8_16_0)) { - in.readOptionalWriteable(DataStreamGlobalRetention::read); - } - } - /** * Please use {@link GetComposableIndexTemplateAction.Response#Response(Map)} */ @@ -184,6 +178,11 @@ public RolloverConfiguration getRolloverConfiguration() { return rolloverConfiguration; } + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to write these responses until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) @Override public void writeTo(StreamOutput out) throws IOException { out.writeMap(indexTemplates, StreamOutput::writeWriteable); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetComposableIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetComposableIndexTemplateAction.java index 608e7529d34bf..3d5800de2cb3a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetComposableIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetComposableIndexTemplateAction.java @@ -12,51 +12,61 @@ import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; +import org.elasticsearch.action.support.ChannelActionListener; +import org.elasticsearch.action.support.local.TransportLocalClusterStateAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.metadata.DataStreamLifecycle; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.util.concurrent.EsExecutors; +import org.elasticsearch.core.UpdateForV10; import org.elasticsearch.injection.guice.Inject; +import org.elasticsearch.tasks.CancellableTask; import org.elasticsearch.tasks.Task; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import java.util.HashMap; import java.util.Map; -public class TransportGetComposableIndexTemplateAction extends TransportMasterNodeReadAction< +public class TransportGetComposableIndexTemplateAction extends TransportLocalClusterStateAction< GetComposableIndexTemplateAction.Request, GetComposableIndexTemplateAction.Response> { private final ClusterSettings clusterSettings; + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC it must be registered with the TransportService until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) + @SuppressWarnings("this-escape") @Inject public TransportGetComposableIndexTemplateAction( TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, - ActionFilters actionFilters, - IndexNameExpressionResolver indexNameExpressionResolver + ActionFilters actionFilters ) { super( GetComposableIndexTemplateAction.NAME, - transportService, - clusterService, - threadPool, actionFilters, - GetComposableIndexTemplateAction.Request::new, - indexNameExpressionResolver, - GetComposableIndexTemplateAction.Response::new, + transportService.getTaskManager(), + clusterService, EsExecutors.DIRECT_EXECUTOR_SERVICE ); clusterSettings = clusterService.getClusterSettings(); + + transportService.registerRequestHandler( + actionName, + executor, + false, + true, + GetComposableIndexTemplateAction.Request::new, + (request, channel, task) -> executeDirect(task, request, new ChannelActionListener<>(channel)) + ); } @Override @@ -65,12 +75,13 @@ protected ClusterBlockException checkBlock(GetComposableIndexTemplateAction.Requ } @Override - protected void masterOperation( + protected void localClusterStateOperation( Task task, GetComposableIndexTemplateAction.Request request, ClusterState state, ActionListener listener ) { + final var cancellableTask = (CancellableTask) task; Map allTemplates = state.metadata().templatesV2(); Map results; // If we did not ask for a specific name, then we return all templates @@ -91,6 +102,7 @@ protected void masterOperation( throw new ResourceNotFoundException("index template matching [" + request.name() + "] not found"); } } + cancellableTask.ensureNotCancelled(); if (request.includeDefaults()) { listener.onResponse( new GetComposableIndexTemplateAction.Response( diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetComposableIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetComposableIndexTemplateAction.java index 1a9bfe3bac9b8..78b2dc0963301 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetComposableIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetComposableIndexTemplateAction.java @@ -14,8 +14,10 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestUtils; import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.ServerlessScope; +import org.elasticsearch.rest.action.RestCancellableNodeClient; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; @@ -26,7 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; -import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; @ServerlessScope(Scope.PUBLIC) public class RestGetComposableIndexTemplateAction extends BaseRestHandler { @@ -47,17 +48,23 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - final GetComposableIndexTemplateAction.Request getRequest = new GetComposableIndexTemplateAction.Request(request.param("name")); - - getRequest.local(request.paramAsBoolean("local", getRequest.local())); - getRequest.masterNodeTimeout(getMasterNodeTimeout(request)); + final GetComposableIndexTemplateAction.Request getRequest = new GetComposableIndexTemplateAction.Request( + RestUtils.getMasterNodeTimeout(request), + request.param("name") + ); getRequest.includeDefaults(request.paramAsBoolean("include_defaults", false)); + RestUtils.consumeDeprecatedLocalParameter(request); + final boolean implicitAll = getRequest.name() == null; - return channel -> client.execute(GetComposableIndexTemplateAction.INSTANCE, getRequest, new RestToXContentListener<>(channel, r -> { - final boolean templateExists = r.indexTemplates().isEmpty() == false; - return (templateExists || implicitAll) ? OK : NOT_FOUND; - })); + return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).execute( + GetComposableIndexTemplateAction.INSTANCE, + getRequest, + new RestToXContentListener<>(channel, r -> { + final boolean templateExists = r.indexTemplates().isEmpty() == false; + return (templateExists || implicitAll) ? OK : NOT_FOUND; + }) + ); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java index 3d355f1905555..1ace9bfbeeb55 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.util.concurrent.ListenableFuture; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; +import org.elasticsearch.rest.RestUtils; import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.ServerlessScope; import org.elasticsearch.rest.action.RestResponseListener; @@ -30,7 +31,6 @@ import java.util.Map; import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; @ServerlessScope(Scope.INTERNAL) public class RestTemplatesAction extends AbstractCatAction { @@ -58,13 +58,13 @@ protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient ? new GetIndexTemplatesRequest() : new GetIndexTemplatesRequest(matchPattern); getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local())); - getIndexTemplatesRequest.masterNodeTimeout(getMasterNodeTimeout(request)); + getIndexTemplatesRequest.masterNodeTimeout(RestUtils.getMasterNodeTimeout(request)); final GetComposableIndexTemplateAction.Request getComposableTemplatesRequest = new GetComposableIndexTemplateAction.Request( + RestUtils.getMasterNodeTimeout(request), matchPattern ); - getComposableTemplatesRequest.local(request.paramAsBoolean("local", getComposableTemplatesRequest.local())); - getComposableTemplatesRequest.masterNodeTimeout(getMasterNodeTimeout(request)); + RestUtils.consumeDeprecatedLocalParameter(request); return channel -> { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateRequestTests.java deleted file mode 100644 index 08e40e6a548ac..0000000000000 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateRequestTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.action.admin.indices.template.get; - -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.test.AbstractWireSerializingTestCase; - -public class GetComposableIndexTemplateRequestTests extends AbstractWireSerializingTestCase { - @Override - protected Writeable.Reader instanceReader() { - return GetComposableIndexTemplateAction.Request::new; - } - - @Override - protected GetComposableIndexTemplateAction.Request createTestInstance() { - return new GetComposableIndexTemplateAction.Request(randomBoolean() ? null : randomAlphaOfLength(4)); - } - - @Override - protected GetComposableIndexTemplateAction.Request mutateInstance(GetComposableIndexTemplateAction.Request instance) { - return randomValueOtherThan(instance, this::createTestInstance); - } -} diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateResponseTests.java deleted file mode 100644 index ead01c977c8e4..0000000000000 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetComposableIndexTemplateResponseTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.action.admin.indices.template.get; - -import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration; -import org.elasticsearch.action.admin.indices.rollover.RolloverConfigurationTests; -import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; -import org.elasticsearch.cluster.metadata.ComposableIndexTemplateTests; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.indices.IndicesModule; -import org.elasticsearch.test.AbstractWireSerializingTestCase; - -import java.util.HashMap; -import java.util.Map; - -public class GetComposableIndexTemplateResponseTests extends AbstractWireSerializingTestCase { - @Override - protected Writeable.Reader instanceReader() { - return GetComposableIndexTemplateAction.Response::new; - } - - @Override - protected GetComposableIndexTemplateAction.Response createTestInstance() { - RolloverConfiguration rolloverConfiguration = randomBoolean() ? null : RolloverConfigurationTests.randomRolloverConditions(); - if (randomBoolean()) { - return new GetComposableIndexTemplateAction.Response(Map.of(), rolloverConfiguration); - } - Map templates = new HashMap<>(); - for (int i = 0; i < randomIntBetween(1, 4); i++) { - templates.put(randomAlphaOfLength(4), ComposableIndexTemplateTests.randomInstance()); - } - return new GetComposableIndexTemplateAction.Response(templates, rolloverConfiguration); - } - - @Override - protected GetComposableIndexTemplateAction.Response mutateInstance(GetComposableIndexTemplateAction.Response instance) { - var rolloverConfiguration = instance.getRolloverConfiguration(); - var templates = instance.indexTemplates(); - switch (randomInt(1)) { - case 0 -> rolloverConfiguration = randomBoolean() || rolloverConfiguration == null - ? randomValueOtherThan(rolloverConfiguration, RolloverConfigurationTests::randomRolloverConditions) - : null; - case 1 -> { - var updatedTemplates = new HashMap(); - for (String name : templates.keySet()) { - if (randomBoolean()) { - updatedTemplates.put(name, templates.get(name)); - } - } - updatedTemplates.put(randomAlphaOfLength(4), ComposableIndexTemplateTests.randomInstance()); - templates = updatedTemplates; - } - } - return new GetComposableIndexTemplateAction.Response(templates, rolloverConfiguration); - } - - @Override - protected NamedWriteableRegistry getNamedWriteableRegistry() { - return new NamedWriteableRegistry(IndicesModule.getNamedWriteables()); - } -} diff --git a/test/framework/src/main/java/org/elasticsearch/test/TestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/TestCluster.java index 368ffd7320089..6b3debe07d25a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TestCluster.java @@ -116,7 +116,11 @@ public void wipe(Set excludeTemplates) { private void deleteTemplates(Set excludeTemplates, ActionListener listener) { final SubscribableListener getComposableTemplates = SubscribableListener.newForked( - l -> client().execute(GetComposableIndexTemplateAction.INSTANCE, new GetComposableIndexTemplateAction.Request("*"), l) + l -> client().execute( + GetComposableIndexTemplateAction.INSTANCE, + new GetComposableIndexTemplateAction.Request(TEST_REQUEST_TIMEOUT, "*"), + l + ) ); final SubscribableListener getComponentTemplates = SubscribableListener.newForked( diff --git a/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 808cd5e0b22b6..626e1e1e9e9d5 100644 --- a/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -513,7 +513,7 @@ private void ensureWatcherTemplatesAdded() throws Exception { assertBusy(() -> { GetComposableIndexTemplateAction.Response response = client().execute( GetComposableIndexTemplateAction.INSTANCE, - new GetComposableIndexTemplateAction.Request(HISTORY_TEMPLATE_NAME) + new GetComposableIndexTemplateAction.Request(TEST_REQUEST_TIMEOUT, HISTORY_TEMPLATE_NAME) ).get(); assertThat("[" + HISTORY_TEMPLATE_NAME + "] is missing", response.indexTemplates().size(), equalTo(1)); });