Skip to content

Commit

Permalink
Add REST APIs for IndexTemplateV2Metadata CRUD (elastic#54039)
Browse files Browse the repository at this point in the history
* Add REST APIs for IndexTemplateV2Metadata CRUD

This commit adds the get/put/delete APIs for interacting with the now v2 versions of index
templates.

These APIs are behind the existing `es.itv2_feature_flag_registered` system property feature flag.

Relates to elastic#53101

* Add exceptions for HLRC tests

* Add skips for 7.x versions

* Use index_template instead of template_v2 in action names

* Add test for MetaDataIndexTemplateService.addIndexTemplateV2

* Move removal to static method and add test

* Add unit tests for request classes (implement hashCode & equals)

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
dakrone and elasticmachine committed Mar 27, 2020
1 parent 2eb079b commit a81ee6f
Show file tree
Hide file tree
Showing 24 changed files with 1,597 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,9 @@ public void testApiNamingConventions() throws Exception {
"cluster.delete_component_template",
"indices.create_data_stream",
"indices.get_data_streams",
"indices.delete_data_stream"
"indices.delete_data_stream",
"indices.put_index_template",
"indices.delete_index_template"
};
//These API are not required for high-level client feature completeness
String[] notRequiredApi = new String[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"indices.delete_index_template":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html",
"description":"Deletes an index template."
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_index_template/{name}",
"methods":[
"DELETE"
],
"parts":{
"name":{
"type":"string",
"description":"The name of the template"
}
}
}
]
},
"params":{
"timeout":{
"type":"time",
"description":"Explicit operation timeout"
},
"master_timeout":{
"type":"time",
"description":"Specify timeout for connection to master"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"indices.get_index_template":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html",
"description":"Returns an index template."
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_index_template",
"methods":[
"GET"
]
},
{
"path":"/_index_template/{name}",
"methods":[
"GET"
],
"parts":{
"name":{
"type":"list",
"description":"The comma separated names of the index templates"
}
}
}
]
},
"params":{
"flat_settings":{
"type":"boolean",
"description":"Return settings in flat format (default: false)"
},
"master_timeout":{
"type":"time",
"description":"Explicit operation timeout for connection to master node"
},
"local":{
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"indices.put_index_template":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html",
"description":"Creates or updates an index template."
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_index_template/{name}",
"methods":[
"PUT",
"POST"
],
"parts":{
"name":{
"type":"string",
"description":"The name of the template"
}
}
}
]
},
"params":{
"order":{
"type":"number",
"description":"The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)"
},
"create":{
"type":"boolean",
"description":"Whether the index template should only be added if new or can also replace an existing one",
"default":false
},
"master_timeout":{
"type":"time",
"description":"Specify timeout for connection to master"
}
},
"body":{
"description":"The template definition",
"required":true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
setup:
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.put_index_template:
name: test
body:
index_patterns: test-*
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: keyword

---
"Get index template":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.get_index_template:
name: test

- match: {index_templates.0.name: test}
- match: {index_templates.0.index_template.index_patterns: ["test-*"]}
- match: {index_templates.0.index_template.template.settings: {index: {number_of_shards: '1', number_of_replicas: '0'}}}
- match: {index_templates.0.index_template.template.mappings: {properties: {field: {type: keyword}}}}

---
"Get all tindex emplates":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.put_index_template:
name: test2
body:
index_patterns: test2-*
template:
settings:
number_of_shards: 1

- do:
indices.get_index_template: {}

- length: {index_templates: 2}

---
"Get index template with local flag":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.get_index_template:
name: test
local: true

- match: {index_templates.0.name: test}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
setup:
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.delete_index_template:
name: '*'
ignore: 404
---
"Get missing template":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
catch: missing
indices.get_index_template:
name: test

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
"Put index template":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.put_index_template:
name: test
body:
index_patterns: test-*
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: keyword

- do:
indices.get_index_template:
name: test

- match: {index_templates.0.name: "test"}
- match: {index_templates.0.index_template.index_patterns: ["test-*"]}
- match: {index_templates.0.index_template.template.settings.index: {number_of_shards: '1', number_of_replicas: '0'}}
- match: {index_templates.0.index_template.template.mappings: {properties: {field: {type: keyword}}}}

---
"Put multiple index templates":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.put_index_template:
name: test
body:
index_patterns: [test-*, test2-*]
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: text
aliases:
test_alias: {}
test_blias: { routing: b }
test_clias: { filter: { term: { user: kimchy }}}

- do:
indices.get_index_template:
name: test

- match: {index_templates.0.index_template.index_patterns: ["test-*", "test2-*"]}
- match: {index_templates.0.index_template.template.settings.index: {number_of_shards: '1', number_of_replicas: '0'}}
- match: {index_templates.0.index_template.template.mappings: {properties: {field: {type: text}}}}
- length: {index_templates.0.index_template.template.aliases: 3}
- is_true: index_templates.0.index_template.template.aliases.test_alias
- match: {index_templates.0.index_template.template.aliases.test_blias.index_routing: "b" }
- match: {index_templates.0.index_template.template.aliases.test_blias.search_routing: "b" }
- match: {index_templates.0.index_template.template.aliases.test_clias.filter.term.user: "kimchy" }

---
"Put index template with 'create' flag":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
indices.put_index_template:
name: test2
body:
index_patterns: test-*
template:
settings:
number_of_shards: 1
number_of_replicas: 0

- do:
indices.get_index_template:
name: test2

- match: {index_templates.0.index_template.index_patterns: ["test-*"]}
- match: {index_templates.0.index_template.template.settings.index: {number_of_shards: '1', number_of_replicas: '0'}}

- do:
catch: bad_request
indices.put_index_template:
name: test2
create: true
body:
index_patterns: test-*
template:
settings:
number_of_shards: 1
number_of_replicas: 0

---
"Put index template without index_patterns":
- skip:
version: " - 7.7.99"
reason: "index template v2 API unavailable before 7.8"

- do:
catch: bad_request
indices.put_index_template:
name: test
body: {}
Loading

0 comments on commit a81ee6f

Please sign in to comment.