Skip to content

Commit 80e8017

Browse files
authored
Run TransportGetIndexTemplatesAction on local node (elastic#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.
1 parent 65e4ec1 commit 80e8017

File tree

27 files changed

+199
-178
lines changed

27 files changed

+199
-178
lines changed

docs/changelog/119837.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 119837
2+
summary: Run `TransportGetIndexTemplateAction` on local node
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

docs/reference/indices/get-index-template-v1.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<titleabbrev>Get index template (legacy)</titleabbrev>
55
++++
66

7-
IMPORTANT: This documentation is about legacy index templates,
8-
which are deprecated and will be replaced by the composable templates introduced in {es} 7.8.
7+
IMPORTANT: This documentation is about legacy index templates,
8+
which are deprecated and will be replaced by the composable templates introduced in {es} 7.8.
99
For information about composable templates, see <<index-templates>>.
1010

1111
.New API reference
@@ -69,7 +69,7 @@ or use a value of `_all` or `*`.
6969

7070
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=flat-settings]
7171

72-
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local]
72+
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local-deprecated-9.0.0]
7373

7474
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
7575

qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/RestActionCancellationIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.action.admin.indices.recovery.RecoveryAction;
1818
import org.elasticsearch.action.admin.indices.template.get.GetComponentTemplateAction;
1919
import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction;
20+
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction;
2021
import org.elasticsearch.action.support.CancellableActionTestPlugin;
2122
import org.elasticsearch.action.support.PlainActionFuture;
2223
import org.elasticsearch.action.support.RefCountingListener;
@@ -72,6 +73,10 @@ public void testGetComponentTemplateCancellation() {
7273
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_component_template"), GetComponentTemplateAction.NAME);
7374
}
7475

76+
public void testGetIndexTemplateCancellation() {
77+
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_template"), GetIndexTemplatesAction.NAME);
78+
}
79+
7580
public void testGetComposableTemplateCancellation() {
7681
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_index_template"), GetComposableIndexTemplateAction.NAME);
7782
}

rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
},
3939
"master_timeout":{
4040
"type":"time",
41-
"description":"Explicit operation timeout for connection to master node"
41+
"description":"Timeout for waiting for new cluster state in case it is blocked"
4242
},
4343
"local":{
44+
"deprecated":true,
4445
"type":"boolean",
4546
"description":"Return local information, do not retrieve the state from master node (default: false)"
4647
}

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.exists_template/10_basic.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ setup:
3131

3232
---
3333
"Test indices.exists_template with local flag":
34+
- requires:
35+
test_runner_features: ["allowed_warnings"]
36+
3437
- do:
3538
indices.exists_template:
3639
name: test
3740
local: true
41+
allowed_warnings:
42+
- "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version"
3843

3944
- is_false: ''
4045

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_template/10_basic.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,50 @@ setup:
6262

6363
---
6464
"Get template with local flag":
65+
- requires:
66+
test_runner_features: ["allowed_warnings"]
6567

6668
- do:
6769
indices.get_template:
6870
name: test
6971
local: true
72+
allowed_warnings:
73+
- "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version"
7074

7175
- is_true: test
7276

77+
---
78+
"Deprecated local parameter":
79+
- requires:
80+
capabilities:
81+
- method: GET
82+
path: /_template
83+
capabilities: ["local_param_deprecated"]
84+
test_runner_features: ["capabilities", "warnings"]
85+
reason: Deprecation was implemented with capability
86+
87+
- do:
88+
indices.get_template:
89+
name: test
90+
local: true
91+
warnings:
92+
- "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version"
93+
94+
---
95+
"Deprecated local parameter works in v8 compat mode":
96+
- requires:
97+
test_runner_features: ["headers"]
98+
99+
- do:
100+
headers:
101+
Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
102+
Accept: "application/vnd.elasticsearch+json;compatible-with=8"
103+
indices.get_template:
104+
name: test
105+
local: true
106+
107+
- exists: test.index_patterns
108+
73109
---
74110
"Get template with flat settings and master timeout":
75111

server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ public void testIndexTemplates() throws Exception {
183183
ClusterStateResponse clusterStateResponseUnfiltered = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get();
184184
assertThat(clusterStateResponseUnfiltered.getState().metadata().templates().size(), is(greaterThanOrEqualTo(2)));
185185

186-
GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates("foo_template").get();
186+
GetIndexTemplatesResponse getIndexTemplatesResponse = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "foo_template")
187+
.get();
187188
assertIndexTemplateExists(getIndexTemplatesResponse, "foo_template");
188189
}
189190

server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public void testTemplateUpdate() throws Exception {
9595
// the updates only happen on cluster state updates, so we need to make sure that the cluster state updates are happening
9696
// so we need to simulate updates to make sure the template upgrade kicks in
9797
updateClusterSettings(Settings.builder().put(TestPlugin.UPDATE_TEMPLATE_DUMMY_SETTING.getKey(), updateCount.incrementAndGet()));
98-
List<IndexTemplateMetadata> templates = indicesAdmin().prepareGetTemplates("test_*").get().getIndexTemplates();
98+
List<IndexTemplateMetadata> templates = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "test_*")
99+
.get()
100+
.getIndexTemplates();
99101
assertThat(templates, hasSize(3));
100102
boolean addedFound = false;
101103
boolean changedFound = false;
@@ -139,7 +141,9 @@ private void assertTemplates() throws Exception {
139141
// so we need to simulate updates to make sure the template upgrade kicks in
140142
updateClusterSettings(Settings.builder().put(TestPlugin.UPDATE_TEMPLATE_DUMMY_SETTING.getKey(), updateCount.incrementAndGet()));
141143

142-
List<IndexTemplateMetadata> templates = indicesAdmin().prepareGetTemplates("test_*").get().getIndexTemplates();
144+
List<IndexTemplateMetadata> templates = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "test_*")
145+
.get()
146+
.getIndexTemplates();
143147
assertThat(templates, hasSize(2));
144148
boolean addedFound = false;
145149
boolean changedFound = false;

server/src/internalClusterTest/java/org/elasticsearch/indices/template/IndexTemplateBlocksIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testIndexTemplatesWithBlocks() throws IOException {
5050
try {
5151
setClusterReadOnly(true);
5252

53-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_blocks").get();
53+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_blocks").get();
5454
assertThat(response.getIndexTemplates(), hasSize(1));
5555

5656
assertBlocked(

server/src/internalClusterTest/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
7979
indicesAdmin().prepareDeleteTemplate("*").get();
8080

8181
// check get all templates on an empty index.
82-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
82+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
8383
assertThat(response.getIndexTemplates(), empty());
8484

8585
indicesAdmin().preparePutTemplate("template_1")
@@ -145,7 +145,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
145145
);
146146
expectThrows(IllegalArgumentException.class, builder);
147147

148-
response = indicesAdmin().prepareGetTemplates().get();
148+
response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
149149
assertThat(response.getIndexTemplates(), hasSize(2));
150150

151151
// index something into test_index, will match on both templates
@@ -292,15 +292,16 @@ public void testThatGetIndexTemplatesWorks() throws Exception {
292292
.get();
293293

294294
logger.info("--> get template template_1");
295-
GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates("template_1").get();
295+
GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
296296
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(1));
297297
assertThat(getTemplate1Response.getIndexTemplates().get(0), is(notNullValue()));
298298
assertThat(getTemplate1Response.getIndexTemplates().get(0).patterns(), is(Collections.singletonList("te*")));
299299
assertThat(getTemplate1Response.getIndexTemplates().get(0).getOrder(), is(0));
300300
assertThat(getTemplate1Response.getIndexTemplates().get(0).getVersion(), is(123));
301301

302302
logger.info("--> get non-existing-template");
303-
GetIndexTemplatesResponse getTemplate2Response = indicesAdmin().prepareGetTemplates("non-existing-template").get();
303+
GetIndexTemplatesResponse getTemplate2Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "non-existing-template")
304+
.get();
304305
assertThat(getTemplate2Response.getIndexTemplates(), hasSize(0));
305306
}
306307

@@ -375,7 +376,7 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
375376
.get();
376377

377378
logger.info("--> get template template_*");
378-
GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates("template_*").get();
379+
GetIndexTemplatesResponse getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_*").get();
379380
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(2));
380381

381382
List<String> templateNames = new ArrayList<>();
@@ -384,7 +385,7 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
384385
assertThat(templateNames, containsInAnyOrder("template_1", "template_2"));
385386

386387
logger.info("--> get all templates");
387-
getTemplate1Response = indicesAdmin().prepareGetTemplates("template*").get();
388+
getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template*").get();
388389
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(3));
389390

390391
templateNames = new ArrayList<>();
@@ -394,7 +395,7 @@ public void testThatGetIndexTemplatesWithSimpleRegexWorks() throws Exception {
394395
assertThat(templateNames, containsInAnyOrder("template_1", "template_2", "template3"));
395396

396397
logger.info("--> get templates template_1 and template_2");
397-
getTemplate1Response = indicesAdmin().prepareGetTemplates("template_1", "template_2").get();
398+
getTemplate1Response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1", "template_2").get();
398399
assertThat(getTemplate1Response.getIndexTemplates(), hasSize(2));
399400

400401
templateNames = new ArrayList<>();
@@ -419,7 +420,7 @@ public void testThatInvalidGetIndexTemplatesFails() throws Exception {
419420

420421
private void testExpectActionRequestValidationException(String... names) {
421422
assertRequestBuilderThrows(
422-
indicesAdmin().prepareGetTemplates(names),
423+
indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, names),
423424
ActionRequestValidationException.class,
424425
"get template with " + Arrays.toString(names)
425426
);
@@ -430,7 +431,7 @@ public void testBrokenMapping() throws Exception {
430431
indicesAdmin().prepareDeleteTemplate("*").get();
431432

432433
// check get all templates on an empty index.
433-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
434+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
434435
assertThat(response.getIndexTemplates(), empty());
435436

436437
MapperParsingException e = expectThrows(
@@ -441,7 +442,7 @@ public void testBrokenMapping() throws Exception {
441442
);
442443
assertThat(e.getMessage(), containsString("Failed to parse mapping"));
443444

444-
response = indicesAdmin().prepareGetTemplates().get();
445+
response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
445446
assertThat(response.getIndexTemplates(), hasSize(0));
446447
}
447448

@@ -450,7 +451,7 @@ public void testInvalidSettings() throws Exception {
450451
indicesAdmin().prepareDeleteTemplate("*").get();
451452

452453
// check get all templates on an empty index.
453-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
454+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
454455
assertThat(response.getIndexTemplates(), empty());
455456

456457
IllegalArgumentException e = expectThrows(
@@ -465,7 +466,7 @@ public void testInvalidSettings() throws Exception {
465466
e.getMessage()
466467
);
467468

468-
response = indicesAdmin().prepareGetTemplates().get();
469+
response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
469470
assertEquals(0, response.getIndexTemplates().size());
470471

471472
createIndex("test");
@@ -597,7 +598,7 @@ public void testDuplicateAlias() throws Exception {
597598
.addAlias(new Alias("my_alias").filter(termQuery("field", "value2")))
598599
.get();
599600

600-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_1").get();
601+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
601602
assertThat(response.getIndexTemplates().size(), equalTo(1));
602603
assertThat(response.getIndexTemplates().get(0).getAliases().size(), equalTo(1));
603604
assertThat(response.getIndexTemplates().get(0).getAliases().get("my_alias").filter().string(), containsString("\"value1\""));
@@ -610,7 +611,7 @@ public void testAliasInvalidFilterValidJson() throws Exception {
610611
.addAlias(new Alias("invalid_alias").filter("{ \"invalid\": {} }"))
611612
.get();
612613

613-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_1").get();
614+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
614615
assertThat(response.getIndexTemplates().size(), equalTo(1));
615616
assertThat(response.getIndexTemplates().get(0).getAliases().size(), equalTo(1));
616617
assertThat(response.getIndexTemplates().get(0).getAliases().get("invalid_alias").filter().string(), equalTo("{\"invalid\":{}}"));
@@ -631,7 +632,7 @@ public void testAliasInvalidFilterInvalidJson() throws Exception {
631632
);
632633
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [invalid_alias]"));
633634

634-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("template_1").get();
635+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "template_1").get();
635636
assertThat(response.getIndexTemplates().size(), equalTo(0));
636637
}
637638

@@ -747,7 +748,7 @@ public void testCombineTemplates() throws Exception {
747748
indicesAdmin().prepareDeleteTemplate("*").get();
748749

749750
// check get all templates on an empty index.
750-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
751+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
751752
assertThat(response.getIndexTemplates(), empty());
752753

753754
// Now, a complete mapping with two separated templates is error
@@ -789,7 +790,7 @@ public void testCombineTemplates() throws Exception {
789790
);
790791
assertThat(e.getMessage(), containsString("analyzer [custom_1] has not been configured in mappings"));
791792

792-
response = indicesAdmin().prepareGetTemplates().get();
793+
response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
793794
assertThat(response.getIndexTemplates(), hasSize(1));
794795

795796
}
@@ -806,7 +807,7 @@ public void testOrderAndVersion() {
806807
.setMapping("field", "type=text")
807808
);
808809

809-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates("versioned_template").get();
810+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT, "versioned_template").get();
810811
assertThat(response.getIndexTemplates().size(), equalTo(1));
811812
assertThat(response.getIndexTemplates().get(0).getVersion(), equalTo(version));
812813
assertThat(response.getIndexTemplates().get(0).getOrder(), equalTo(order));
@@ -856,7 +857,7 @@ public void testPartitionedTemplate() throws Exception {
856857
indicesAdmin().prepareDeleteTemplate("*").get();
857858

858859
// check get all templates on an empty index.
859-
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates().get();
860+
GetIndexTemplatesResponse response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
860861
assertThat(response.getIndexTemplates(), empty());
861862

862863
// provide more partitions than shards
@@ -882,7 +883,7 @@ public void testPartitionedTemplate() throws Exception {
882883
assertThat(eBadMapping.getMessage(), containsString("must have routing required for partitioned index"));
883884

884885
// no templates yet
885-
response = indicesAdmin().prepareGetTemplates().get();
886+
response = indicesAdmin().prepareGetTemplates(TEST_REQUEST_TIMEOUT).get();
886887
assertEquals(0, response.getIndexTemplates().size());
887888

888889
// a valid configuration that only provides the partition size

0 commit comments

Comments
 (0)