Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for V2 index templates to /_cat/templates #55829

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
"Help":
- skip:
version: " - 7.9.99"
reason: "not backported yet"

- do:
cat.templates:
help: true
Expand All @@ -10,6 +14,7 @@
index_patterns .+ \n
order .+ \n
version .+ \n
composed_of .+ \n
$/

---
Expand All @@ -26,6 +31,9 @@

---
"Normal templates":
- skip:
version: " - 7.9.99"
reason: "not backported yet"

- do:
indices.put_template:
Expand Down Expand Up @@ -58,7 +66,7 @@
(^|\n)test \s+
\[test-\*\] \s+
0 \s+
1
1 \s+
(\n|$)
/

Expand All @@ -68,12 +76,15 @@
(^|\n)test_2 \s+
\[test-2\*\] \s+
1 \s+
2
2 \s+
(\n|$)
/

---
"Filtered templates":
- skip:
version: " - 7.9.99"
reason: "not backported yet"

- do:
indices.put_template:
Expand Down Expand Up @@ -107,12 +118,16 @@
test \s+
\[t\*\] \s+
0 \s+
1
1 \s*
\n
$/

---
"Column headers":
- skip:
version: " - 7.9.99"
reason: "not backported yet"

- do:
indices.put_template:
name: test
Expand All @@ -135,17 +150,22 @@
name \s+
index_patterns \s+
order \s+
version
version \s+
composed_of
\n
test \s+
\[t\*\] \s+
0 \s+
1
1 \s*
\n
$/

---
"Select columns":
- skip:
version: " - 7.9.99"
reason: "not backported yet"

- do:
indices.put_template:
name: test
Expand Down Expand Up @@ -177,7 +197,10 @@
---
"Sort templates":
- skip:
version: " - 7.9.99"
reason: "not backported yet"
features: default_shards, no_xpack

- do:
indices.put_template:
name: test
Expand Down Expand Up @@ -207,8 +230,8 @@
- match:
$body: |
/^
test \s+ \[t\*\] \s+ \n
test_1 \s+ \[te\*\] \s+ 1 \n
test \s+ \[t\*\] \s+ \n \n
test_1 \s+ \[te\*\] \s+ 1 \n \n
$/

- do:
Expand All @@ -219,15 +242,18 @@
- match:
$body: |
/^
test_1 \s+ \[te\*\] \s+ 1\n
test \s+ \[t\*\] \s+ \n
test_1 \s+ \[te\*\] \s+ 1\n \n
test \s+ \[t\*\] \s+ \n \n

$/

---
"Multiple template":
- skip:
version: " - 7.9.99"
reason: "not backported yet"
features: default_shards, no_xpack

- do:
indices.put_template:
name: test_1
Expand All @@ -254,4 +280,57 @@
test_1 \s+
\[t\*,\ te\*\]
\n
\n
$/

---
"Mixture of V1 and V2 templates":
- skip:
version: " - 7.9.99"
reason: "not backported yet"
features: allowed_warnings

- do:
indices.put_template:
name: test
body:
order: 0
version: 1
index_patterns: test-*
settings:
number_of_shards: 1
number_of_replicas: 0

- do:
allowed_warnings:
- "index template [testv2] has index patterns [v2-test] matching patterns from existing older templates [global] with patterns (global => [*]); this template [testv2] will take precedence during new index creation"
indices.put_index_template:
name: testv2
body:
index_patterns: [v2-test]
priority: 4
version: 3
composed_of: [foo, bar]

- do:
cat.templates: {}

- match:
$body: >
/
(^|\n)test \s+
\[test-\*\] \s+
0 \s+
1 \s+
(\n|$)
/

- match:
$body: >
/
(^|\n)testv2 \s+
\[v2-test\] \s+
4 \s+
3 \s+
\[foo,\ bar\]
/
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateV2;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.regex.Regex;
Expand All @@ -32,6 +33,7 @@
import org.elasticsearch.rest.action.RestResponseListener;

import java.util.List;
import java.util.Map;

import static org.elasticsearch.rest.RestRequest.Method.GET;

Expand Down Expand Up @@ -76,8 +78,9 @@ protected Table getTableWithHeader(RestRequest request) {
table.startHeaders();
table.addCell("name", "alias:n;desc:template name");
table.addCell("index_patterns", "alias:t;desc:template index patterns");
table.addCell("order", "alias:o;desc:template application order number");
table.addCell("order", "alias:o,p;desc:template application order/priority number");
table.addCell("version", "alias:v;desc:version");
table.addCell("composed_of", "alias:c;desc:component templates comprising index template");
table.endHeaders();
return table;
}
Expand All @@ -93,6 +96,21 @@ private Table buildTable(RestRequest request, ClusterStateResponse clusterStateR
table.addCell("[" + String.join(", ", indexData.patterns()) + "]");
table.addCell(indexData.getOrder());
table.addCell(indexData.getVersion());
table.addCell("");
table.endRow();
}
}

for (Map.Entry<String, IndexTemplateV2> entry : metadata.templatesV2().entrySet()) {
String name = entry.getKey();
IndexTemplateV2 template = entry.getValue();
if (patternString == null || Regex.simpleMatch(patternString, name)) {
table.startRow();
table.addCell(name);
table.addCell("[" + String.join(", ", template.indexPatterns()) + "]");
table.addCell(template.priority());
table.addCell(template.version());
table.addCell("[" + String.join(", ", template.composedOf()) + "]");
table.endRow();
}
}
Expand Down