From f2a90be7735c2842c857e113c605b6edc02cb13d Mon Sep 17 00:00:00 2001 From: Himanshu Setia <58999915+setiah@users.noreply.github.com> Date: Thu, 4 Feb 2021 19:28:33 -0800 Subject: [PATCH] Removing _reload_search_analyzers related changes since the related x-pack support is removed (#48) Signed-off-by: Peter Nied --- .../elasticsearch/client/IndicesClient.java | 26 ----- .../client/IndicesRequestConverters.java | 10 -- .../indices/ReloadAnalyzersRequest.java | 68 ----------- .../indices/ReloadAnalyzersResponse.java | 108 ------------------ .../elasticsearch/client/IndicesClientIT.java | 12 -- .../client/IndicesRequestConvertersTests.java | 18 --- .../IndicesClientDocumentationIT.java | 77 ------------- 7 files changed, 319 deletions(-) delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java index b1ee336d3df..ff3c9fe2801 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -72,8 +72,6 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutComposableIndexTemplateRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersResponse; import org.elasticsearch.client.indices.ResizeRequest; import org.elasticsearch.client.indices.ResizeResponse; import org.elasticsearch.client.indices.SimulateIndexTemplateRequest; @@ -1837,30 +1835,6 @@ public final class IndicesClient { options, AcknowledgedResponse::fromXContent, listener, emptySet()); } - /** - * Synchronously calls the _reload_search_analyzers API - * - * @param request the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - */ - public ReloadAnalyzersResponse reloadAnalyzers(ReloadAnalyzersRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::reloadAnalyzers, options, - ReloadAnalyzersResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously calls the _reload_search_analyzers API - * @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 reloadAnalyzersAsync(ReloadAnalyzersRequest request, RequestOptions options, - ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::reloadAnalyzers, options, - ReloadAnalyzersResponse::fromXContent, listener, emptySet()); - } - /** * Synchronously calls the delete alias api * @param request the request diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java index e8354f2f586..f054e799777 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java @@ -58,7 +58,6 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutComposableIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersRequest; import org.elasticsearch.client.indices.ResizeRequest; import org.elasticsearch.client.indices.SimulateIndexTemplateRequest; import org.elasticsearch.client.indices.UnfreezeIndexRequest; @@ -806,15 +805,6 @@ final class IndicesRequestConverters { return request; } - static Request reloadAnalyzers(ReloadAnalyzersRequest reloadAnalyzersRequest) { - String endpoint = RequestConverters.endpoint(reloadAnalyzersRequest.getIndices(), "_reload_search_analyzers"); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withIndicesOptions(reloadAnalyzersRequest.indicesOptions()); - request.addParameters(parameters.asMap()); - return request; - } - static Request deleteAlias(DeleteAliasRequest deleteAliasRequest) { String endpoint = new RequestConverters.EndpointBuilder() .addPathPart(deleteAliasRequest.getIndex()) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java deleted file mode 100644 index e815d91bbe8..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersRequest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.action.support.IndicesOptions; -import org.elasticsearch.client.Validatable; - -import java.util.Objects; - -/** - * Request for the _reload_search_analyzers API - */ -public final class ReloadAnalyzersRequest implements Validatable { - - private final String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); - - /** - * Creates a new reload analyzers request - * @param indices the index for which to reload analyzers - */ - public ReloadAnalyzersRequest(String... indices) { - this.indices = Objects.requireNonNull(indices); - } - - /** - * Returns the indices - */ - public String[] getIndices() { - return indices; - } - - /** - * Specifies what type of requested indices to ignore and how to deal with wildcard expressions. - * For example indices that don't exist. - * - * @return the current behaviour when it comes to index names and wildcard indices expressions - */ - public IndicesOptions indicesOptions() { - return indicesOptions; - } - - /** - * Specifies what type of requested indices to ignore and how to deal with wildcard expressions. - * For example indices that don't exist. - * - * @param indicesOptions the desired behaviour regarding indices to ignore and wildcard indices expressions - */ - public void setIndicesOptions(IndicesOptions indicesOptions) { - this.indicesOptions = indicesOptions; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java deleted file mode 100644 index e2c39d0a7ae..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/ReloadAnalyzersResponse.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.core.BroadcastResponse; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; - -/** - * The response object that will be returned when reloading analyzers - */ -public class ReloadAnalyzersResponse extends BroadcastResponse { - - private final Map reloadDetails; - - ReloadAnalyzersResponse(final Shards shards, Map reloadDetails) { - super(shards); - this.reloadDetails = reloadDetails; - } - - @SuppressWarnings({ "unchecked" }) - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("reload_analyzer", - true, arg -> { - Shards shards = (Shards) arg[0]; - List> results = (List>) arg[1]; - Map reloadDetails = new HashMap<>(); - for (Tuple result : results) { - reloadDetails.put(result.v1(), result.v2()); - } - return new ReloadAnalyzersResponse(shards, reloadDetails); - }); - - @SuppressWarnings({ "unchecked" }) - private static final ConstructingObjectParser, Void> ENTRY_PARSER = new ConstructingObjectParser<>( - "reload_analyzer.entry", true, arg -> { - String index = (String) arg[0]; - Set nodeIds = new HashSet<>((List) arg[1]); - Set analyzers = new HashSet<>((List) arg[2]); - return new Tuple<>(index, new ReloadDetails(index, nodeIds, analyzers)); - }); - - static { - declareShardsField(PARSER); - PARSER.declareObjectArray(constructorArg(), ENTRY_PARSER, new ParseField("reload_details")); - ENTRY_PARSER.declareString(constructorArg(), new ParseField("index")); - ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_node_ids")); - ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_analyzers")); - } - - public static ReloadAnalyzersResponse fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - public Map getReloadedDetails() { - return reloadDetails; - } - - public static class ReloadDetails { - - private final String indexName; - private final Set reloadedIndicesNodes; - private final Set reloadedAnalyzers; - - public ReloadDetails(String name, Set reloadedIndicesNodes, Set reloadedAnalyzers) { - this.indexName = name; - this.reloadedIndicesNodes = reloadedIndicesNodes; - this.reloadedAnalyzers = reloadedAnalyzers; - } - - public String getIndexName() { - return indexName; - } - - public Set getReloadedIndicesNodes() { - return reloadedIndicesNodes; - } - - public Set getReloadedAnalyzers() { - return reloadedAnalyzers; - } - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 7f9a599804a..7db2704728c 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -88,8 +88,6 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutComposableIndexTemplateRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersResponse; import org.elasticsearch.client.indices.SimulateIndexTemplateRequest; import org.elasticsearch.client.indices.SimulateIndexTemplateResponse; import org.elasticsearch.client.indices.UnfreezeIndexRequest; @@ -1996,16 +1994,6 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { assertTrue(unfreeze.isAcknowledged()); } - public void testReloadAnalyzer() throws IOException { - createIndex("test", Settings.EMPTY); - RestHighLevelClient client = highLevelClient(); - - ReloadAnalyzersResponse reloadResponse = execute(new ReloadAnalyzersRequest("test"), client.indices()::reloadAnalyzers, - client.indices()::reloadAnalyzersAsync); - assertNotNull(reloadResponse.shards()); - assertTrue(reloadResponse.getReloadedDetails().containsKey("test")); - } - public void testDeleteAlias() throws IOException { String index = "test"; createIndex(index, Settings.EMPTY); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java index 87074b7a879..9bed5062c02 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java @@ -57,7 +57,6 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.client.indices.RandomCreateIndexGenerator; -import org.elasticsearch.client.indices.ReloadAnalyzersRequest; import org.elasticsearch.client.indices.ResizeRequest; import org.elasticsearch.client.indices.rollover.RolloverRequest; import org.elasticsearch.common.CheckedFunction; @@ -1236,23 +1235,6 @@ public class IndicesRequestConvertersTests extends ESTestCase { Assert.assertThat(request.getEntity(), nullValue()); } - public void testReloadAnalyzers() { - String[] indices = RequestConvertersTests.randomIndicesNames(1, 5); - StringJoiner endpoint = new StringJoiner("/", "/", ""); - if (CollectionUtils.isEmpty(indices) == false) { - endpoint.add(String.join(",", indices)); - } - ReloadAnalyzersRequest reloadRequest = new ReloadAnalyzersRequest(indices); - Map expectedParams = new HashMap<>(); - RequestConvertersTests.setRandomIndicesOptions(reloadRequest::setIndicesOptions, reloadRequest::indicesOptions, - expectedParams); - Request request = IndicesRequestConverters.reloadAnalyzers(reloadRequest); - Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); - Assert.assertThat(request.getEndpoint(), equalTo(endpoint + "/_reload_search_analyzers")); - Assert.assertThat(request.getParameters(), equalTo(expectedParams)); - Assert.assertThat(request.getEntity(), nullValue()); - } - public void testDeleteAlias() { DeleteAliasRequest deleteAliasRequest = new DeleteAliasRequest(randomAlphaOfLength(4), randomAlphaOfLength(4)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index 4a3a636f190..de150b72721 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -57,7 +57,6 @@ import org.elasticsearch.client.GetAliasesResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.SyncedFlushResponse; -import org.elasticsearch.client.core.BroadcastResponse.Shards; import org.elasticsearch.client.core.ShardsAcknowledgedResponse; import org.elasticsearch.client.indices.AnalyzeRequest; import org.elasticsearch.client.indices.AnalyzeResponse; @@ -85,9 +84,6 @@ import org.elasticsearch.client.indices.PutComponentTemplateRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutComposableIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersRequest; -import org.elasticsearch.client.indices.ReloadAnalyzersResponse; -import org.elasticsearch.client.indices.ReloadAnalyzersResponse.ReloadDetails; import org.elasticsearch.client.indices.SimulateIndexTemplateRequest; import org.elasticsearch.client.indices.SimulateIndexTemplateResponse; import org.elasticsearch.client.indices.UnfreezeIndexRequest; @@ -3172,79 +3168,6 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase assertTrue(latch.await(30L, TimeUnit.SECONDS)); } - public void testReloadSearchAnalyzers() throws Exception { - RestHighLevelClient client = highLevelClient(); - { - CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT); - assertTrue(createIndexResponse.isAcknowledged()); - } - - { - // tag::reload-analyzers-request - ReloadAnalyzersRequest request = new ReloadAnalyzersRequest("index"); // <1> - // end::reload-analyzers-request - - // tag::reload-analyzers-request-indicesOptions - request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1> - // end::reload-analyzers-request-indicesOptions - - // tag::reload-analyzers-execute - ReloadAnalyzersResponse reloadResponse = client.indices().reloadAnalyzers(request, RequestOptions.DEFAULT); - // end::reload-analyzers-execute - - // tag::reload-analyzers-response - Shards shards = reloadResponse.shards(); // <1> - Map reloadDetails = reloadResponse.getReloadedDetails(); // <2> - ReloadDetails details = reloadDetails.get("index"); // <3> - String indexName = details.getIndexName(); // <4> - Set indicesNodes = details.getReloadedIndicesNodes(); // <5> - Set analyzers = details.getReloadedAnalyzers(); // <6> - // end::reload-analyzers-response - assertNotNull(shards); - assertEquals("index", indexName); - assertEquals(1, indicesNodes.size()); - assertEquals(0, analyzers.size()); - - // tag::reload-analyzers-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(ReloadAnalyzersResponse reloadResponse) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::reload-analyzers-execute-listener - - // Replace the empty listener by a blocking listener in test - final CountDownLatch latch = new CountDownLatch(1); - listener = new LatchedActionListener<>(listener, latch); - - // tag::reload-analyzers-execute-async - client.indices().reloadAnalyzersAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::reload-analyzers-execute-async - - assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } - - { - // tag::reload-analyzers-notfound - try { - ReloadAnalyzersRequest request = new ReloadAnalyzersRequest("does_not_exist"); - client.indices().reloadAnalyzers(request, RequestOptions.DEFAULT); - } catch (ElasticsearchException exception) { - if (exception.status() == RestStatus.BAD_REQUEST) { - // <1> - } - } - // end::reload-analyzers-notfound - } - } - @SuppressWarnings("unused") public void testDeleteAlias() throws Exception { RestHighLevelClient client = highLevelClient();