From 80e8017bb605db5a7296668485cefb33c49cbae8 Mon Sep 17 00:00:00 2001
From: Niels Bauman <33722607+nielsbauman@users.noreply.github.com>
Date: Fri, 10 Jan 2025 10:20:16 +1000
Subject: [PATCH] Run `TransportGetIndexTemplatesAction` on local node
(#119837)
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/119837.yaml | 5 ++
.../indices/get-index-template-v1.asciidoc | 6 +-
.../http/RestActionCancellationIT.java | 5 ++
.../api/indices.get_template.json | 3 +-
.../test/indices.exists_template/10_basic.yml | 5 ++
.../test/indices.get_template/10_basic.yml | 36 +++++++++
.../cluster/SimpleClusterStateIT.java | 3 +-
.../metadata/TemplateUpgradeServiceIT.java | 8 +-
.../template/IndexTemplateBlocksIT.java | 2 +-
.../template/SimpleIndexTemplateIT.java | 41 +++++-----
.../snapshots/RestoreSnapshotIT.java | 4 +-
.../SnapshotCustomPluginStateIT.java | 10 +--
.../get/GetIndexTemplatesRequest.java | 31 +++++---
.../get/GetIndexTemplatesRequestBuilder.java | 12 ++-
.../get/GetIndexTemplatesResponse.java | 12 +--
.../get/TransportGetIndexTemplatesAction.java | 46 ++++++-----
.../client/internal/IndicesAdminClient.java | 4 +-
.../indices/RestGetIndexTemplateAction.java | 33 +++++---
.../rest/action/cat/RestTemplatesAction.java | 11 ++-
.../get/GetIndexTemplatesResponseTests.java | 76 -------------------
.../org/elasticsearch/test/TestCluster.java | 2 +-
...ortMonitoringMigrateAlertsActionTests.java | 2 +-
.../local/LocalExporterIntegTests.java | 2 +-
.../LocalExporterResourceIntegTests.java | 6 +-
.../test/MonitoringIntegTestCase.java | 6 +-
.../PermissionPrecedenceTests.java | 4 +-
.../xpack/security/TemplateUpgraderTests.java | 2 +-
27 files changed, 199 insertions(+), 178 deletions(-)
create mode 100644 docs/changelog/119837.yaml
delete mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponseTests.java
diff --git a/docs/changelog/119837.yaml b/docs/changelog/119837.yaml
new file mode 100644
index 0000000000000..3c0a930aa3544
--- /dev/null
+++ b/docs/changelog/119837.yaml
@@ -0,0 +1,5 @@
+pr: 119837
+summary: Run `TransportGetIndexTemplateAction` on local node
+area: Indices APIs
+type: enhancement
+issues: []
diff --git a/docs/reference/indices/get-index-template-v1.asciidoc b/docs/reference/indices/get-index-template-v1.asciidoc
index 5072a194319ef..d1b652e3987d8 100644
--- a/docs/reference/indices/get-index-template-v1.asciidoc
+++ b/docs/reference/indices/get-index-template-v1.asciidoc
@@ -4,8 +4,8 @@
Get index template (legacy)
++++
-IMPORTANT: This documentation is about legacy index templates,
-which are deprecated and will be replaced by the composable templates introduced in {es} 7.8.
+IMPORTANT: This documentation is about legacy index templates,
+which are deprecated and will be replaced by the composable templates introduced in {es} 7.8.
For information about composable templates, see <>.
.New API reference
@@ -69,7 +69,7 @@ or use a value of `_all` or `*`.
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=flat-settings]
-include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local]
+include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local-deprecated-9.0.0]
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
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 641ca0be47ee5..ce514c5f1b1e7 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
@@ -17,6 +17,7 @@
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.admin.indices.template.get.GetIndexTemplatesAction;
import org.elasticsearch.action.support.CancellableActionTestPlugin;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.RefCountingListener;
@@ -72,6 +73,10 @@ public void testGetComponentTemplateCancellation() {
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_component_template"), GetComponentTemplateAction.NAME);
}
+ public void testGetIndexTemplateCancellation() {
+ runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_template"), GetIndexTemplatesAction.NAME);
+ }
+
public void testGetComposableTemplateCancellation() {
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_index_template"), GetComposableIndexTemplateAction.NAME);
}
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_template.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_template.json
index 963d9a4cb670e..74fdd1ef5c8a1 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_template.json
+++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_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.exists_template/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.exists_template/10_basic.yml
index 67592a013e8f1..4031423209830 100644
--- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.exists_template/10_basic.yml
+++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.exists_template/10_basic.yml
@@ -31,10 +31,15 @@ setup:
---
"Test indices.exists_template with local flag":
+ - requires:
+ test_runner_features: ["allowed_warnings"]
+
- do:
indices.exists_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"
- is_false: ''
diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_template/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_template/10_basic.yml
index 9becbd54a3773..c602d913502d5 100644
--- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_template/10_basic.yml
+++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_template/10_basic.yml
@@ -62,14 +62,50 @@ setup:
---
"Get template with local flag":
+ - requires:
+ test_runner_features: ["allowed_warnings"]
- do:
indices.get_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"
- is_true: test
+---
+"Deprecated local parameter":
+ - requires:
+ capabilities:
+ - method: GET
+ path: /_template
+ capabilities: ["local_param_deprecated"]
+ test_runner_features: ["capabilities", "warnings"]
+ reason: Deprecation was implemented with capability
+
+ - do:
+ indices.get_template:
+ name: test
+ 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_template:
+ name: test
+ local: true
+
+ - exists: test.index_patterns
+
---
"Get template with flat settings and master timeout":
diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java
index def125e5c99c3..7777dd778a6c1 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java
@@ -183,7 +183,8 @@ public void testIndexTemplates() throws Exception {
ClusterStateResponse clusterStateResponseUnfiltered = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get();
assertThat(clusterStateResponseUnfiltered.getState().metadata().templates().size(), is(greaterThanOrEqualTo(2)));
- GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates("foo_template").get();
+ GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "foo_template")
+ .get();
assertIndexTemplateExists(getIndexTemplatesResponse, "foo_template");
}
diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java
index 5e51c83d54795..b5c3861633350 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java
@@ -95,7 +95,9 @@ public void testTemplateUpdate() throws Exception {
// the updates only happen on cluster state updates, so we need to make sure that the cluster state updates are happening
// so we need to simulate updates to make sure the template upgrade kicks in
updateClusterSettings(Settings.builder().put(TestPlugin.UPDATE_TEMPLATE_DUMMY_SETTING.getKey(), updateCount.incrementAndGet()));
- List templates = indicesAdmin().prepareGetTemplates("test_*").get().getIndexTemplates();
+ List templates = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "test_*")
+ .get()
+ .getIndexTemplates();
assertThat(templates, hasSize(3));
boolean addedFound = false;
boolean changedFound = false;
@@ -139,7 +141,9 @@ private void assertTemplates() throws Exception {
// so we need to simulate updates to make sure the template upgrade kicks in
updateClusterSettings(Settings.builder().put(TestPlugin.UPDATE_TEMPLATE_DUMMY_SETTING.getKey(), updateCount.incrementAndGet()));
- List templates = indicesAdmin().prepareGetTemplates("test_*").get().getIndexTemplates();
+ List templates = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "test_*")
+ .get()
+ .getIndexTemplates();
assertThat(templates, hasSize(2));
boolean addedFound = false;
boolean changedFound = false;
diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/template/IndexTemplateBlocksIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/template/IndexTemplateBlocksIT.java
index 2aa834b98987a..a5d3dcaf104ad 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/indices/template/IndexTemplateBlocksIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/template/IndexTemplateBlocksIT.java
@@ -50,7 +50,7 @@ public void testIndexTemplatesWithBlocks() throws IOException {
try {
setClusterReadOnly(true);
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_blocks").get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_blocks").get();
assertThat(response.getIndexTemplates(), hasSize(1));
assertBlocked(
diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java
index e63da56c39c11..ac3fc28aab307 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java
@@ -79,7 +79,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
indicesAdmin().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), empty());
indicesAdmin().preparePutTemplate("template_1")
@@ -145,7 +145,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
);
expectThrows(IllegalArgumentException.class, builder);
- response = indicesAdmin().prepareGetTemplates().get();
+ response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), hasSize(2));
// index something into test_index, will match on both templates
@@ -292,7 +292,7 @@ public void testThatGetIndexTemplatesWorks() throws Exception {
.get();
logger.info("--> get template template_1");
- GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates("template_1").get();
+ GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(1));
assertThat(getTemplate1Response.getIndexTemplates().get(0), is(notNullValue()));
assertThat(getTemplate1Response.getIndexTemplates().get(0).patterns(), is(Collections.singletonList("te*")));
@@ -300,7 +300,8 @@ public void testThatGetIndexTemplatesWorks() throws Exception {
assertThat(getTemplate1Response.getIndexTemplates().get(0).getVersion(), is(123));
logger.info("--> get non-existing-template");
- GetIndexTemplatesResponse getTemplate2Response = indicesAdmin().prepareGetTemplates("non-existing-template").get();
+ GetIndexTemplatesResponse getTemplate2Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "non-existing-template")
+ .get();
assertThat(getTemplate2Response.getIndexTemplates(), hasSize(0));
}
@@ -375,7 +376,7 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
.get();
logger.info("--> get template template_*");
- GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates("template_*").get();
+ GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_*").get();
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(2));
List templateNames = new ArrayList<>();
@@ -384,7 +385,7 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
assertThat(templateNames, containsInAnyOrder("template_1", "template_2"));
logger.info("--> get all templates");
- getTemplate1Response = indicesAdmin().prepareGetTemplates("template*").get();
+ getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template*").get();
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(3));
templateNames = new ArrayList<>();
@@ -394,7 +395,7 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
assertThat(templateNames, containsInAnyOrder("template_1", "template_2", "template3"));
logger.info("--> get templates template_1 and template_2");
- getTemplate1Response = indicesAdmin().prepareGetTemplates("template_1", "template_2").get();
+ getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1", "template_2").get();
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(2));
templateNames = new ArrayList<>();
@@ -419,7 +420,7 @@ public void testThatInvalidGetIndexTemplatesFails() throws Exception {
private void testExpectActionRequestValidationException(String... names) {
assertRequestBuilderThrows(
- indicesAdmin().prepareGetTemplates(names),
+ indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, names),
ActionRequestValidationException.class,
"get template with " + Arrays.toString(names)
);
@@ -430,7 +431,7 @@ public void testBrokenMapping() throws Exception {
indicesAdmin().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), empty());
MapperParsingException e = expectThrows(
@@ -441,7 +442,7 @@ public void testBrokenMapping() throws Exception {
);
assertThat(e.getMessage(), containsString("Failed to parse mapping"));
- response = indicesAdmin().prepareGetTemplates().get();
+ response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), hasSize(0));
}
@@ -450,7 +451,7 @@ public void testInvalidSettings() throws Exception {
indicesAdmin().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), empty());
IllegalArgumentException e = expectThrows(
@@ -465,7 +466,7 @@ public void testInvalidSettings() throws Exception {
e.getMessage()
);
- response = indicesAdmin().prepareGetTemplates().get();
+ response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertEquals(0, response.getIndexTemplates().size());
createIndex("test");
@@ -597,7 +598,7 @@ public void testDuplicateAlias() throws Exception {
.addAlias(new Alias("my_alias").filter(termQuery("field", "value2")))
.get();
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_1").get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
assertThat(response.getIndexTemplates().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getAliases().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getAliases().get("my_alias").filter().string(), containsString("\"value1\""));
@@ -610,7 +611,7 @@ public void testAliasInvalidFilterValidJson() throws Exception {
.addAlias(new Alias("invalid_alias").filter("{ \"invalid\": {} }"))
.get();
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_1").get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
assertThat(response.getIndexTemplates().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getAliases().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getAliases().get("invalid_alias").filter().string(), equalTo("{\"invalid\":{}}"));
@@ -631,7 +632,7 @@ public void testAliasInvalidFilterInvalidJson() throws Exception {
);
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [invalid_alias]"));
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_1").get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
assertThat(response.getIndexTemplates().size(), equalTo(0));
}
@@ -747,7 +748,7 @@ public void testCombineTemplates() throws Exception {
indicesAdmin().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), empty());
// Now, a complete mapping with two separated templates is error
@@ -789,7 +790,7 @@ public void testCombineTemplates() throws Exception {
);
assertThat(e.getMessage(), containsString("analyzer [custom_1] has not been configured in mappings"));
- response = indicesAdmin().prepareGetTemplates().get();
+ response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), hasSize(1));
}
@@ -806,7 +807,7 @@ public void testOrderAndVersion() {
.setMapping("field", "type=text")
);
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("versioned_template").get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "versioned_template").get();
assertThat(response.getIndexTemplates().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getVersion(), equalTo(version));
assertThat(response.getIndexTemplates().get(0).getOrder(), equalTo(order));
@@ -856,7 +857,7 @@ public void testPartitionedTemplate() throws Exception {
indicesAdmin().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
- GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertThat(response.getIndexTemplates(), empty());
// provide more partitions than shards
@@ -882,7 +883,7 @@ public void testPartitionedTemplate() throws Exception {
assertThat(eBadMapping.getMessage(), containsString("must have routing required for partitioned index"));
// no templates yet
- response = indicesAdmin().prepareGetTemplates().get();
+ response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertEquals(0, response.getIndexTemplates().size());
// a valid configuration that only provides the partition size
diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java
index f84948afe97ad..b2bb38c5364a5 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/RestoreSnapshotIT.java
@@ -424,7 +424,7 @@ public void testRestoreTemplates() throws Exception {
logger.info("--> delete test template");
assertThat(indicesAdmin().prepareDeleteTemplate("test-template").get().isAcknowledged(), equalTo(true));
- GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
logger.info("--> restore cluster state");
@@ -437,7 +437,7 @@ public void testRestoreTemplates() throws Exception {
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), equalTo(0));
logger.info("--> check that template is restored");
- getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateExists(getIndexTemplatesResponse, "test-template");
}
diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SnapshotCustomPluginStateIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SnapshotCustomPluginStateIT.java
index 8adac063dcc5b..99cfafe48bc4f 100644
--- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SnapshotCustomPluginStateIT.java
+++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SnapshotCustomPluginStateIT.java
@@ -133,7 +133,7 @@ public void testIncludeGlobalState() throws Exception {
if (testTemplate) {
logger.info("--> delete test template");
cluster().wipeTemplates("test-template");
- GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
}
@@ -161,7 +161,7 @@ public void testIncludeGlobalState() throws Exception {
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), equalTo(0));
logger.info("--> check that template wasn't restored");
- GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
logger.info("--> restore cluster state");
@@ -173,7 +173,7 @@ public void testIncludeGlobalState() throws Exception {
if (testTemplate) {
logger.info("--> check that template is restored");
- getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateExists(getIndexTemplatesResponse, "test-template");
}
@@ -225,7 +225,7 @@ public void testIncludeGlobalState() throws Exception {
);
}
- getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
logger.info("--> try restoring index and cluster state from snapshot without global state");
@@ -238,7 +238,7 @@ public void testIncludeGlobalState() throws Exception {
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
logger.info("--> check that global state wasn't restored but index was");
- getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates().get();
+ getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
assertFalse(getPipelines("barbaz").isFound());
assertNull(safeExecute(GetStoredScriptAction.INSTANCE, new GetStoredScriptRequest(TEST_REQUEST_TIMEOUT, "foobar")).getSource());
diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java
index e3f765eb8ae88..1c911b4a0a97c 100644
--- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java
+++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java
@@ -9,38 +9,42 @@
package org.elasticsearch.action.admin.indices.template.get;
import org.elasticsearch.action.ActionRequestValidationException;
-import org.elasticsearch.action.support.master.MasterNodeReadRequest;
+import org.elasticsearch.action.support.local.LocalClusterStateRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
+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 java.io.IOException;
+import java.util.Map;
import static org.elasticsearch.action.ValidateActions.addValidationError;
/**
* Request that allows to retrieve index templates
*/
-public class GetIndexTemplatesRequest extends MasterNodeReadRequest {
+public class GetIndexTemplatesRequest extends LocalClusterStateRequest {
private final String[] names;
- public GetIndexTemplatesRequest(String... names) {
- super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
+ public GetIndexTemplatesRequest(TimeValue masterTimeout, String... names) {
+ super(masterTimeout);
this.names = names;
}
+ /**
+ * 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 GetIndexTemplatesRequest(StreamInput in) throws IOException {
super(in);
names = in.readStringArray();
}
- @Override
- public void writeTo(StreamOutput out) throws IOException {
- super.writeTo(out);
- out.writeStringArray(names);
- }
-
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
@@ -56,6 +60,11 @@ public ActionRequestValidationException validate() {
return validationException;
}
+ @Override
+ public Task createTask(long id, String type, String action, TaskId parentTaskId, Map headers) {
+ return new CancellableTask(id, type, action, "", parentTaskId, headers);
+ }
+
/**
* The names of the index templates.
*/
diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequestBuilder.java
index 97aabbd4631b7..ed53154cc5c93 100644
--- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequestBuilder.java
+++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequestBuilder.java
@@ -8,15 +8,13 @@
*/
package org.elasticsearch.action.admin.indices.template.get;
-import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
+import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.client.internal.ElasticsearchClient;
+import org.elasticsearch.core.TimeValue;
-public class GetIndexTemplatesRequestBuilder extends MasterNodeReadOperationRequestBuilder<
- GetIndexTemplatesRequest,
- GetIndexTemplatesResponse,
- GetIndexTemplatesRequestBuilder> {
+public class GetIndexTemplatesRequestBuilder extends ActionRequestBuilder {
- public GetIndexTemplatesRequestBuilder(ElasticsearchClient client, String... names) {
- super(client, GetIndexTemplatesAction.INSTANCE, new GetIndexTemplatesRequest(names));
+ public GetIndexTemplatesRequestBuilder(ElasticsearchClient client, TimeValue masterTimeout, String... names) {
+ super(client, GetIndexTemplatesAction.INSTANCE, new GetIndexTemplatesRequest(masterTimeout, names));
}
}
diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponse.java
index 2d854d2c6fa45..69ae3f1db92ae 100644
--- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponse.java
+++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponse.java
@@ -10,8 +10,8 @@
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
-import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
@@ -26,11 +26,6 @@ public class GetIndexTemplatesResponse extends ActionResponse implements ToXCont
private final List indexTemplates;
- public GetIndexTemplatesResponse(StreamInput in) throws IOException {
- super(in);
- indexTemplates = in.readCollectionAsList(IndexTemplateMetadata::readFrom);
- }
-
public GetIndexTemplatesResponse(List indexTemplates) {
this.indexTemplates = indexTemplates;
}
@@ -39,6 +34,11 @@ public List getIndexTemplates() {
return indexTemplates;
}
+ /**
+ * 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.writeCollection(indexTemplates);
diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java
index 99763d4d76dc6..c53ce4a6841ab 100644
--- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java
+++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java
@@ -10,45 +10,53 @@
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.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.regex.Regex;
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.ArrayList;
import java.util.List;
import java.util.Map;
-public class TransportGetIndexTemplatesAction extends TransportMasterNodeReadAction {
+public class TransportGetIndexTemplatesAction extends TransportLocalClusterStateAction<
+ GetIndexTemplatesRequest,
+ GetIndexTemplatesResponse> {
+ /**
+ * 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 TransportGetIndexTemplatesAction(
- TransportService transportService,
- ClusterService clusterService,
- ThreadPool threadPool,
- ActionFilters actionFilters,
- IndexNameExpressionResolver indexNameExpressionResolver
- ) {
+ public TransportGetIndexTemplatesAction(TransportService transportService, ClusterService clusterService, ActionFilters actionFilters) {
super(
GetIndexTemplatesAction.NAME,
- transportService,
- clusterService,
- threadPool,
actionFilters,
- GetIndexTemplatesRequest::new,
- indexNameExpressionResolver,
- GetIndexTemplatesResponse::new,
+ transportService.getTaskManager(),
+ clusterService,
EsExecutors.DIRECT_EXECUTOR_SERVICE
);
+
+ transportService.registerRequestHandler(
+ actionName,
+ executor,
+ false,
+ true,
+ GetIndexTemplatesRequest::new,
+ (request, channel, task) -> executeDirect(task, request, new ChannelActionListener<>(channel))
+ );
}
@Override
@@ -57,12 +65,13 @@ protected ClusterBlockException checkBlock(GetIndexTemplatesRequest request, Clu
}
@Override
- protected void masterOperation(
+ protected void localClusterStateOperation(
Task task,
GetIndexTemplatesRequest request,
ClusterState state,
ActionListener listener
) {
+ final var cancellableTask = (CancellableTask) task;
List results;
// If we did not ask for a specific name, then we return all templates
@@ -84,6 +93,7 @@ protected void masterOperation(
}
}
+ cancellableTask.ensureNotCancelled();
listener.onResponse(new GetIndexTemplatesResponse(results));
}
}
diff --git a/server/src/main/java/org/elasticsearch/client/internal/IndicesAdminClient.java b/server/src/main/java/org/elasticsearch/client/internal/IndicesAdminClient.java
index 00557bc4f05ef..67bb41d16fd8c 100644
--- a/server/src/main/java/org/elasticsearch/client/internal/IndicesAdminClient.java
+++ b/server/src/main/java/org/elasticsearch/client/internal/IndicesAdminClient.java
@@ -421,8 +421,8 @@ public void getTemplates(final GetIndexTemplatesRequest request, final ActionLis
execute(GetIndexTemplatesAction.INSTANCE, request, listener);
}
- public GetIndexTemplatesRequestBuilder prepareGetTemplates(String... names) {
- return new GetIndexTemplatesRequestBuilder(this, names);
+ public GetIndexTemplatesRequestBuilder prepareGetTemplates(TimeValue masterTimeout, String... names) {
+ return new GetIndexTemplatesRequestBuilder(this, masterTimeout, names);
}
public ActionFuture validateQuery(final ValidateQueryRequest request) {
diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java
index b0b879a6d787c..4d67a33194b4b 100644
--- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java
+++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java
@@ -9,12 +9,15 @@
package org.elasticsearch.rest.action.admin.indices;
+import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.Strings;
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.action.RestCancellableNodeClient;
import org.elasticsearch.rest.action.RestToXContentListener;
import java.io.IOException;
@@ -25,12 +28,14 @@
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;
/**
* The REST handler for get template and head template APIs.
*/
public class RestGetIndexTemplateAction extends BaseRestHandler {
+
+ private static final Set CAPABILITIES = Set.of("local_param_deprecated");
+
@Override
public List routes() {
return List.of(new Route(GET, "/_template"), new Route(GET, "/_template/{name}"), new Route(HEAD, "/_template/{name}"));
@@ -45,21 +50,31 @@ public String getName() {
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
- final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
-
- getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
- getIndexTemplatesRequest.masterNodeTimeout(getMasterNodeTimeout(request));
+ final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(
+ RestUtils.getMasterNodeTimeout(request),
+ names
+ );
+ RestUtils.consumeDeprecatedLocalParameter(request);
final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;
- return channel -> client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestToXContentListener<>(channel, r -> {
- final boolean templateExists = r.getIndexTemplates().isEmpty() == false;
- return (templateExists || implicitAll) ? OK : NOT_FOUND;
- }));
+ return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).execute(
+ GetIndexTemplatesAction.INSTANCE,
+ getIndexTemplatesRequest,
+ new RestToXContentListener<>(channel, r -> {
+ final boolean templateExists = r.getIndexTemplates().isEmpty() == false;
+ return (templateExists || implicitAll) ? OK : NOT_FOUND;
+ })
+ );
}
@Override
protected Set responseParams() {
return Settings.FORMAT_PARAMS;
}
+
+ @Override
+ public Set supportedCapabilities() {
+ return CAPABILITIES;
+ }
}
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 1ace9bfbeeb55..8175524c5e2df 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
@@ -54,17 +54,16 @@ protected void documentation(StringBuilder sb) {
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
final String matchPattern = request.hasParam("name") ? request.param("name") : null;
+ final var masterNodeTimeout = RestUtils.getMasterNodeTimeout(request);
final GetIndexTemplatesRequest getIndexTemplatesRequest = matchPattern == null
- ? new GetIndexTemplatesRequest()
- : new GetIndexTemplatesRequest(matchPattern);
- getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
- getIndexTemplatesRequest.masterNodeTimeout(RestUtils.getMasterNodeTimeout(request));
+ ? new GetIndexTemplatesRequest(masterNodeTimeout)
+ : new GetIndexTemplatesRequest(masterNodeTimeout, matchPattern);
+ RestUtils.consumeDeprecatedLocalParameter(request);
final GetComposableIndexTemplateAction.Request getComposableTemplatesRequest = new GetComposableIndexTemplateAction.Request(
- RestUtils.getMasterNodeTimeout(request),
+ masterNodeTimeout,
matchPattern
);
- RestUtils.consumeDeprecatedLocalParameter(request);
return channel -> {
diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponseTests.java
deleted file mode 100644
index d6ab47f448f8b..0000000000000
--- a/server/src/test/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesResponseTests.java
+++ /dev/null
@@ -1,76 +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.cluster.metadata.AliasMetadata;
-import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
-import org.elasticsearch.common.io.stream.Writeable;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.test.AbstractWireSerializingTestCase;
-
-import java.io.IOException;
-import java.io.UncheckedIOException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.stream.IntStream;
-
-import static org.hamcrest.Matchers.equalTo;
-
-public class GetIndexTemplatesResponseTests extends AbstractWireSerializingTestCase {
-
- @Override
- protected GetIndexTemplatesResponse createTestInstance() {
- List templates = new ArrayList<>();
- int numTemplates = between(0, 10);
- for (int t = 0; t < numTemplates; t++) {
- IndexTemplateMetadata.Builder templateBuilder = IndexTemplateMetadata.builder("template-" + t);
- templateBuilder.patterns(IntStream.range(0, between(1, 5)).mapToObj(i -> "pattern-" + i).toList());
- int numAlias = between(0, 5);
- for (int i = 0; i < numAlias; i++) {
- templateBuilder.putAlias(AliasMetadata.builder(randomAlphaOfLengthBetween(1, 10)));
- }
- if (randomBoolean()) {
- templateBuilder.settings(Settings.builder().put("index.setting-1", randomLong()));
- }
- if (randomBoolean()) {
- templateBuilder.order(randomInt());
- }
- if (randomBoolean()) {
- templateBuilder.version(between(0, 100));
- }
- if (randomBoolean()) {
- try {
- templateBuilder.putMapping("doc", "{\"properties\":{\"type\":\"text\"}}");
- } catch (IOException ex) {
- throw new UncheckedIOException(ex);
- }
- }
- templates.add(templateBuilder.build());
- }
- return new GetIndexTemplatesResponse(templates);
- }
-
- @Override
- protected GetIndexTemplatesResponse mutateInstance(GetIndexTemplatesResponse instance) {
- return null;// TODO implement https://github.com/elastic/elasticsearch/issues/25929
- }
-
- @Override
- protected Writeable.Reader instanceReader() {
- return GetIndexTemplatesResponse::new;
- }
-
- @Override
- protected void assertEqualInstances(GetIndexTemplatesResponse expectedInstance, GetIndexTemplatesResponse newInstance) {
- assertNotSame(newInstance, expectedInstance);
- assertThat(new HashSet<>(newInstance.getIndexTemplates()), equalTo(new HashSet<>(expectedInstance.getIndexTemplates())));
- }
-}
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 6b3debe07d25a..c79939a4184be 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/TestCluster.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/TestCluster.java
@@ -292,7 +292,7 @@ private void handleWipeIndicesFailure(Exception exception, boolean wipingAllIndi
private void wipeAllTemplates(Set exclude, RefCountingListener listeners) {
SubscribableListener
- .newForked(l -> client().admin().indices().prepareGetTemplates().execute(l))
+ .newForked(l -> client().admin().indices().prepareGetTemplates(TEST_REQUEST_TIMEOUT).execute(l))
.andThenAccept(response -> {
for (IndexTemplateMetadata indexTemplate : response.getIndexTemplates()) {
if (exclude.contains(indexTemplate.getName())) {
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java
index 9d47fc3e973b3..8935b9f450c1f 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java
@@ -520,7 +520,7 @@ private void checkMonitoringTemplates() {
templates.add(".monitoring-logstash");
templates.add(".monitoring-beats");
- GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(".monitoring-*").get();
+ GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(TEST_REQUEST_TIMEOUT, ".monitoring-*").get();
Set actualTemplates = response.getIndexTemplates().stream().map(IndexTemplateMetadata::getName).collect(Collectors.toSet());
assertEquals(templates, actualTemplates);
}
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java
index d68395ef7656f..3409fe8a69666 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java
@@ -236,7 +236,7 @@ private void checkMonitoringTemplates() {
templates.add(".monitoring-logstash");
templates.add(".monitoring-beats");
- GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(".monitoring-*").get();
+ GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(TEST_REQUEST_TIMEOUT, ".monitoring-*").get();
Set actualTemplates = response.getIndexTemplates().stream().map(IndexTemplateMetadata::getName).collect(Collectors.toSet());
assertEquals(templates, actualTemplates);
}
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterResourceIntegTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterResourceIntegTests.java
index d382905c1c9c2..4259fb5328435 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterResourceIntegTests.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterResourceIntegTests.java
@@ -319,7 +319,11 @@ private void assertResourcesExist() throws Exception {
private void assertTemplateNotUpdated() {
final String name = MonitoringTemplateRegistry.getTemplateConfigForMonitoredSystem(system).getTemplateName();
- for (IndexTemplateMetadata template : client().admin().indices().prepareGetTemplates(name).get().getIndexTemplates()) {
+ for (IndexTemplateMetadata template : client().admin()
+ .indices()
+ .prepareGetTemplates(TEST_REQUEST_TIMEOUT, name)
+ .get()
+ .getIndexTemplates()) {
final String docMapping = template.getMappings().toString();
assertThat(docMapping, notNullValue());
diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java
index bcf942292a1f8..92e18178a667b 100644
--- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java
+++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java
@@ -140,7 +140,11 @@ protected List> monitoringWatches() {
protected void assertTemplateInstalled(String name) {
boolean found = false;
- for (IndexTemplateMetadata template : client().admin().indices().prepareGetTemplates().get().getIndexTemplates()) {
+ for (IndexTemplateMetadata template : client().admin()
+ .indices()
+ .prepareGetTemplates(TEST_REQUEST_TIMEOUT)
+ .get()
+ .getIndexTemplates()) {
if (Regex.simpleMatch(name, template.getName())) {
found = true;
}
diff --git a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/PermissionPrecedenceTests.java b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/PermissionPrecedenceTests.java
index f80c232e40f73..60923ac023474 100644
--- a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/PermissionPrecedenceTests.java
+++ b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/PermissionPrecedenceTests.java
@@ -89,7 +89,7 @@ public void testDifferentCombinationsOfIndices() throws Exception {
).admin().indices().preparePutTemplate("template1").setPatterns(Collections.singletonList("test_*")).get();
assertAcked(putResponse);
- GetIndexTemplatesResponse getResponse = client.admin().indices().prepareGetTemplates("template1").get();
+ GetIndexTemplatesResponse getResponse = client.admin().indices().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template1").get();
List templates = getResponse.getIndexTemplates();
assertThat(templates, hasSize(1));
@@ -114,7 +114,7 @@ public void testDifferentCombinationsOfIndices() throws Exception {
basicAuthHeaderValue("user", SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING)
);
assertThrowsAuthorizationException(
- client.filterWithHeader(headers).admin().indices().prepareGetTemplates("template1")::get,
+ client.filterWithHeader(headers).admin().indices().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template1")::get,
GetIndexTemplatesAction.NAME,
"user"
);
diff --git a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/TemplateUpgraderTests.java b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/TemplateUpgraderTests.java
index d73719bb0cac4..416c4212acc49 100644
--- a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/TemplateUpgraderTests.java
+++ b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/TemplateUpgraderTests.java
@@ -79,7 +79,7 @@ public void testTemplatesWorkAsExpected() throws Exception {
}
private void assertTemplates(String existingTemplate, String deletedTemplate) {
- GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
+ GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
List templateNames = response.getIndexTemplates().stream().map(IndexTemplateMetadata::name).collect(Collectors.toList());
assertThat(templateNames, hasItem(existingTemplate));
assertThat(templateNames, not(hasItem(deletedTemplate)));