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

HLRC support for Index Templates V2 #54838

Merged
merged 18 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7dc97a4
HLRC support for Index Templates V2
probakowski Apr 6, 2020
7f9dcbe
remove debug comment
probakowski Apr 6, 2020
38dd892
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
a1f765b
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
14443a1
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
4ab09b3
Update client/rest-high-level/src/test/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
812d06c
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
a3d0837
review comments
probakowski Apr 7, 2020
bfe9a4c
Merge branch 'master' into hlrc-index-templates-v2
elasticmachine Apr 7, 2020
7b26fb1
review comments
probakowski Apr 7, 2020
ec4fdf3
review comments
probakowski Apr 7, 2020
15ad1d2
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
8b562f9
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
8e4d6a5
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
1bcf1dc
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
d436459
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
b54f105
Update client/rest-high-level/src/main/java/org/elasticsearch/client/…
probakowski Apr 7, 2020
a157c5b
Merge branch 'master' into hlrc-index-templates-v2
elasticmachine Apr 7, 2020
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
Expand Up @@ -48,17 +48,22 @@
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.DeleteIndexTemplateV2Request;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
import org.elasticsearch.client.indices.GetIndexTemplatesV2Request;
import org.elasticsearch.client.indices.GetIndexTemplatesV2Response;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.GetMappingsResponse;
import org.elasticsearch.client.indices.IndexTemplateV2ExistRequest;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
import org.elasticsearch.client.indices.PutIndexTemplateV2Request;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.ReloadAnalyzersRequest;
import org.elasticsearch.client.indices.ReloadAnalyzersResponse;
Expand Down Expand Up @@ -909,6 +914,36 @@ public Cancellable putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequ
AcknowledgedResponse::fromXContent, listener, emptySet());
}

/**
* Puts an index template using the Index Templates API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @param putIndexTemplateRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public AcknowledgedResponse putIndexTemplate(PutIndexTemplateV2Request putIndexTemplateRequest, RequestOptions options)
throws IOException {
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putIndexTemplate,
options, AcknowledgedResponse::fromXContent, emptySet());
}

/**
* Asynchronously puts an index template using the Index Templates API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @param putIndexTemplateRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable putIndexTemplateAsync(PutIndexTemplateV2Request putIndexTemplateRequest,
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
probakowski marked this conversation as resolved.
Show resolved Hide resolved
return restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putIndexTemplate,
options, AcknowledgedResponse::fromXContent, listener, emptySet());
}

/**
* Validate a potentially expensive query without executing it.
* <p>
Expand Down Expand Up @@ -943,6 +978,36 @@ public Cancellable validateQueryAsync(ValidateQueryRequest validateQueryRequest,
ValidateQueryResponse::fromXContent, listener, emptySet());
}

/**
* Gets index templates using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param getIndexTemplatesRequest the request
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetIndexTemplatesV2Response getIndexTemplate(GetIndexTemplatesV2Request getIndexTemplatesRequest,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getIndexTemplates,
options, GetIndexTemplatesV2Response::fromXContent, emptySet());
}

/**
* Asynchronously gets index templates using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @param getIndexTemplatesRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable getIndexTemplateAsync(GetIndexTemplatesV2Request getIndexTemplatesRequest, RequestOptions options,
ActionListener<GetIndexTemplatesV2Response> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getIndexTemplates, options, GetIndexTemplatesV2Response::fromXContent, listener, emptySet());
}

/**
* Gets index templates using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
Expand All @@ -953,7 +1018,7 @@ public Cancellable validateQueryAsync(ValidateQueryRequest validateQueryRequest,
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest,
RequestOptions options) throws IOException {
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getTemplates,
options, GetIndexTemplatesResponse::fromXContent, emptySet());
Expand Down Expand Up @@ -1006,6 +1071,37 @@ public Cancellable existsTemplateAsync(IndexTemplatesExistRequest indexTemplates
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}

/**
* Uses the Index Templates API to determine if index templates exist
*
* @param indexTemplatesRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return true if any index templates in the request exist, false otherwise
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public boolean existsIndexTemplate(IndexTemplateV2ExistRequest indexTemplatesRequest,
RequestOptions options) throws IOException {
probakowski marked this conversation as resolved.
Show resolved Hide resolved
return restHighLevelClient.performRequest(indexTemplatesRequest,
IndicesRequestConverters::templatesExist, options,
RestHighLevelClient::convertExistsResponse, emptySet());
}

/**
* Uses the Index Templates API to determine if index templates exist
* @param indexTemplatesExistRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion. The listener will be called with the value {@code true}
* @return cancellable that may be used to cancel the request
*/
public Cancellable existsIndexTemplateAsync(IndexTemplateV2ExistRequest indexTemplatesExistRequest,
RequestOptions options,
ActionListener<Boolean> listener) {
probakowski marked this conversation as resolved.
Show resolved Hide resolved

return restHighLevelClient.performRequestAsync(indexTemplatesExistRequest,
IndicesRequestConverters::templatesExist, options,
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}

/**
* Calls the analyze API
*
Expand Down Expand Up @@ -1112,6 +1208,35 @@ public Cancellable deleteTemplateAsync(DeleteIndexTemplateRequest request, Reque
options, AcknowledgedResponse::fromXContent, listener, emptySet());
}

/**
* Delete an index template using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
*
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public AcknowledgedResponse deleteIndexTemplate(DeleteIndexTemplateV2Request request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::deleteIndexTemplate,
options, AcknowledgedResponse::fromXContent, emptySet());
}

/**
* Asynchronously delete an index template using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable deleteIndexTemplateAsync(DeleteIndexTemplateV2Request request, RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
probakowski marked this conversation as resolved.
Show resolved Hide resolved
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::deleteIndexTemplate,
options, AcknowledgedResponse::fromXContent, listener, emptySet());
}

/**
* Synchronously calls the _reload_search_analyzers API
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@
import org.elasticsearch.client.indices.CloseIndexRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.DeleteIndexTemplateV2Request;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesV2Request;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.IndexTemplateV2ExistRequest;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
import org.elasticsearch.client.indices.PutIndexTemplateV2Request;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.ReloadAnalyzersRequest;
import org.elasticsearch.client.indices.ResizeRequest;
Expand Down Expand Up @@ -403,6 +407,23 @@ static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) thro
return request;
}

static Request putIndexTemplate(PutIndexTemplateV2Request putIndexTemplateRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_index_template")
.addPathPart(putIndexTemplateRequest.name()).build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
if (putIndexTemplateRequest.create()) {
params.putParam("create", Boolean.TRUE.toString());
}
if (Strings.hasText(putIndexTemplateRequest.cause())) {
params.putParam("cause", putIndexTemplateRequest.cause());
}
request.addParameters(params.asMap());
request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
String endpoint = RequestConverters.endpoint(indices, "_validate/query");
Expand Down Expand Up @@ -442,6 +463,19 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
return request;
}

static Request getIndexTemplates(GetIndexTemplatesV2Request getIndexTemplatesRequest) {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_index_template")
.addPathPart(getIndexTemplatesRequest.name())
.build();
final Request request = new Request(HttpGet.METHOD_NAME, endpoint);
final RequestConverters.Params params = new RequestConverters.Params();
params.withLocal(getIndexTemplatesRequest.isLocal());
params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
request.addParameters(params.asMap());
return request;
}

static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequest) {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_template")
Expand All @@ -455,6 +489,19 @@ static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequ
return request;
}

static Request templatesExist(IndexTemplateV2ExistRequest indexTemplatesExistRequest) {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_index_template")
.addPathPart(indexTemplatesExistRequest.name())
.build();
final Request request = new Request(HttpHead.METHOD_NAME, endpoint);
final RequestConverters.Params params = new RequestConverters.Params();
params.withLocal(indexTemplatesExistRequest.isLocal());
params.withMasterTimeout(indexTemplatesExistRequest.getMasterNodeTimeout());
request.addParameters(params.asMap());
return request;
}

static Request analyze(AnalyzeRequest request) throws IOException {
RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder();
String index = request.index();
Expand Down Expand Up @@ -501,6 +548,16 @@ static Request deleteTemplate(DeleteIndexTemplateRequest deleteIndexTemplateRequ
return request;
}

static Request deleteIndexTemplate(DeleteIndexTemplateV2Request deleteIndexTemplateRequest) {
String name = deleteIndexTemplateRequest.getName();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_index_template").addPathPart(name).build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withMasterTimeout(deleteIndexTemplateRequest.masterNodeTimeout());
request.addParameters(params.asMap());
return request;
}

static Request reloadAnalyzers(ReloadAnalyzersRequest reloadAnalyzersRequest) {
String endpoint = RequestConverters.endpoint(reloadAnalyzersRequest.getIndices(), "_reload_search_analyzers");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.client.indices;

import org.elasticsearch.client.TimedRequest;

public class DeleteIndexTemplateV2Request extends TimedRequest {

private final String name;

public DeleteIndexTemplateV2Request(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.client.indices;

import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.unit.TimeValue;

/**
* A request to read the content of component templates
probakowski marked this conversation as resolved.
Show resolved Hide resolved
*/
public class GetIndexTemplatesV2Request implements Validatable {
probakowski marked this conversation as resolved.
Show resolved Hide resolved

private final String name;

private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private boolean local = false;

/**
* Create a request to read the content of component template. If no template name is provided, all templates will
probakowski marked this conversation as resolved.
Show resolved Hide resolved
* be read
*
* @param name the name of template to read
*/
public GetIndexTemplatesV2Request(String name) {
this.name = name;
}

/**
* @return the name of component template this request is requesting
probakowski marked this conversation as resolved.
Show resolved Hide resolved
*/
public String name() {
return name;
}

/**
* @return the timeout for waiting for the master node to respond
*/
public TimeValue getMasterNodeTimeout() {
return masterNodeTimeout;
}

public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout;
}

public void setMasterNodeTimeout(String masterNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
setMasterNodeTimeout(timeValue);
}

/**
* @return true if this request is to read from the local cluster state, rather than the master node - false otherwise
*/
public boolean isLocal() {
return local;
}

public void setLocal(boolean local) {
this.local = local;
}
}
Loading