forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add REST API for ComponentTemplate CRUD (elastic#53558)
* Add REST API for ComponentTemplate CRUD This adds the Put/Get/DeleteComponentTemplate APIs that allow inserting, retrieving, and removing ComponentTemplateMetadata into the cluster state metadata. These APIs are currently only available behind a feature flag system property - `es.itv2_feature_flag_registered`. Relates to elastic#53101 Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
347b759
commit b506b05
Showing
23 changed files
with
1,454 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_component_template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"cluster.delete_component_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-templates.html", | ||
"description":"Deletes a component template" | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_component_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" | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_component_template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"cluster.get_component_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-templates.html", | ||
"description":"Returns one or more component templates" | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_component_template", | ||
"methods":[ | ||
"GET" | ||
] | ||
}, | ||
{ | ||
"path":"/_component_template/{name}", | ||
"methods":[ | ||
"GET" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"list", | ||
"description":"The comma separated names of the component templates" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"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)" | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_component_template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"cluster.put_component_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-templates.html", | ||
"description":"Creates or updates a component template" | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_component_template/{name}", | ||
"methods":[ | ||
"PUT", | ||
"POST" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"string", | ||
"description":"The name of the template" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"create":{ | ||
"type":"boolean", | ||
"description":"Whether the index template should only be added if new or can also replace an existing one", | ||
"default":false | ||
}, | ||
"timeout":{ | ||
"type":"time", | ||
"description":"Explicit operation timeout" | ||
}, | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Specify timeout for connection to master" | ||
} | ||
}, | ||
"body":{ | ||
"description":"The template definition", | ||
"required":true | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
rest-api-spec/src/main/resources/rest-api-spec/test/cluster.component_template/10_basic.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
"Basic CRUD": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: not backported yet | ||
|
||
- do: | ||
cluster.put_component_template: | ||
name: test | ||
body: | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
aliases: | ||
aliasname: {} | ||
version: 2 | ||
_meta: | ||
foo: bar | ||
baz: | ||
eggplant: true | ||
|
||
- do: | ||
cluster.get_component_template: | ||
name: test | ||
|
||
- match: {component_templates.0.name: test} | ||
- match: {component_templates.0.component_template.version: 2} | ||
- match: {component_templates.0.component_template._meta: {foo: bar, baz: {eggplant: true}}} | ||
- match: {component_templates.0.component_template.template.settings: {index: {number_of_shards: '1', number_of_replicas: '0'}}} | ||
- match: {component_templates.0.component_template.template.mappings: {properties: {field: {type: keyword}}}} | ||
- match: {component_templates.0.component_template.template.aliases: {aliasname: {}}} | ||
|
||
- do: | ||
cluster.delete_component_template: | ||
name: test | ||
|
||
- do: | ||
catch: missing | ||
cluster.get_component_template: | ||
name: test | ||
|
||
- is_false: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...org/elasticsearch/action/admin/indices/template/delete/DeleteComponentTemplateAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.delete; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
public class DeleteComponentTemplateAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final DeleteComponentTemplateAction INSTANCE = new DeleteComponentTemplateAction(); | ||
public static final String NAME = "cluster:admin/component_template/delete"; | ||
|
||
private DeleteComponentTemplateAction() { | ||
super(NAME, AcknowledgedResponse::new); | ||
} | ||
|
||
public static class Request extends MasterNodeRequest<Request> { | ||
|
||
private String name; | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
name = in.readString(); | ||
} | ||
|
||
public Request() { } | ||
|
||
/** | ||
* Constructs a new delete index request for the specified name. | ||
*/ | ||
public Request(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Set the index template name to delete. | ||
*/ | ||
public Request name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (name == null) { | ||
validationException = addValidationError("name is missing", validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
/** | ||
* The index template name to delete. | ||
*/ | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(name); | ||
} | ||
} | ||
} |
Oops, something went wrong.