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 simulate template composition API _index_template/_simulate_index/{name} #55686

Merged
merged 28 commits into from Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2be7e19
Add _index_template/_simulate_index/{name} api
andreidan Apr 23, 2020
17a912e
Remove unused logger
andreidan Apr 24, 2020
3025a51
Merge branch 'master' into itv2-simulate-api
elasticmachine Apr 24, 2020
490ca72
Tests
andreidan Apr 24, 2020
20eeea4
Yaml parsing and new line
andreidan Apr 24, 2020
871980a
Fix tests
andreidan Apr 24, 2020
f34071d
Fix version restriction
andreidan Apr 24, 2020
8ba793a
Fix response serialisation
andreidan Apr 24, 2020
4b85534
Rename PostSimulateIndexTemplateAction to SimulateIndexTemplateAction
andreidan Apr 24, 2020
b98a59b
Rename RestPostSimulateIndexTemplateAction to RestSimulateIndexTempla…
andreidan Apr 24, 2020
cbcc977
Remove "post_" prefix
andreidan Apr 24, 2020
3ca7e20
Drop /post from action name
andreidan Apr 27, 2020
a436e39
Update rest api spec
andreidan Apr 27, 2020
604936a
Drop "post" from package name
andreidan Apr 27, 2020
edc8610
Fix indentation
andreidan Apr 27, 2020
34d7a75
Use the resolveAndValidateAliases method to resolve aliases
andreidan Apr 27, 2020
c68ece9
Merge branch 'master' into itv2-simulate-api
elasticmachine Apr 27, 2020
6a319da
Rename overlapping_v1_templates to overlapping
andreidan Apr 27, 2020
4134282
Update methods docs and fix use case where candidate exists
andreidan Apr 28, 2020
facb14a
Return overlapping V1 and V2 templates and their patterns
andreidan Apr 28, 2020
651b578
Remove v1 mentions
andreidan Apr 28, 2020
03d9b0f
Drop dynamic keys from response
andreidan Apr 28, 2020
8863d1f
Use additional map
andreidan Apr 28, 2020
db5782b
Update remove indexService reason
andreidan Apr 28, 2020
7a6582c
Merge branch 'master' into itv2-simulate-api
elasticmachine Apr 28, 2020
ab918fd
Use composed_of in the simulated template
andreidan Apr 28, 2020
e368647
Assert overlapping is array
andreidan Apr 28, 2020
d3cac66
Merge branch 'master' into itv2-simulate-api
elasticmachine Apr 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -861,6 +861,7 @@ public void testApiNamingConventions() throws Exception {
"indices.create_data_stream",
"indices.get_data_streams",
"indices.delete_data_stream",
"indices.simulate_index_template"
};
//These API are not required for high-level client feature completeness
String[] notRequiredApi = new String[] {
Expand Down
@@ -0,0 +1,35 @@
{
"indices.simulate_index_template":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html",
"description": "Simulate matching the given index name against the index templates in the system"
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_index_template/_simulate_index/{name}",
"methods":[
"POST"
],
"parts":{
"name":{
"type":"string",
"description":"The name of the index (it will have to be a concrete index name)"
andreidan marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
]
},
"params":{
"master_timeout":{
"type":"time",
"description":"Specify timeout for connection to master"
}
},
"body":{
"description":"New index template definition, which will be included in the simulation, as if it already exists in the system",
"required":false
}
}
}
@@ -0,0 +1,140 @@
---
"Simulate index template without new template in the body":
- skip:
version: " - 7.99.99"
reason: "simulate index template API has not been backported"
features: allowed_warnings

- do:
allowed_warnings:
- "index template [test] has index patterns [te*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test] will take precedence during new index creation"
indices.put_index_template:
name: test
body:
index_patterns: te*
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: keyword

- do:
indices.simulate_index_template:
name: test

- match: {template.settings.index.number_of_shards: "1"}
- match: {template.settings.index.number_of_replicas: "0"}
- match: {template.mappings._doc.properties.field.type: "keyword"}
- match: {overlapping_v1_templates: {}}

---
"Simulate index template specifying a new template":
- skip:
version: " - 7.99.99"
reason: "simulate index template API has not been backported"
features: allowed_warnings

- do:
allowed_warnings:
- "index template [test] has index patterns [te*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test] will take precedence during new index creation"
indices.put_index_template:
name: test
body:
index_patterns: te*
priority: 10
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: keyword

- do:
indices.simulate_index_template:
name: test
body:
index_patterns: te*
priority: 15
template:
settings:
index.blocks.write: true

- match: {template.settings.index.blocks.write: "true"}
- match: {overlapping_v1_templates: {}}

---
"Simulate index template with index not matching any template":
- skip:
version: " - 7.99.99"
reason: "simulate index template API has not been backported"
features: allowed_warnings

- do:
allowed_warnings:
- "index template [test] has index patterns [te*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test] will take precedence during new index creation"
indices.put_index_template:
name: test
body:
index_patterns: te*
priority: 10
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: keyword

- do:
indices.simulate_index_template:
name: will_not_match

- match: {body: null}

---
"Simulate index matches overlapping V1 and V2 templates":
- skip:
version: " - 7.99.99"
reason: "simulate index template API has not been backported"
features: allowed_warnings

- do:
indices.put_template:
name: v1_template
body:
index_patterns: [t*, t1*]
settings:
number_of_shards: 5

- do:
allowed_warnings:
- "index template [test] has index patterns [te*] matching patterns from existing older templates [v1_template] with patterns
(v1_template => [t*, t1*]); this template [test] will take precedence during new index creation"
indices.put_index_template:
name: test
body:
index_patterns: te*
priority: 10
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
field:
type: keyword

- do:
indices.simulate_index_template:
name: test

- match: {template.settings.index.number_of_shards: "1"}
- match: {template.settings.index.number_of_replicas: "0"}
- match: {template.mappings._doc.properties.field.type: "keyword"}
- match: {overlapping_v1_templates: {v1_template: ["t*", "t1*"]}}
17 changes: 11 additions & 6 deletions server/src/main/java/org/elasticsearch/action/ActionModule.java
Expand Up @@ -28,9 +28,6 @@
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction;
import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction;
import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction;
import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction;
Expand Down Expand Up @@ -108,6 +105,9 @@
import org.elasticsearch.action.admin.indices.close.TransportVerifyShardBeforeCloseAction;
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction;
import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction;
import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.flush.FlushAction;
Expand Down Expand Up @@ -158,6 +158,8 @@
import org.elasticsearch.action.admin.indices.template.get.TransportGetComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.get.TransportGetIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.template.get.TransportGetIndexTemplatesAction;
import org.elasticsearch.action.admin.indices.template.post.SimulateIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.post.TransportSimulateIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateV2Action;
Expand Down Expand Up @@ -260,11 +262,9 @@
import org.elasticsearch.rest.action.admin.cluster.RestClusterStatsAction;
import org.elasticsearch.rest.action.admin.cluster.RestClusterUpdateSettingsAction;
import org.elasticsearch.rest.action.admin.cluster.RestCreateSnapshotAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteDataStreamAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteRepositoryAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteSnapshotAction;
import org.elasticsearch.rest.action.admin.cluster.RestDeleteStoredScriptAction;
import org.elasticsearch.rest.action.admin.indices.RestGetDataStreamsAction;
import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction;
import org.elasticsearch.rest.action.admin.cluster.RestGetScriptContextAction;
import org.elasticsearch.rest.action.admin.cluster.RestGetScriptLanguageAction;
Expand All @@ -277,7 +277,6 @@
import org.elasticsearch.rest.action.admin.cluster.RestNodesStatsAction;
import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction;
import org.elasticsearch.rest.action.admin.cluster.RestPendingClusterTasksAction;
import org.elasticsearch.rest.action.admin.indices.RestCreateDataStreamAction;
import org.elasticsearch.rest.action.admin.cluster.RestPutRepositoryAction;
import org.elasticsearch.rest.action.admin.cluster.RestPutStoredScriptAction;
import org.elasticsearch.rest.action.admin.cluster.RestReloadSecureSettingsAction;
Expand All @@ -288,15 +287,18 @@
import org.elasticsearch.rest.action.admin.indices.RestAnalyzeAction;
import org.elasticsearch.rest.action.admin.indices.RestClearIndicesCacheAction;
import org.elasticsearch.rest.action.admin.indices.RestCloseIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestCreateDataStreamAction;
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteComponentTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteDataStreamAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteIndexTemplateV2Action;
import org.elasticsearch.rest.action.admin.indices.RestFlushAction;
import org.elasticsearch.rest.action.admin.indices.RestForceMergeAction;
import org.elasticsearch.rest.action.admin.indices.RestGetAliasesAction;
import org.elasticsearch.rest.action.admin.indices.RestGetComponentTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestGetDataStreamsAction;
import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction;
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateV2Action;
Expand All @@ -310,6 +312,7 @@
import org.elasticsearch.rest.action.admin.indices.RestIndicesShardStoresAction;
import org.elasticsearch.rest.action.admin.indices.RestIndicesStatsAction;
import org.elasticsearch.rest.action.admin.indices.RestOpenIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestSimulateIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestPutComponentTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateV2Action;
Expand Down Expand Up @@ -550,6 +553,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(PutIndexTemplateV2Action.INSTANCE, TransportPutIndexTemplateV2Action.class);
actions.register(GetIndexTemplateV2Action.INSTANCE, TransportGetIndexTemplateV2Action.class);
actions.register(DeleteIndexTemplateV2Action.INSTANCE, TransportDeleteIndexTemplateV2Action.class);
actions.register(SimulateIndexTemplateAction.INSTANCE, TransportSimulateIndexTemplateAction.class);
}
actions.register(ValidateQueryAction.INSTANCE, TransportValidateQueryAction.class);
actions.register(RefreshAction.INSTANCE, TransportRefreshAction.class);
Expand Down Expand Up @@ -700,6 +704,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestPutIndexTemplateV2Action());
registerHandler.accept(new RestGetIndexTemplateV2Action());
registerHandler.accept(new RestDeleteIndexTemplateV2Action());
registerHandler.accept(new RestSimulateIndexTemplateAction());
}

registerHandler.accept(new RestPutMappingAction());
Expand Down
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.indices.template.post;

import org.elasticsearch.action.ActionType;

public class SimulateIndexTemplateAction extends ActionType<SimulateIndexTemplateResponse> {

public static final SimulateIndexTemplateAction INSTANCE = new SimulateIndexTemplateAction();
public static final String NAME = "indices:admin/index_template/simulate_index/post";
andreidan marked this conversation as resolved.
Show resolved Hide resolved

private SimulateIndexTemplateAction() {
super(NAME, SimulateIndexTemplateResponse::new);
}

}