diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1f78910e9a..b8f4262ca5c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -209,6 +209,14 @@ Before submitting your changes, run the test suite to make sure that nothing is ./gradlew check ``` +If your changes affect only the documentation, run: + +```sh +./gradlew -p docs check +``` +For more information about testing code examples in the documentation, see +https://github.com/elastic/elasticsearch/blob/master/docs/README.asciidoc + ### Project layout This repository is split into many top level directories. The most important diff --git a/client/benchmark/src/main/java/org/elasticsearch/client/benchmark/transport/TransportClientBenchmark.java b/client/benchmark/src/main/java/org/elasticsearch/client/benchmark/transport/TransportClientBenchmark.java index d2aee2251a6..c9ab38fe355 100644 --- a/client/benchmark/src/main/java/org/elasticsearch/client/benchmark/transport/TransportClientBenchmark.java +++ b/client/benchmark/src/main/java/org/elasticsearch/client/benchmark/transport/TransportClientBenchmark.java @@ -79,7 +79,7 @@ public final class TransportClientBenchmark extends AbstractBenchmark bulkData) { - NoopBulkRequestBuilder builder = NoopBulkAction.INSTANCE.newRequestBuilder(client); + NoopBulkRequestBuilder builder = new NoopBulkRequestBuilder(client,NoopBulkAction.INSTANCE); for (String bulkItem : bulkData) { builder.add(new IndexRequest(indexName, typeName).source(bulkItem.getBytes(StandardCharsets.UTF_8), XContentType.JSON)); } @@ -108,7 +108,7 @@ public final class TransportClientBenchmark extends AbstractBenchmark { +public class NoopBulkAction extends Action { public static final String NAME = "mock:data/write/bulk"; public static final NoopBulkAction INSTANCE = new NoopBulkAction(); @@ -32,11 +31,6 @@ public class NoopBulkAction extends Action +public class NoopBulkRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public NoopBulkRequestBuilder(ElasticsearchClient client, NoopBulkAction action) { diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java index b24190b6946..ca2c3d9adfc 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java @@ -21,9 +21,8 @@ package org.elasticsearch.plugin.noop.action.search; import org.elasticsearch.action.Action; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.ElasticsearchClient; -public class NoopSearchAction extends Action { +public class NoopSearchAction extends Action { public static final NoopSearchAction INSTANCE = new NoopSearchAction(); public static final String NAME = "mock:data/read/search"; @@ -31,11 +30,6 @@ public class NoopSearchAction extends Action { +public class NoopSearchRequestBuilder extends ActionRequestBuilder { public NoopSearchRequestBuilder(ElasticsearchClient client, NoopSearchAction action) { super(client, action, new SearchRequest()); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ClusterClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ClusterClient.java index 846f29bfb6e..4254b132b57 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ClusterClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ClusterClient.java @@ -24,7 +24,10 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; import org.elasticsearch.action.ingest.PutPipelineRequest; -import org.elasticsearch.action.ingest.PutPipelineResponse; +import org.elasticsearch.action.ingest.GetPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineResponse; +import org.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.WritePipelineResponse; import java.io.IOException; @@ -72,9 +75,9 @@ public final class ClusterClient { * See * Put Pipeline API on elastic.co */ - public PutPipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException { + public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline, - PutPipelineResponse::fromXContent, emptySet(), headers); + WritePipelineResponse::fromXContent, emptySet(), headers); } /** @@ -83,8 +86,54 @@ public final class ClusterClient { * See * Put Pipeline API on elastic.co */ - public void putPipelineAsync(PutPipelineRequest request, ActionListener listener, Header... headers) { + public void putPipelineAsync(PutPipelineRequest request, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline, - PutPipelineResponse::fromXContent, listener, emptySet(), headers); + WritePipelineResponse::fromXContent, listener, emptySet(), headers); + } + + /** + * Get an existing pipeline + *

+ * See + * Get Pipeline API on elastic.co + */ + public GetPipelineResponse getPipeline(GetPipelineRequest request, Header... headers) throws IOException { + return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::getPipeline, + GetPipelineResponse::fromXContent, emptySet(), headers); + } + + /** + * Asynchronously get an existing pipeline + *

+ * See + * Get Pipeline API on elastic.co + */ + public void getPipelineAsync(GetPipelineRequest request, ActionListener listener, Header... headers) { + restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::getPipeline, + GetPipelineResponse::fromXContent, listener, emptySet(), headers); + } + + /** + * Delete an existing pipeline + *

+ * See + * + * Delete Pipeline API on elastic.co + */ + public WritePipelineResponse deletePipeline(DeletePipelineRequest request, Header... headers) throws IOException { + return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::deletePipeline, + WritePipelineResponse::fromXContent, emptySet(), headers); + } + + /** + * Asynchronously delete an existing pipeline + *

+ * See + * + * Delete Pipeline API on elastic.co + */ + public void deletePipelineAsync(DeletePipelineRequest request, ActionListener listener, Header... headers) { + restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline, + WritePipelineResponse::fromXContent, listener, emptySet(), headers); } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 435381774b0..6c8bb845259 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -60,7 +60,9 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.MultiGetRequest; import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.ingest.DeletePipelineRequest; import org.elasticsearch.action.ingest.PutPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineRequest; import org.elasticsearch.action.search.ClearScrollRequest; import org.elasticsearch.action.search.MultiSearchRequest; import org.elasticsearch.action.search.SearchRequest; @@ -620,6 +622,18 @@ final class RequestConverters { return request; } + static Request getPipeline(GetPipelineRequest getPipelineRequest) { + String endpoint = new EndpointBuilder() + .addPathPartAsIs("_ingest/pipeline") + .addCommaSeparatedPathParts(getPipelineRequest.getIds()) + .build(); + Request request = new Request(HttpGet.METHOD_NAME, endpoint); + + Params parameters = new Params(request); + parameters.withMasterTimeout(getPipelineRequest.masterNodeTimeout()); + return request; + } + static Request putPipeline(PutPipelineRequest putPipelineRequest) throws IOException { String endpoint = new EndpointBuilder() .addPathPartAsIs("_ingest/pipeline") @@ -635,6 +649,20 @@ final class RequestConverters { return request; } + static Request deletePipeline(DeletePipelineRequest deletePipelineRequest) { + String endpoint = new EndpointBuilder() + .addPathPartAsIs("_ingest/pipeline") + .addPathPart(deletePipelineRequest.getId()) + .build(); + Request request = new Request(HttpDelete.METHOD_NAME, endpoint); + + Params parameters = new Params(request); + parameters.withTimeout(deletePipelineRequest.timeout()); + parameters.withMasterTimeout(deletePipelineRequest.masterNodeTimeout()); + + return request; + } + static Request listTasks(ListTasksRequest listTaskRequest) { if (listTaskRequest.getTaskId() != null && listTaskRequest.getTaskId().isSet()) { throw new IllegalArgumentException("TaskId cannot be used for list tasks request"); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 8537bf3b450..fc74a43dd80 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -279,6 +279,17 @@ public class RestHighLevelClient implements Closeable { * * See Bulk API on elastic.co */ + public final BulkResponse bulk(BulkRequest bulkRequest, RequestOptions options) throws IOException { + return performRequestAndParseEntity(bulkRequest, RequestConverters::bulk, options, BulkResponse::fromXContent, emptySet()); + } + + /** + * Executes a bulk request using the Bulk API + * + * See Bulk API on elastic.co + * @deprecated Prefer {@link #bulk(BulkRequest, RequestOptions)} + */ + @Deprecated public final BulkResponse bulk(BulkRequest bulkRequest, Header... headers) throws IOException { return performRequestAndParseEntity(bulkRequest, RequestConverters::bulk, BulkResponse::fromXContent, emptySet(), headers); } @@ -288,6 +299,17 @@ public class RestHighLevelClient implements Closeable { * * See Bulk API on elastic.co */ + public final void bulkAsync(BulkRequest bulkRequest, RequestOptions options, ActionListener listener) { + performRequestAsyncAndParseEntity(bulkRequest, RequestConverters::bulk, options, BulkResponse::fromXContent, listener, emptySet()); + } + + /** + * Asynchronously executes a bulk request using the Bulk API + * + * See Bulk API on elastic.co + * @deprecated Prefer {@link #bulkAsync(BulkRequest, RequestOptions, ActionListener)} + */ + @Deprecated public final void bulkAsync(BulkRequest bulkRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(bulkRequest, RequestConverters::bulk, BulkResponse::fromXContent, listener, emptySet(), headers); } @@ -584,6 +606,7 @@ public class RestHighLevelClient implements Closeable { FieldCapabilitiesResponse::fromXContent, listener, emptySet(), headers); } + @Deprecated protected final Resp performRequestAndParseEntity(Req request, CheckedFunction requestConverter, CheckedFunction entityParser, @@ -591,16 +614,34 @@ public class RestHighLevelClient implements Closeable { return performRequest(request, requestConverter, (response) -> parseEntity(response.getEntity(), entityParser), ignores, headers); } + protected final Resp performRequestAndParseEntity(Req request, + CheckedFunction requestConverter, + RequestOptions options, + CheckedFunction entityParser, + Set ignores) throws IOException { + return performRequest(request, requestConverter, options, + response -> parseEntity(response.getEntity(), entityParser), ignores); + } + + @Deprecated protected final Resp performRequest(Req request, CheckedFunction requestConverter, CheckedFunction responseConverter, Set ignores, Header... headers) throws IOException { + return performRequest(request, requestConverter, optionsForHeaders(headers), responseConverter, ignores); + } + + protected final Resp performRequest(Req request, + CheckedFunction requestConverter, + RequestOptions options, + CheckedFunction responseConverter, + Set ignores) throws IOException { ActionRequestValidationException validationException = request.validate(); if (validationException != null) { throw validationException; } Request req = requestConverter.apply(request); - addHeaders(req, headers); + req.setOptions(options); Response response; try { response = client.performRequest(req); @@ -626,6 +667,7 @@ public class RestHighLevelClient implements Closeable { } } + @Deprecated protected final void performRequestAsyncAndParseEntity(Req request, CheckedFunction requestConverter, CheckedFunction entityParser, @@ -634,10 +676,28 @@ public class RestHighLevelClient implements Closeable { listener, ignores, headers); } + protected final void performRequestAsyncAndParseEntity(Req request, + CheckedFunction requestConverter, + RequestOptions options, + CheckedFunction entityParser, + ActionListener listener, Set ignores) { + performRequestAsync(request, requestConverter, options, + response -> parseEntity(response.getEntity(), entityParser), listener, ignores); + } + + @Deprecated protected final void performRequestAsync(Req request, CheckedFunction requestConverter, CheckedFunction responseConverter, ActionListener listener, Set ignores, Header... headers) { + performRequestAsync(request, requestConverter, optionsForHeaders(headers), responseConverter, listener, ignores); + } + + protected final void performRequestAsync(Req request, + CheckedFunction requestConverter, + RequestOptions options, + CheckedFunction responseConverter, + ActionListener listener, Set ignores) { ActionRequestValidationException validationException = request.validate(); if (validationException != null) { listener.onFailure(validationException); @@ -650,19 +710,12 @@ public class RestHighLevelClient implements Closeable { listener.onFailure(e); return; } - addHeaders(req, headers); + req.setOptions(options); ResponseListener responseListener = wrapResponseListener(responseConverter, listener, ignores); client.performRequestAsync(req, responseListener); } - private static void addHeaders(Request request, Header... headers) { - Objects.requireNonNull(headers, "headers cannot be null"); - for (Header header : headers) { - request.addHeader(header.getName(), header.getValue()); - } - } - final ResponseListener wrapResponseListener(CheckedFunction responseConverter, ActionListener actionListener, Set ignores) { return new ResponseListener() { @@ -746,6 +799,15 @@ public class RestHighLevelClient implements Closeable { } } + private static RequestOptions optionsForHeaders(Header[] headers) { + RequestOptions.Builder options = RequestOptions.DEFAULT.toBuilder(); + for (Header header : headers) { + Objects.requireNonNull(header, "header cannot be null"); + options.addHeader(header.getName(), header.getValue()); + } + return options.build(); + } + static boolean convertExistsResponse(Response response) { return response.getStatusLine().getStatusCode() == 200; } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java index 44332b058bc..42db51e81b7 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java @@ -22,8 +22,11 @@ package org.elasticsearch.client; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.ingest.GetPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineResponse; import org.elasticsearch.action.ingest.PutPipelineRequest; -import org.elasticsearch.action.ingest.PutPipelineResponse; +import org.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.WritePipelineResponse; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -32,7 +35,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.indices.recovery.RecoverySettings; -import org.elasticsearch.ingest.Pipeline; +import org.elasticsearch.ingest.PipelineConfiguration; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -113,38 +116,50 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase { public void testPutPipeline() throws IOException { String id = "some_pipeline_id"; - XContentType xContentType = randomFrom(XContentType.values()); - XContentBuilder pipelineBuilder = XContentBuilder.builder(xContentType.xContent()); - pipelineBuilder.startObject(); - { - pipelineBuilder.field(Pipeline.DESCRIPTION_KEY, "some random set of processors"); - pipelineBuilder.startArray(Pipeline.PROCESSORS_KEY); - { - pipelineBuilder.startObject().startObject("set"); - { - pipelineBuilder - .field("field", "foo") - .field("value", "bar"); - } - pipelineBuilder.endObject().endObject(); - pipelineBuilder.startObject().startObject("convert"); - { - pipelineBuilder - .field("field", "rank") - .field("type", "integer"); - } - pipelineBuilder.endObject().endObject(); - } - pipelineBuilder.endArray(); - } - pipelineBuilder.endObject(); + XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); PutPipelineRequest request = new PutPipelineRequest( id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType()); - PutPipelineResponse putPipelineResponse = + WritePipelineResponse putPipelineResponse = execute(request, highLevelClient().cluster()::putPipeline, highLevelClient().cluster()::putPipelineAsync); assertTrue(putPipelineResponse.isAcknowledged()); } + + public void testGetPipeline() throws IOException { + String id = "some_pipeline_id"; + XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); + { + PutPipelineRequest request = new PutPipelineRequest( + id, + BytesReference.bytes(pipelineBuilder), + pipelineBuilder.contentType() + ); + createPipeline(request); + } + + GetPipelineRequest request = new GetPipelineRequest(id); + + GetPipelineResponse response = + execute(request, highLevelClient().cluster()::getPipeline, highLevelClient().cluster()::getPipelineAsync); + assertTrue(response.isFound()); + assertEquals(response.pipelines().get(0).getId(), id); + PipelineConfiguration expectedConfig = + new PipelineConfiguration(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType()); + assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap()); + } + + public void testDeletePipeline() throws IOException { + String id = "some_pipeline_id"; + { + createPipeline(id); + } + + DeletePipelineRequest request = new DeletePipelineRequest(id); + + WritePipelineResponse response = + execute(request, highLevelClient().cluster()::deletePipeline, highLevelClient().cluster()::deletePipelineAsync); + assertTrue(response.isAcknowledged()); + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java index 0bd6ecef8fb..3d1db23da16 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java @@ -26,7 +26,6 @@ import org.apache.http.RequestLine; import org.apache.http.client.methods.HttpGet; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; -import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicRequestLine; import org.apache.http.message.BasicStatusLine; import org.apache.lucene.util.BytesRef; @@ -48,11 +47,13 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collections; -import java.util.List; +import java.util.Set; +import java.util.TreeSet; import java.util.stream.Collectors; import static java.util.Collections.emptySet; -import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -73,12 +74,12 @@ public class CustomRestHighLevelClientTests extends ESTestCase { final RestClient restClient = mock(RestClient.class); restHighLevelClient = new CustomRestClient(restClient); - doAnswer(inv -> mockPerformRequest(((Request) inv.getArguments()[0]).getHeaders().iterator().next())) + doAnswer(inv -> mockPerformRequest((Request) inv.getArguments()[0])) .when(restClient) .performRequest(any(Request.class)); doAnswer(inv -> mockPerformRequestAsync( - ((Request) inv.getArguments()[0]).getHeaders().iterator().next(), + ((Request) inv.getArguments()[0]), (ResponseListener) inv.getArguments()[1])) .when(restClient) .performRequestAsync(any(Request.class), any(ResponseListener.class)); @@ -87,26 +88,32 @@ public class CustomRestHighLevelClientTests extends ESTestCase { public void testCustomEndpoint() throws IOException { final MainRequest request = new MainRequest(); - final Header header = new BasicHeader("node_name", randomAlphaOfLengthBetween(1, 10)); + String nodeName = randomAlphaOfLengthBetween(1, 10); - MainResponse response = restHighLevelClient.custom(request, header); - assertEquals(header.getValue(), response.getNodeName()); + MainResponse response = restHighLevelClient.custom(request, optionsForNodeName(nodeName)); + assertEquals(nodeName, response.getNodeName()); - response = restHighLevelClient.customAndParse(request, header); - assertEquals(header.getValue(), response.getNodeName()); + response = restHighLevelClient.customAndParse(request, optionsForNodeName(nodeName)); + assertEquals(nodeName, response.getNodeName()); } public void testCustomEndpointAsync() throws Exception { final MainRequest request = new MainRequest(); - final Header header = new BasicHeader("node_name", randomAlphaOfLengthBetween(1, 10)); + String nodeName = randomAlphaOfLengthBetween(1, 10); PlainActionFuture future = PlainActionFuture.newFuture(); - restHighLevelClient.customAsync(request, future, header); - assertEquals(header.getValue(), future.get().getNodeName()); + restHighLevelClient.customAsync(request, optionsForNodeName(nodeName), future); + assertEquals(nodeName, future.get().getNodeName()); future = PlainActionFuture.newFuture(); - restHighLevelClient.customAndParseAsync(request, future, header); - assertEquals(header.getValue(), future.get().getNodeName()); + restHighLevelClient.customAndParseAsync(request, optionsForNodeName(nodeName), future); + assertEquals(nodeName, future.get().getNodeName()); + } + + private static RequestOptions optionsForNodeName(String nodeName) { + RequestOptions.Builder options = RequestOptions.DEFAULT.toBuilder(); + options.addHeader("node_name", nodeName); + return options.build(); } /** @@ -115,27 +122,27 @@ public class CustomRestHighLevelClientTests extends ESTestCase { */ @SuppressForbidden(reason = "We're forced to uses Class#getDeclaredMethods() here because this test checks protected methods") public void testMethodsVisibility() throws ClassNotFoundException { - final String[] methodNames = new String[]{"performRequest", - "performRequestAsync", + final String[] methodNames = new String[]{"parseEntity", + "parseResponseException", + "performRequest", "performRequestAndParseEntity", - "performRequestAsyncAndParseEntity", - "parseEntity", - "parseResponseException"}; + "performRequestAsync", + "performRequestAsyncAndParseEntity"}; - final List protectedMethods = Arrays.stream(RestHighLevelClient.class.getDeclaredMethods()) + final Set protectedMethods = Arrays.stream(RestHighLevelClient.class.getDeclaredMethods()) .filter(method -> Modifier.isProtected(method.getModifiers())) .map(Method::getName) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(TreeSet::new)); - assertThat(protectedMethods, containsInAnyOrder(methodNames)); + assertThat(protectedMethods, contains(methodNames)); } /** - * Mocks the asynchronous request execution by calling the {@link #mockPerformRequest(Header)} method. + * Mocks the asynchronous request execution by calling the {@link #mockPerformRequest(Request)} method. */ - private Void mockPerformRequestAsync(Header httpHeader, ResponseListener responseListener) { + private Void mockPerformRequestAsync(Request request, ResponseListener responseListener) { try { - responseListener.onSuccess(mockPerformRequest(httpHeader)); + responseListener.onSuccess(mockPerformRequest(request)); } catch (IOException e) { responseListener.onFailure(e); } @@ -145,7 +152,9 @@ public class CustomRestHighLevelClientTests extends ESTestCase { /** * Mocks the synchronous request execution like if it was executed by Elasticsearch. */ - private Response mockPerformRequest(Header httpHeader) throws IOException { + private Response mockPerformRequest(Request request) throws IOException { + assertThat(request.getOptions().getHeaders(), hasSize(1)); + Header httpHeader = request.getOptions().getHeaders().get(0); final Response mockResponse = mock(Response.class); when(mockResponse.getHost()).thenReturn(new HttpHost("localhost", 9200)); @@ -171,20 +180,20 @@ public class CustomRestHighLevelClientTests extends ESTestCase { super(restClient, RestClient::close, Collections.emptyList()); } - MainResponse custom(MainRequest mainRequest, Header... headers) throws IOException { - return performRequest(mainRequest, this::toRequest, this::toResponse, emptySet(), headers); + MainResponse custom(MainRequest mainRequest, RequestOptions options) throws IOException { + return performRequest(mainRequest, this::toRequest, options, this::toResponse, emptySet()); } - MainResponse customAndParse(MainRequest mainRequest, Header... headers) throws IOException { - return performRequestAndParseEntity(mainRequest, this::toRequest, MainResponse::fromXContent, emptySet(), headers); + MainResponse customAndParse(MainRequest mainRequest, RequestOptions options) throws IOException { + return performRequestAndParseEntity(mainRequest, this::toRequest, options, MainResponse::fromXContent, emptySet()); } - void customAsync(MainRequest mainRequest, ActionListener listener, Header... headers) { - performRequestAsync(mainRequest, this::toRequest, this::toResponse, listener, emptySet(), headers); + void customAsync(MainRequest mainRequest, RequestOptions options, ActionListener listener) { + performRequestAsync(mainRequest, this::toRequest, options, this::toResponse, listener, emptySet()); } - void customAndParseAsync(MainRequest mainRequest, ActionListener listener, Header... headers) { - performRequestAsyncAndParseEntity(mainRequest, this::toRequest, MainResponse::fromXContent, listener, emptySet(), headers); + void customAndParseAsync(MainRequest mainRequest, RequestOptions options, ActionListener listener) { + performRequestAsyncAndParseEntity(mainRequest, this::toRequest, options, MainResponse::fromXContent, listener, emptySet()); } Request toRequest(MainRequest mainRequest) throws IOException { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java index aabe2c4d1e2..f7a934405c2 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java @@ -21,7 +21,12 @@ package org.elasticsearch.client; import org.apache.http.Header; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ingest.PutPipelineRequest; import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.ingest.Pipeline; import org.elasticsearch.test.rest.ESRestTestCase; import org.junit.AfterClass; import org.junit.Before; @@ -80,4 +85,42 @@ public abstract class ESRestHighLevelClientTestCase extends ESRestTestCase { super(restClient, (client) -> {}, Collections.emptyList()); } } + + protected static XContentBuilder buildRandomXContentPipeline() throws IOException { + XContentType xContentType = randomFrom(XContentType.values()); + XContentBuilder pipelineBuilder = XContentBuilder.builder(xContentType.xContent()); + pipelineBuilder.startObject(); + { + pipelineBuilder.field(Pipeline.DESCRIPTION_KEY, "some random set of processors"); + pipelineBuilder.startArray(Pipeline.PROCESSORS_KEY); + { + pipelineBuilder.startObject().startObject("set"); + { + pipelineBuilder + .field("field", "foo") + .field("value", "bar"); + } + pipelineBuilder.endObject().endObject(); + pipelineBuilder.startObject().startObject("convert"); + { + pipelineBuilder + .field("field", "rank") + .field("type", "integer"); + } + pipelineBuilder.endObject().endObject(); + } + pipelineBuilder.endArray(); + } + pipelineBuilder.endObject(); + return pipelineBuilder; + } + + protected static void createPipeline(String pipelineId) throws IOException { + XContentBuilder builder = buildRandomXContentPipeline(); + createPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(builder), builder.contentType())); + } + + protected static void createPipeline(PutPipelineRequest putPipelineRequest) throws IOException { + assertOK(client().performRequest(RequestConverters.putPipeline(putPipelineRequest))); + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 5388b5ba82e..f61d79b8d42 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -63,6 +63,8 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.MultiGetRequest; import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineRequest; import org.elasticsearch.action.ingest.PutPipelineRequest; import org.elasticsearch.action.search.ClearScrollRequest; import org.elasticsearch.action.search.MultiSearchRequest; @@ -1450,6 +1452,35 @@ public class RequestConvertersTests extends ESTestCase { assertEquals(expectedParams, expectedRequest.getParameters()); } + public void testGetPipeline() { + String pipelineId = "some_pipeline_id"; + Map expectedParams = new HashMap<>(); + GetPipelineRequest request = new GetPipelineRequest("some_pipeline_id"); + setRandomMasterTimeout(request, expectedParams); + Request expectedRequest = RequestConverters.getPipeline(request); + StringJoiner endpoint = new StringJoiner("/", "/", ""); + endpoint.add("_ingest/pipeline"); + endpoint.add(pipelineId); + assertEquals(endpoint.toString(), expectedRequest.getEndpoint()); + assertEquals(HttpGet.METHOD_NAME, expectedRequest.getMethod()); + assertEquals(expectedParams, expectedRequest.getParameters()); + } + + public void testDeletePipeline() { + String pipelineId = "some_pipeline_id"; + Map expectedParams = new HashMap<>(); + DeletePipelineRequest request = new DeletePipelineRequest(pipelineId); + setRandomMasterTimeout(request, expectedParams); + setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); + Request expectedRequest = RequestConverters.deletePipeline(request); + StringJoiner endpoint = new StringJoiner("/", "/", ""); + endpoint.add("_ingest/pipeline"); + endpoint.add(pipelineId); + assertEquals(endpoint.toString(), expectedRequest.getEndpoint()); + assertEquals(HttpDelete.METHOD_NAME, expectedRequest.getMethod()); + assertEquals(expectedParams, expectedRequest.getParameters()); + } + public void testRollover() throws IOException { RolloverRequest rolloverRequest = new RolloverRequest(randomAlphaOfLengthBetween(3, 10), randomBoolean() ? null : randomAlphaOfLengthBetween(3, 10)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java index 29bb2d05afc..0da577f17e8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java @@ -23,8 +23,11 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.LatchedActionListener; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.ingest.GetPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineResponse; import org.elasticsearch.action.ingest.PutPipelineRequest; -import org.elasticsearch.action.ingest.PutPipelineResponse; +import org.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.WritePipelineResponse; import org.elasticsearch.client.ESRestHighLevelClientTestCase; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; @@ -34,11 +37,13 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.indices.recovery.RecoverySettings; +import org.elasticsearch.ingest.PipelineConfiguration; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -208,7 +213,7 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase // end::put-pipeline-request-masterTimeout // tag::put-pipeline-execute - PutPipelineResponse response = client.cluster().putPipeline(request); // <1> + WritePipelineResponse response = client.cluster().putPipeline(request); // <1> // end::put-pipeline-execute // tag::put-pipeline-response @@ -232,10 +237,10 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase ); // tag::put-pipeline-execute-listener - ActionListener listener = - new ActionListener() { + ActionListener listener = + new ActionListener() { @Override - public void onResponse(PutPipelineResponse response) { + public void onResponse(WritePipelineResponse response) { // <1> } @@ -257,4 +262,144 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase assertTrue(latch.await(30L, TimeUnit.SECONDS)); } } + + public void testGetPipeline() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + createPipeline("my-pipeline-id"); + } + + { + // tag::get-pipeline-request + GetPipelineRequest request = new GetPipelineRequest("my-pipeline-id"); // <1> + // end::get-pipeline-request + + // tag::get-pipeline-request-masterTimeout + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> + request.masterNodeTimeout("1m"); // <2> + // end::get-pipeline-request-masterTimeout + + // tag::get-pipeline-execute + GetPipelineResponse response = client.cluster().getPipeline(request); // <1> + // end::get-pipeline-execute + + // tag::get-pipeline-response + boolean successful = response.isFound(); // <1> + List pipelines = response.pipelines(); // <2> + for(PipelineConfiguration pipeline: pipelines) { + Map config = pipeline.getConfigAsMap(); // <3> + } + // end::get-pipeline-response + + assertTrue(successful); + } + } + + public void testGetPipelineAsync() throws Exception { + RestHighLevelClient client = highLevelClient(); + + { + createPipeline("my-pipeline-id"); + } + + { + GetPipelineRequest request = new GetPipelineRequest("my-pipeline-id"); + + // tag::get-pipeline-execute-listener + ActionListener listener = + new ActionListener() { + @Override + public void onResponse(GetPipelineResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::get-pipeline-execute-listener + + // Replace the empty listener by a blocking listener in test + final CountDownLatch latch = new CountDownLatch(1); + listener = new LatchedActionListener<>(listener, latch); + + // tag::get-pipeline-execute-async + client.cluster().getPipelineAsync(request, listener); // <1> + // end::get-pipeline-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + } + + public void testDeletePipeline() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + createPipeline("my-pipeline-id"); + } + + { + // tag::delete-pipeline-request + DeletePipelineRequest request = new DeletePipelineRequest("my-pipeline-id"); // <1> + // end::delete-pipeline-request + + // tag::delete-pipeline-request-timeout + request.timeout(TimeValue.timeValueMinutes(2)); // <1> + request.timeout("2m"); // <2> + // end::delete-pipeline-request-timeout + + // tag::delete-pipeline-request-masterTimeout + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> + request.masterNodeTimeout("1m"); // <2> + // end::delete-pipeline-request-masterTimeout + + // tag::delete-pipeline-execute + WritePipelineResponse response = client.cluster().deletePipeline(request); // <1> + // end::delete-pipeline-execute + + // tag::delete-pipeline-response + boolean acknowledged = response.isAcknowledged(); // <1> + // end::delete-pipeline-response + assertTrue(acknowledged); + } + } + + public void testDeletePipelineAsync() throws Exception { + RestHighLevelClient client = highLevelClient(); + + { + createPipeline("my-pipeline-id"); + } + + { + DeletePipelineRequest request = new DeletePipelineRequest("my-pipeline-id"); + + // tag::delete-pipeline-execute-listener + ActionListener listener = + new ActionListener() { + @Override + public void onResponse(WritePipelineResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::delete-pipeline-execute-listener + + // Replace the empty listener by a blocking listener in test + final CountDownLatch latch = new CountDownLatch(1); + listener = new LatchedActionListener<>(listener, latch); + + // tag::delete-pipeline-execute-async + client.cluster().deletePipelineAsync(request, listener); // <1> + // end::delete-pipeline-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + } } diff --git a/client/rest/src/main/java/org/elasticsearch/client/Request.java b/client/rest/src/main/java/org/elasticsearch/client/Request.java index 59b82e5bf96..a6febe91ae8 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/Request.java +++ b/client/rest/src/main/java/org/elasticsearch/client/Request.java @@ -19,17 +19,11 @@ package org.elasticsearch.client; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; -import org.apache.http.message.BasicHeader; import org.apache.http.nio.entity.NStringEntity; -import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; @@ -42,11 +36,9 @@ public final class Request { private final String method; private final String endpoint; private final Map parameters = new HashMap<>(); - private final List

headers = new ArrayList<>(); private HttpEntity entity; - private HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory = - HttpAsyncResponseConsumerFactory.DEFAULT; + private RequestOptions options = RequestOptions.DEFAULT; /** * Create the {@linkplain Request}. @@ -127,40 +119,29 @@ public final class Request { } /** - * Add the provided header to the request. + * Set the portion of an HTTP request to Elasticsearch that can be + * manipulated without changing Elasticsearch's behavior. */ - public void addHeader(String name, String value) { - Objects.requireNonNull(name, "header name cannot be null"); - Objects.requireNonNull(value, "header value cannot be null"); - this.headers.add(new ReqHeader(name, value)); + public void setOptions(RequestOptions options) { + Objects.requireNonNull(options, "options cannot be null"); + this.options = options; } /** - * Headers to attach to the request. + * Set the portion of an HTTP request to Elasticsearch that can be + * manipulated without changing Elasticsearch's behavior. */ - List
getHeaders() { - return Collections.unmodifiableList(headers); + public void setOptions(RequestOptions.Builder options) { + Objects.requireNonNull(options, "options cannot be null"); + this.options = options.build(); } /** - * set the {@link HttpAsyncResponseConsumerFactory} used to create one - * {@link HttpAsyncResponseConsumer} callback per retry. Controls how the - * response body gets streamed from a non-blocking HTTP connection on the - * client side. + * Get the portion of an HTTP request to Elasticsearch that can be + * manipulated without changing Elasticsearch's behavior. */ - public void setHttpAsyncResponseConsumerFactory(HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory) { - this.httpAsyncResponseConsumerFactory = - Objects.requireNonNull(httpAsyncResponseConsumerFactory, "httpAsyncResponseConsumerFactory cannot be null"); - } - - /** - * The {@link HttpAsyncResponseConsumerFactory} used to create one - * {@link HttpAsyncResponseConsumer} callback per retry. Controls how the - * response body gets streamed from a non-blocking HTTP connection on the - * client side. - */ - public HttpAsyncResponseConsumerFactory getHttpAsyncResponseConsumerFactory() { - return httpAsyncResponseConsumerFactory; + public RequestOptions getOptions() { + return options; } @Override @@ -175,18 +156,7 @@ public final class Request { if (entity != null) { b.append(", entity=").append(entity); } - if (headers.size() > 0) { - b.append(", headers="); - for (int h = 0; h < headers.size(); h++) { - if (h != 0) { - b.append(','); - } - b.append(headers.get(h).toString()); - } - } - if (httpAsyncResponseConsumerFactory != HttpAsyncResponseConsumerFactory.DEFAULT) { - b.append(", consumerFactory=").append(httpAsyncResponseConsumerFactory); - } + b.append(", options=").append(options); return b.append('}').toString(); } @@ -204,40 +174,11 @@ public final class Request { && endpoint.equals(other.endpoint) && parameters.equals(other.parameters) && Objects.equals(entity, other.entity) - && headers.equals(other.headers) - && httpAsyncResponseConsumerFactory.equals(other.httpAsyncResponseConsumerFactory); + && options.equals(other.options); } @Override public int hashCode() { - return Objects.hash(method, endpoint, parameters, entity, headers.hashCode(), httpAsyncResponseConsumerFactory); - } - - /** - * Custom implementation of {@link BasicHeader} that overrides equals and hashCode. - */ - static final class ReqHeader extends BasicHeader { - - ReqHeader(String name, String value) { - super(name, value); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (other instanceof ReqHeader) { - Header otherHeader = (Header) other; - return Objects.equals(getName(), otherHeader.getName()) && - Objects.equals(getValue(), otherHeader.getValue()); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(getName(), getValue()); - } + return Objects.hash(method, endpoint, parameters, entity, options); } } diff --git a/client/rest/src/main/java/org/elasticsearch/client/RequestOptions.java b/client/rest/src/main/java/org/elasticsearch/client/RequestOptions.java new file mode 100644 index 00000000000..e31db17a336 --- /dev/null +++ b/client/rest/src/main/java/org/elasticsearch/client/RequestOptions.java @@ -0,0 +1,175 @@ +/* + * 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; + +import org.apache.http.message.BasicHeader; +import org.apache.http.Header; +import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; +import org.elasticsearch.client.HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + + +import java.util.ArrayList; + +/** + * The portion of an HTTP request to Elasticsearch that can be + * manipulated without changing Elasticsearch's behavior. + */ +public final class RequestOptions { + public static final RequestOptions DEFAULT = new Builder( + Collections.
emptyList(), HeapBufferedResponseConsumerFactory.DEFAULT).build(); + + private final List
headers; + private final HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory; + + private RequestOptions(Builder builder) { + this.headers = Collections.unmodifiableList(new ArrayList<>(builder.headers)); + this.httpAsyncResponseConsumerFactory = builder.httpAsyncResponseConsumerFactory; + } + + public Builder toBuilder() { + Builder builder = new Builder(headers, httpAsyncResponseConsumerFactory); + return builder; + } + + /** + * Headers to attach to the request. + */ + public List
getHeaders() { + return headers; + } + + /** + * The {@link HttpAsyncResponseConsumerFactory} used to create one + * {@link HttpAsyncResponseConsumer} callback per retry. Controls how the + * response body gets streamed from a non-blocking HTTP connection on the + * client side. + */ + public HttpAsyncResponseConsumerFactory getHttpAsyncResponseConsumerFactory() { + return httpAsyncResponseConsumerFactory; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("RequestOptions{"); + if (headers.size() > 0) { + b.append(", headers="); + for (int h = 0; h < headers.size(); h++) { + if (h != 0) { + b.append(','); + } + b.append(headers.get(h).toString()); + } + } + if (httpAsyncResponseConsumerFactory != HttpAsyncResponseConsumerFactory.DEFAULT) { + b.append(", consumerFactory=").append(httpAsyncResponseConsumerFactory); + } + return b.append('}').toString(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null || (obj.getClass() != getClass())) { + return false; + } + if (obj == this) { + return true; + } + + RequestOptions other = (RequestOptions) obj; + return headers.equals(other.headers) + && httpAsyncResponseConsumerFactory.equals(other.httpAsyncResponseConsumerFactory); + } + + @Override + public int hashCode() { + return Objects.hash(headers, httpAsyncResponseConsumerFactory); + } + + public static class Builder { + private final List
headers; + private HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory; + + private Builder(List
headers, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory) { + this.headers = new ArrayList<>(headers); + this.httpAsyncResponseConsumerFactory = httpAsyncResponseConsumerFactory; + } + + /** + * Build the {@linkplain RequestOptions}. + */ + public RequestOptions build() { + return new RequestOptions(this); + } + + /** + * Add the provided header to the request. + */ + public void addHeader(String name, String value) { + Objects.requireNonNull(name, "header name cannot be null"); + Objects.requireNonNull(value, "header value cannot be null"); + this.headers.add(new ReqHeader(name, value)); + } + + /** + * set the {@link HttpAsyncResponseConsumerFactory} used to create one + * {@link HttpAsyncResponseConsumer} callback per retry. Controls how the + * response body gets streamed from a non-blocking HTTP connection on the + * client side. + */ + public void setHttpAsyncResponseConsumerFactory(HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory) { + this.httpAsyncResponseConsumerFactory = + Objects.requireNonNull(httpAsyncResponseConsumerFactory, "httpAsyncResponseConsumerFactory cannot be null"); + } + } + + /** + * Custom implementation of {@link BasicHeader} that overrides equals and + * hashCode so it is easier to test equality of {@link RequestOptions}. + */ + static final class ReqHeader extends BasicHeader { + + ReqHeader(String name, String value) { + super(name, value); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other instanceof ReqHeader) { + Header otherHeader = (Header) other; + return Objects.equals(getName(), otherHeader.getName()) && + Objects.equals(getValue(), otherHeader.getValue()); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(getName(), getValue()); + } + } +} diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java index 2256274f01a..0e603c4069a 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java @@ -312,8 +312,7 @@ public class RestClient implements Closeable { Request request = new Request(method, endpoint); addParameters(request, params); request.setEntity(entity); - request.setHttpAsyncResponseConsumerFactory(httpAsyncResponseConsumerFactory); - addHeaders(request, headers); + setOptions(request, httpAsyncResponseConsumerFactory, headers); return performRequest(request); } @@ -427,8 +426,7 @@ public class RestClient implements Closeable { request = new Request(method, endpoint); addParameters(request, params); request.setEntity(entity); - request.setHttpAsyncResponseConsumerFactory(httpAsyncResponseConsumerFactory); - addHeaders(request, headers); + setOptions(request, httpAsyncResponseConsumerFactory, headers); } catch (Exception e) { responseListener.onFailure(e); return; @@ -465,11 +463,11 @@ public class RestClient implements Closeable { } URI uri = buildUri(pathPrefix, request.getEndpoint(), requestParams); HttpRequestBase httpRequest = createHttpRequest(request.getMethod(), uri, request.getEntity()); - setHeaders(httpRequest, request.getHeaders()); + setHeaders(httpRequest, request.getOptions().getHeaders()); FailureTrackingResponseListener failureTrackingResponseListener = new FailureTrackingResponseListener(listener); long startTime = System.nanoTime(); performRequestAsync(startTime, nextHost(), httpRequest, ignoreErrorCodes, - request.getHttpAsyncResponseConsumerFactory(), failureTrackingResponseListener); + request.getOptions().getHttpAsyncResponseConsumerFactory(), failureTrackingResponseListener); } private void performRequestAsync(final long startTime, final HostTuple> hostTuple, final HttpRequestBase request, @@ -891,11 +889,24 @@ public class RestClient implements Closeable { */ @Deprecated private static void addHeaders(Request request, Header... headers) { + setOptions(request, RequestOptions.DEFAULT.getHttpAsyncResponseConsumerFactory(), headers); + } + + /** + * Add all headers from the provided varargs argument to a {@link Request}. This only exists + * to support methods that exist for backwards compatibility. + */ + @Deprecated + private static void setOptions(Request request, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory, + Header... headers) { Objects.requireNonNull(headers, "headers cannot be null"); + RequestOptions.Builder options = request.getOptions().toBuilder(); for (Header header : headers) { Objects.requireNonNull(header, "header cannot be null"); - request.addHeader(header.getName(), header.getValue()); + options.addHeader(header.getName(), header.getValue()); } + options.setHttpAsyncResponseConsumerFactory(httpAsyncResponseConsumerFactory); + request.setOptions(options); } /** diff --git a/client/rest/src/test/java/org/elasticsearch/client/RequestOptionsTests.java b/client/rest/src/test/java/org/elasticsearch/client/RequestOptionsTests.java new file mode 100644 index 00000000000..19106792228 --- /dev/null +++ b/client/rest/src/test/java/org/elasticsearch/client/RequestOptionsTests.java @@ -0,0 +1,142 @@ +/* + * 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; + +import org.apache.http.Header; +import org.elasticsearch.client.HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; + +public class RequestOptionsTests extends RestClientTestCase { + public void testDefault() { + assertEquals(Collections.
emptyList(), RequestOptions.DEFAULT.getHeaders()); + assertEquals(HttpAsyncResponseConsumerFactory.DEFAULT, RequestOptions.DEFAULT.getHttpAsyncResponseConsumerFactory()); + assertEquals(RequestOptions.DEFAULT, RequestOptions.DEFAULT.toBuilder().build()); + } + + public void testAddHeader() { + try { + randomBuilder().addHeader(null, randomAsciiLettersOfLengthBetween(3, 10)); + fail("expected failure"); + } catch (NullPointerException e) { + assertEquals("header name cannot be null", e.getMessage()); + } + + try { + randomBuilder().addHeader(randomAsciiLettersOfLengthBetween(3, 10), null); + fail("expected failure"); + } catch (NullPointerException e) { + assertEquals("header value cannot be null", e.getMessage()); + } + + RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder(); + int numHeaders = between(0, 5); + List
headers = new ArrayList<>(); + for (int i = 0; i < numHeaders; i++) { + Header header = new RequestOptions.ReqHeader(randomAsciiAlphanumOfLengthBetween(5, 10), randomAsciiAlphanumOfLength(3)); + headers.add(header); + builder.addHeader(header.getName(), header.getValue()); + } + RequestOptions options = builder.build(); + assertEquals(headers, options.getHeaders()); + + try { + options.getHeaders().add( + new RequestOptions.ReqHeader(randomAsciiAlphanumOfLengthBetween(5, 10), randomAsciiAlphanumOfLength(3))); + fail("expected failure"); + } catch (UnsupportedOperationException e) { + assertNull(e.getMessage()); + } + } + + public void testSetHttpAsyncResponseConsumerFactory() { + try { + RequestOptions.DEFAULT.toBuilder().setHttpAsyncResponseConsumerFactory(null); + fail("expected failure"); + } catch (NullPointerException e) { + assertEquals("httpAsyncResponseConsumerFactory cannot be null", e.getMessage()); + } + + HttpAsyncResponseConsumerFactory factory = mock(HttpAsyncResponseConsumerFactory.class); + RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder(); + builder.setHttpAsyncResponseConsumerFactory(factory); + RequestOptions options = builder.build(); + assertSame(factory, options.getHttpAsyncResponseConsumerFactory()); + } + + public void testEqualsAndHashCode() { + RequestOptions request = randomBuilder().build(); + assertEquals(request, request); + + RequestOptions copy = copy(request); + assertEquals(request, copy); + assertEquals(copy, request); + assertEquals(request.hashCode(), copy.hashCode()); + + RequestOptions mutant = mutate(request); + assertNotEquals(request, mutant); + assertNotEquals(mutant, request); + } + + static RequestOptions.Builder randomBuilder() { + RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder(); + + if (randomBoolean()) { + int headerCount = between(1, 5); + for (int i = 0; i < headerCount; i++) { + builder.addHeader(randomAsciiAlphanumOfLength(3), randomAsciiAlphanumOfLength(3)); + } + } + + if (randomBoolean()) { + builder.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(1)); + } + + return builder; + } + + private static RequestOptions copy(RequestOptions options) { + return options.toBuilder().build(); + } + + private static RequestOptions mutate(RequestOptions options) { + RequestOptions.Builder mutant = options.toBuilder(); + int mutationType = between(0, 1); + switch (mutationType) { + case 0: + mutant.addHeader("extra", "m"); + return mutant.build(); + case 1: + mutant.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(5)); + return mutant.build(); + default: + throw new UnsupportedOperationException("Unknown mutation type [" + mutationType + "]"); + } + } +} diff --git a/client/rest/src/test/java/org/elasticsearch/client/RequestTests.java b/client/rest/src/test/java/org/elasticsearch/client/RequestTests.java index 29bbf23a1f2..a7cf625b61d 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RequestTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RequestTests.java @@ -37,6 +37,7 @@ import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; public class RequestTests extends RestClientTestCase { @@ -127,33 +128,33 @@ public class RequestTests extends RestClientTestCase { assertEquals(json, new String(os.toByteArray(), ContentType.APPLICATION_JSON.getCharset())); } - public void testAddHeader() { + public void testSetOptions() { final String method = randomFrom(new String[] {"GET", "PUT", "POST", "HEAD", "DELETE"}); final String endpoint = randomAsciiLettersOfLengthBetween(1, 10); Request request = new Request(method, endpoint); try { - request.addHeader(null, randomAsciiLettersOfLengthBetween(3, 10)); + request.setOptions((RequestOptions) null); fail("expected failure"); } catch (NullPointerException e) { - assertEquals("header name cannot be null", e.getMessage()); + assertEquals("options cannot be null", e.getMessage()); } try { - request.addHeader(randomAsciiLettersOfLengthBetween(3, 10), null); + request.setOptions((RequestOptions.Builder) null); fail("expected failure"); } catch (NullPointerException e) { - assertEquals("header value cannot be null", e.getMessage()); + assertEquals("options cannot be null", e.getMessage()); } - int numHeaders = between(0, 5); - List
headers = new ArrayList<>(); - for (int i = 0; i < numHeaders; i++) { - Header header = new Request.ReqHeader(randomAsciiAlphanumOfLengthBetween(5, 10), randomAsciiAlphanumOfLength(3)); - headers.add(header); - request.addHeader(header.getName(), header.getValue()); - } - assertEquals(headers, new ArrayList<>(request.getHeaders())); + RequestOptions.Builder builder = RequestOptionsTests.randomBuilder(); + request.setOptions(builder); + assertEquals(builder.build(), request.getOptions()); + + builder = RequestOptionsTests.randomBuilder(); + RequestOptions options = builder.build(); + request.setOptions(options); + assertSame(options, request.getOptions()); } public void testEqualsAndHashCode() { @@ -193,14 +194,9 @@ public class RequestTests extends RestClientTestCase { } if (randomBoolean()) { - int headerCount = between(1, 5); - for (int i = 0; i < headerCount; i++) { - request.addHeader(randomAsciiAlphanumOfLength(3), randomAsciiAlphanumOfLength(3)); - } - } - - if (randomBoolean()) { - request.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(1)); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(1)); + request.setOptions(options); } return request; @@ -222,7 +218,7 @@ public class RequestTests extends RestClientTestCase { return mutant; } Request mutant = copy(request); - int mutationType = between(0, 3); + int mutationType = between(0, 2); switch (mutationType) { case 0: mutant.addParameter(randomAsciiAlphanumOfLength(mutant.getParameters().size() + 4), "extra"); @@ -231,10 +227,9 @@ public class RequestTests extends RestClientTestCase { mutant.setJsonEntity("mutant"); // randomRequest can't produce this value return mutant; case 2: - mutant.addHeader("extra", "m"); - return mutant; - case 3: - mutant.setHttpAsyncResponseConsumerFactory(new HeapBufferedResponseConsumerFactory(5)); + RequestOptions.Builder options = mutant.getOptions().toBuilder(); + options.addHeader("extra", "m"); + mutant.setOptions(options); return mutant; default: throw new UnsupportedOperationException("Unknown mutation type [" + mutationType + "]"); @@ -246,9 +241,6 @@ public class RequestTests extends RestClientTestCase { to.addParameter(param.getKey(), param.getValue()); } to.setEntity(from.getEntity()); - for (Header header : from.getHeaders()) { - to.addHeader(header.getName(), header.getValue()); - } - to.setHttpAsyncResponseConsumerFactory(from.getHttpAsyncResponseConsumerFactory()); + to.setOptions(from.getOptions()); } } diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java index a3d0196dab9..114d34c73da 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java @@ -378,9 +378,11 @@ public class RestClientSingleHostIntegTests extends RestClientTestCase { String requestBody = "{ \"field\": \"value\" }"; Request request = new Request(method, "/" + statusCode); request.setJsonEntity(requestBody); + RequestOptions.Builder options = request.getOptions().toBuilder(); for (Header header : headers) { - request.addHeader(header.getName(), header.getValue()); + options.addHeader(header.getName(), header.getValue()); } + request.setOptions(options); Response esResponse; try { esResponse = restClient.performRequest(request); diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java index 3811b60023b..634929c5de1 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java @@ -362,9 +362,11 @@ public class RestClientSingleHostTests extends RestClientTestCase { final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header"); final int statusCode = randomStatusCode(getRandom()); Request request = new Request(method, "/" + statusCode); + RequestOptions.Builder options = request.getOptions().toBuilder(); for (Header requestHeader : requestHeaders) { - request.addHeader(requestHeader.getName(), requestHeader.getValue()); + options.addHeader(requestHeader.getName(), requestHeader.getValue()); } + request.setOptions(options); Response esResponse; try { esResponse = restClient.performRequest(request); @@ -438,11 +440,13 @@ public class RestClientSingleHostTests extends RestClientTestCase { final Set uniqueNames = new HashSet<>(); if (randomBoolean()) { Header[] headers = RestClientTestUtil.randomHeaders(getRandom(), "Header"); + RequestOptions.Builder options = request.getOptions().toBuilder(); for (Header header : headers) { - request.addHeader(header.getName(), header.getValue()); - expectedRequest.addHeader(new Request.ReqHeader(header.getName(), header.getValue())); + options.addHeader(header.getName(), header.getValue()); + expectedRequest.addHeader(new RequestOptions.ReqHeader(header.getName(), header.getValue())); uniqueNames.add(header.getName()); } + request.setOptions(options); } for (Header defaultHeader : defaultHeaders) { // request level headers override default headers diff --git a/client/rest/src/test/java/org/elasticsearch/client/documentation/RestClientDocumentation.java b/client/rest/src/test/java/org/elasticsearch/client/documentation/RestClientDocumentation.java index f3ce112fea1..d73c29bd91b 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/documentation/RestClientDocumentation.java +++ b/client/rest/src/test/java/org/elasticsearch/client/documentation/RestClientDocumentation.java @@ -38,6 +38,7 @@ import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.HttpAsyncResponseConsumerFactory; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseListener; import org.elasticsearch.client.RestClient; @@ -171,14 +172,22 @@ public class RestClientDocumentation { //tag::rest-client-body-shorter request.setJsonEntity("{\"json\":\"text\"}"); //end::rest-client-body-shorter - //tag::rest-client-headers - request.addHeader("Accept", "text/plain"); - request.addHeader("Cache-Control", "no-cache"); - //end::rest-client-headers - //tag::rest-client-response-consumer - request.setHttpAsyncResponseConsumerFactory( - new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(30 * 1024 * 1024)); - //end::rest-client-response-consumer + { + //tag::rest-client-headers + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("Accept", "text/plain"); + options.addHeader("Cache-Control", "no-cache"); + request.setOptions(options); + //end::rest-client-headers + } + { + //tag::rest-client-response-consumer + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.setHttpAsyncResponseConsumerFactory( + new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(30 * 1024 * 1024)); + request.setOptions(options); + //end::rest-client-response-consumer + } } { HttpEntity[] documents = new HttpEntity[10]; diff --git a/distribution/src/bin/elasticsearch-keystore.bat b/distribution/src/bin/elasticsearch-keystore.bat index 9bd72a65745..380a3e501d5 100644 --- a/distribution/src/bin/elasticsearch-keystore.bat +++ b/distribution/src/bin/elasticsearch-keystore.bat @@ -5,7 +5,7 @@ setlocal enableextensions call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.common.settings.KeyStoreCli ^ - %* ^ + %%* ^ || exit /b 1 endlocal diff --git a/distribution/src/bin/elasticsearch-plugin.bat b/distribution/src/bin/elasticsearch-plugin.bat index c9a8e9748f1..5d7b1d7a828 100644 --- a/distribution/src/bin/elasticsearch-plugin.bat +++ b/distribution/src/bin/elasticsearch-plugin.bat @@ -6,7 +6,7 @@ setlocal enableextensions set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.plugins.PluginCli ^ - %* ^ + %%* ^ || exit /b 1 endlocal diff --git a/distribution/src/bin/elasticsearch-translog.bat b/distribution/src/bin/elasticsearch-translog.bat index 37d96bbed6c..9c4cefcf2fe 100644 --- a/distribution/src/bin/elasticsearch-translog.bat +++ b/distribution/src/bin/elasticsearch-translog.bat @@ -5,7 +5,7 @@ setlocal enableextensions call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.index.translog.TranslogToolCli ^ - %* ^ + %%* ^ || exit /b 1 endlocal diff --git a/docs/README.asciidoc b/docs/README.asciidoc index 2963359d44c..766aeae0c5d 100644 --- a/docs/README.asciidoc +++ b/docs/README.asciidoc @@ -6,7 +6,9 @@ See: https://github.com/elastic/docs Snippets marked with `// CONSOLE` are automatically annotated with "VIEW IN CONSOLE" and "COPY AS CURL" in the documentation and are automatically tested by the command `gradle :docs:check`. To test just the docs from a single page, -use e.g. `gradle :docs:check -Dtests.method="*rollover*"`. +use e.g. `gradle :docs:check -Dtests.method="\*rollover*"`. + +NOTE: If you have an elasticsearch-extra folder alongside your elasticsearch folder, you must temporarily rename it when you are testing 6.3 or later branches. By default each `// CONSOLE` snippet runs as its own isolated test. You can manipulate the test execution in the following ways: diff --git a/docs/java-rest/high-level/cluster/delete_pipeline.asciidoc b/docs/java-rest/high-level/cluster/delete_pipeline.asciidoc new file mode 100644 index 00000000000..f809f831f78 --- /dev/null +++ b/docs/java-rest/high-level/cluster/delete_pipeline.asciidoc @@ -0,0 +1,80 @@ +[[java-rest-high-cluster-delete-pipeline]] +=== Delete Pipeline API + +[[java-rest-high-cluster-delete-pipeline-request]] +==== Delete Pipeline Request + +A `DeletePipelineRequest` requires a pipeline `id` to delete. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request] +-------------------------------------------------- +<1> The pipeline id to delete + +==== Optional arguments +The following arguments can optionally be provided: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request-timeout] +-------------------------------------------------- +<1> Timeout to wait for the all the nodes to acknowledge the pipeline deletion as a `TimeValue` +<2> Timeout to wait for the all the nodes to acknowledge the pipeline deletion as a `String` + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request-masterTimeout] +-------------------------------------------------- +<1> Timeout to connect to the master node as a `TimeValue` +<2> Timeout to connect to the master node as a `String` + +[[java-rest-high-cluster-delete-pipeline-sync]] +==== Synchronous Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute] +-------------------------------------------------- +<1> Execute the request and get back the response in a `WritePipelineResponse` object. + +[[java-rest-high-cluster-delete-pipeline-async]] +==== Asynchronous Execution + +The asynchronous execution of a delete pipeline request requires both the `DeletePipelineRequest` +instance and an `ActionListener` instance to be passed to the asynchronous +method: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute-async] +-------------------------------------------------- +<1> The `DeletePipelineRequest` to execute and the `ActionListener` to use when +the execution completes + +The asynchronous method does not block and returns immediately. Once it is +completed the `ActionListener` is called back using the `onResponse` method +if the execution successfully completed or using the `onFailure` method if +it failed. + +A typical listener for `WritePipelineResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute-listener] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument +<2> Called in case of failure. The raised exception is provided as an argument + +[[java-rest-high-cluster-delete-pipeline-response]] +==== Delete Pipeline Response + +The returned `WritePipelineResponse` allows to retrieve information about the executed + operation as follows: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-response] +-------------------------------------------------- +<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/cluster/get_pipeline.asciidoc b/docs/java-rest/high-level/cluster/get_pipeline.asciidoc new file mode 100644 index 00000000000..d6a9472a715 --- /dev/null +++ b/docs/java-rest/high-level/cluster/get_pipeline.asciidoc @@ -0,0 +1,75 @@ +[[java-rest-high-cluster-get-pipeline]] +=== Get Pipeline API + +[[java-rest-high-cluster-get-pipeline-request]] +==== Get Pipeline Request + +A `GetPipelineRequest` requires one or more `pipelineIds` to fetch. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-request] +-------------------------------------------------- +<1> The pipeline id to fetch + +==== Optional arguments +The following arguments can optionally be provided: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-request-masterTimeout] +-------------------------------------------------- +<1> Timeout to connect to the master node as a `TimeValue` +<2> Timeout to connect to the master node as a `String` + +[[java-rest-high-cluster-get-pipeline-sync]] +==== Synchronous Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-execute] +-------------------------------------------------- +<1> Execute the request and get back the response in a GetPipelineResponse object. + +[[java-rest-high-cluster-get-pipeline-async]] +==== Asynchronous Execution + +The asynchronous execution of a get pipeline request requires both the `GetPipelineRequest` +instance and an `ActionListener` instance to be passed to the asynchronous +method: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-execute-async] +-------------------------------------------------- +<1> The `GetPipelineRequest` to execute and the `ActionListener` to use when +the execution completes + +The asynchronous method does not block and returns immediately. Once it is +completed the `ActionListener` is called back using the `onResponse` method +if the execution successfully completed or using the `onFailure` method if +it failed. + +A typical listener for `GetPipelineResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-execute-listener] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument +<2> Called in case of failure. The raised exception is provided as an argument + +[[java-rest-high-cluster-get-pipeline-response]] +==== Get Pipeline Response + +The returned `GetPipelineResponse` allows to retrieve information about the executed + operation as follows: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-response] +-------------------------------------------------- +<1> Check if a matching pipeline id was found or not. +<2> Get the list of pipelines found as a list of `PipelineConfig` objects. +<3> Get the individual configuration of each pipeline as a `Map`. diff --git a/docs/java-rest/high-level/cluster/put_pipeline.asciidoc b/docs/java-rest/high-level/cluster/put_pipeline.asciidoc index d50a6741cc0..942b75b74cd 100644 --- a/docs/java-rest/high-level/cluster/put_pipeline.asciidoc +++ b/docs/java-rest/high-level/cluster/put_pipeline.asciidoc @@ -22,8 +22,8 @@ The following arguments can optionally be provided: -------------------------------------------------- include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-request-timeout] -------------------------------------------------- -<1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String` +<1> Timeout to wait for the all the nodes to acknowledge the pipeline creation as a `TimeValue` +<2> Timeout to wait for the all the nodes to acknowledge the pipeline creation as a `String` ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- @@ -39,7 +39,7 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-reque -------------------------------------------------- include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-execute] -------------------------------------------------- -<1> Execute the request and get back the response in a PutPipelineResponse object. +<1> Execute the request and get back the response in a WritePipelineResponse object. [[java-rest-high-cluster-put-pipeline-async]] ==== Asynchronous Execution @@ -60,7 +60,7 @@ completed the `ActionListener` is called back using the `onResponse` method if the execution successfully completed or using the `onFailure` method if it failed. -A typical listener for `PutPipelineResponse` looks like: +A typical listener for `WritePipelineResponse` looks like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- @@ -73,7 +73,7 @@ provided as an argument [[java-rest-high-cluster-put-pipeline-response]] ==== Put Pipeline Response -The returned `PutPipelineResponse` allows to retrieve information about the executed +The returned `WritePipelineResponse` allows to retrieve information about the executed operation as follows: ["source","java",subs="attributes,callouts,macros"] diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index ff1e03afe3e..34873a248b7 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -107,9 +107,13 @@ The Java High Level REST Client supports the following Cluster APIs: * <> * <> +* <> +* <> include::cluster/put_settings.asciidoc[] include::cluster/put_pipeline.asciidoc[] +include::cluster/get_pipeline.asciidoc[] +include::cluster/delete_pipeline.asciidoc[] == Snapshot APIs diff --git a/docs/reference/indices/create-index.asciidoc b/docs/reference/indices/create-index.asciidoc index ade59153644..b013c747a32 100644 --- a/docs/reference/indices/create-index.asciidoc +++ b/docs/reference/indices/create-index.asciidoc @@ -23,7 +23,7 @@ There are several limitations to what you can name your index. The complete lis - Cannot include `\`, `/`, `*`, `?`, `"`, `<`, `>`, `|`, ` ` (space character), `,`, `#` - Indices prior to 7.0 could contain a colon (`:`), but that's been deprecated and won't be supported in 7.0+ - Cannot start with `-`, `_`, `+` -- Cannot be `.` or ``..` +- Cannot be `.` or `..` - Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster) ====================================================== diff --git a/docs/reference/mapping/types/geo-shape.asciidoc b/docs/reference/mapping/types/geo-shape.asciidoc index 8768836484d..5a39c4b117e 100644 --- a/docs/reference/mapping/types/geo-shape.asciidoc +++ b/docs/reference/mapping/types/geo-shape.asciidoc @@ -175,7 +175,7 @@ PUT /example "location": { "type": "geo_shape", "tree": "quadtree", - "precision": "1m" + "precision": "100m" } } } @@ -186,8 +186,8 @@ PUT /example // TESTSETUP This mapping maps the location field to the geo_shape type using the -quad_tree implementation and a precision of 1m. Elasticsearch translates -this into a tree_levels setting of 26. +quad_tree implementation and a precision of 100m. Elasticsearch translates +this into a tree_levels setting of 20. [float] ===== Performance considerations @@ -364,7 +364,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] The following is an example of a Polygon with a hole in WKT: @@ -376,7 +375,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] *IMPORTANT NOTE:* WKT does not enforce a specific order for vertices thus ambiguous polygons around the dateline and poles are possible. @@ -411,7 +409,7 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] +// TEST[catch:/mapper_parsing_exception/] An `orientation` parameter can be defined when setting the geo_shape mapping (see <>). This will define vertex order for the coordinate list on the mapped geo_shape field. It can also be overridden on each document. The following is an example for @@ -425,14 +423,12 @@ POST /example/doc "type" : "polygon", "orientation" : "clockwise", "coordinates" : [ - [ [-177.0, 10.0], [176.0, 15.0], [172.0, 0.0], [176.0, -15.0], [-177.0, -10.0], [-177.0, 10.0] ], - [ [178.2, 8.2], [-178.8, 8.2], [-180.8, -8.8], [178.2, 8.8] ] + [ [100.0, 0.0], [100.0, 1.0], [101.0, 1.0], [101.0, 0.0], [100.0, 0.0] ] ] } } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] [float] ===== http://www.geojson.org/geojson-spec.html#id5[MultiPoint] @@ -484,7 +480,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] The following is an example of a list of WKT linestrings: @@ -496,7 +491,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] [float] ===== http://www.geojson.org/geojson-spec.html#id7[MultiPolygon] @@ -518,7 +512,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] The following is an example of a list of WKT polygons (second polygon contains a hole): @@ -530,7 +523,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] [float] ===== http://geojson.org/geojson-spec.html#geometrycollection[Geometry Collection] @@ -557,7 +549,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] The following is an example of a collection of WKT geometry objects: @@ -569,7 +560,6 @@ POST /example/doc } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] [float] @@ -585,12 +575,11 @@ POST /example/doc { "location" : { "type" : "envelope", - "coordinates" : [ [-45.0, 45.0], [45.0, -45.0] ] + "coordinates" : [ [100.0, 1.0], [101.0, 0.0] ] } } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] The following is an example of an envelope using the WKT BBOX format: @@ -600,11 +589,10 @@ The following is an example of an envelope using the WKT BBOX format: -------------------------------------------------- POST /example/doc { - "location" : "BBOX (-45.0, 45.0, 45.0, -45.0)" + "location" : "BBOX (100.0, 102.0, 2.0, 0.0)" } -------------------------------------------------- // CONSOLE -// TEST[skip:https://github.com/elastic/elasticsearch/issues/23836] [float] ===== Circle @@ -618,7 +606,7 @@ POST /example/doc { "location" : { "type" : "circle", - "coordinates" : [-45.0, 45.0], + "coordinates" : [101.0, 1.0], "radius" : "100m" } } diff --git a/docs/reference/mapping/types/keyword.asciidoc b/docs/reference/mapping/types/keyword.asciidoc index c7b35d7315e..09d540feed1 100644 --- a/docs/reference/mapping/types/keyword.asciidoc +++ b/docs/reference/mapping/types/keyword.asciidoc @@ -103,6 +103,12 @@ The following parameters are accepted by `keyword` fields: How to pre-process the keyword prior to indexing. Defaults to `null`, meaning the keyword is kept as-is. +`split_queries_on_whitespace`:: + + Whether <> should split the input on whitespace + when building a query for this field. + Accepts `true` or `false` (default). + NOTE: Indexes imported from 2.x do not support `keyword`. Instead they will attempt to downgrade `keyword` into `string`. This allows you to merge modern mappings with legacy mappings. Long lived indexes will have to be recreated diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java index c68f498c0ea..5204a07b1c9 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java @@ -52,8 +52,7 @@ import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; -public class GrokProcessorGetAction extends Action { +public class GrokProcessorGetAction extends Action { public static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction(); public static final String NAME = "cluster:admin/ingest/processor/grok/get"; @@ -62,11 +61,6 @@ public class GrokProcessorGetAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, GrokProcessorGetAction.INSTANCE, new Request()); } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java index 99eb9709f73..21b9a11e1f2 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java @@ -20,10 +20,8 @@ package org.elasticsearch.script.mustache; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class MultiSearchTemplateAction - extends Action { +public class MultiSearchTemplateAction extends Action { public static final MultiSearchTemplateAction INSTANCE = new MultiSearchTemplateAction(); public static final String NAME = "indices:data/read/msearch/template"; @@ -36,9 +34,4 @@ public class MultiSearchTemplateAction public MultiSearchTemplateResponse newResponse() { return new MultiSearchTemplateResponse(); } - - @Override - public MultiSearchTemplateRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new MultiSearchTemplateRequestBuilder(client, this); - } } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestBuilder.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestBuilder.java index 4ef6c593d9a..c4dac0dd88e 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestBuilder.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestBuilder.java @@ -24,7 +24,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.ElasticsearchClient; public class MultiSearchTemplateRequestBuilder - extends ActionRequestBuilder { + extends ActionRequestBuilder { protected MultiSearchTemplateRequestBuilder(ElasticsearchClient client, MultiSearchTemplateAction action) { super(client, action, new MultiSearchTemplateRequest()); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java index 2982fbd70c6..1246e8e8e9b 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.script.mustache; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class SearchTemplateAction extends Action { +public class SearchTemplateAction extends Action { public static final SearchTemplateAction INSTANCE = new SearchTemplateAction(); public static final String NAME = "indices:data/read/search/template"; @@ -31,11 +30,6 @@ public class SearchTemplateAction extends Action { + extends ActionRequestBuilder { SearchTemplateRequestBuilder(ElasticsearchClient client, SearchTemplateAction action) { super(client, action, new SearchTemplateRequest()); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java index aa650a37c4f..f91d349f806 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessExecuteAction.java @@ -62,8 +62,7 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestStatus.OK; -public class PainlessExecuteAction extends Action { +public class PainlessExecuteAction extends Action { static final PainlessExecuteAction INSTANCE = new PainlessExecuteAction(); private static final String NAME = "cluster:admin/scripts/painless/execute"; @@ -72,11 +71,6 @@ public class PainlessExecuteAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/FeatureFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/FeatureFieldMapper.java index 5b0158ff55b..30e18ae6d68 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/FeatureFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/FeatureFieldMapper.java @@ -163,14 +163,6 @@ public class FeatureFieldMapper extends FieldMapper { return new TermQuery(new Term("_feature", name())); } - @Override - public Query nullValueQuery() { - if (nullValue() == null) { - return null; - } - return termQuery(nullValue(), null); - } - @Override public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { failIfNoDocValues(); diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java index 8908fbdfbdd..441cbb5fac1 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java @@ -20,12 +20,11 @@ package org.elasticsearch.index.rankeval; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for explaining evaluating search ranking results. */ -public class RankEvalAction extends Action { +public class RankEvalAction extends Action { public static final RankEvalAction INSTANCE = new RankEvalAction(); public static final String NAME = "indices:data/read/rank_eval"; @@ -34,11 +33,6 @@ public class RankEvalAction extends Action { +public class RankEvalRequestBuilder extends ActionRequestBuilder { - public RankEvalRequestBuilder(ElasticsearchClient client, Action action, + public RankEvalRequestBuilder(ElasticsearchClient client, Action action, RankEvalRequest request) { super(client, action, request); } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java index 2aff0d7a5c5..3cc0901c81e 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java @@ -61,7 +61,7 @@ class BulkByScrollParallelizationHelper { static > void startSlicedAction( Request request, BulkByScrollTask task, - Action action, + Action action, ActionListener listener, Client client, DiscoveryNode node, @@ -85,7 +85,7 @@ class BulkByScrollParallelizationHelper { private static > void sliceConditionally( Request request, BulkByScrollTask task, - Action action, + Action action, ActionListener listener, Client client, DiscoveryNode node, @@ -118,7 +118,7 @@ class BulkByScrollParallelizationHelper { private static > void sendSubRequests( Client client, - Action action, + Action action, String localNodeId, BulkByScrollTask task, Request request, diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java index ffbcbbf1e37..ff0803c7742 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java @@ -21,9 +21,8 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.action.Action; import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; -import org.elasticsearch.client.ElasticsearchClient; -public class RethrottleAction extends Action { +public class RethrottleAction extends Action { public static final RethrottleAction INSTANCE = new RethrottleAction(); public static final String NAME = "cluster:admin/reindex/rethrottle"; @@ -31,11 +30,6 @@ public class RethrottleAction extends Action { public RethrottleRequestBuilder(ElasticsearchClient client, - Action action) { + Action action) { super(client, action, new RethrottleRequest()); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java b/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java index 1f99f062d25..8743ef255ba 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java +++ b/modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java @@ -27,10 +27,12 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.BulkByScrollResponse; import org.elasticsearch.index.reindex.BulkByScrollTask; import org.elasticsearch.index.reindex.DeleteByQueryAction; +import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder; import org.elasticsearch.index.reindex.ReindexAction; import org.elasticsearch.index.reindex.ReindexRequest; import org.elasticsearch.index.reindex.ReindexRequestBuilder; import org.elasticsearch.index.reindex.RethrottleAction; +import org.elasticsearch.index.reindex.RethrottleRequestBuilder; import org.elasticsearch.index.reindex.UpdateByQueryAction; import org.elasticsearch.index.reindex.UpdateByQueryRequestBuilder; import org.elasticsearch.script.Script; @@ -47,7 +49,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { public void reindex() { Client client = client(); // tag::reindex1 - BulkByScrollResponse response = ReindexAction.INSTANCE.newRequestBuilder(client) + BulkByScrollResponse response = new ReindexRequestBuilder(client, ReindexAction.INSTANCE) .destination("target_index") .filter(QueryBuilders.matchQuery("category", "xzy")) // <1> .get(); @@ -58,14 +60,14 @@ public class ReindexDocumentationIT extends ESIntegTestCase { Client client = client(); { // tag::update-by-query - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index").abortOnVersionConflict(false); BulkByScrollResponse response = updateByQuery.get(); // end::update-by-query } { // tag::update-by-query-filter - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index") .filter(QueryBuilders.termQuery("level", "awesome")) .size(1000) @@ -75,7 +77,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { } { // tag::update-by-query-size - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index") .source().setSize(500); BulkByScrollResponse response = updateByQuery.get(); @@ -83,7 +85,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { } { // tag::update-by-query-sort - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index").size(100) .source().addSort("cat", SortOrder.DESC); BulkByScrollResponse response = updateByQuery.get(); @@ -91,7 +93,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { } { // tag::update-by-query-script - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("source_index") .script(new Script( ScriptType.INLINE, @@ -108,21 +110,21 @@ public class ReindexDocumentationIT extends ESIntegTestCase { } { // tag::update-by-query-multi-index - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source("foo", "bar").source().setTypes("a", "b"); BulkByScrollResponse response = updateByQuery.get(); // end::update-by-query-multi-index } { // tag::update-by-query-routing - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.source().setRouting("cat"); BulkByScrollResponse response = updateByQuery.get(); // end::update-by-query-routing } { // tag::update-by-query-pipeline - UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.INSTANCE.newRequestBuilder(client); + UpdateByQueryRequestBuilder updateByQuery = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE); updateByQuery.setPipeline("hurray"); BulkByScrollResponse response = updateByQuery.get(); // end::update-by-query-pipeline @@ -156,7 +158,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { { TaskId taskId = null; // tag::update-by-query-rethrottle - RethrottleAction.INSTANCE.newRequestBuilder(client) + new RethrottleRequestBuilder(client, RethrottleAction.INSTANCE) .setTaskId(taskId) .setRequestsPerSecond(2.0f) .get(); @@ -167,7 +169,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { public void deleteByQuery() { Client client = client(); // tag::delete-by-query-sync - BulkByScrollResponse response = DeleteByQueryAction.INSTANCE.newRequestBuilder(client) + BulkByScrollResponse response = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE) .filter(QueryBuilders.matchQuery("gender", "male")) // <1> .source("persons") // <2> .get(); // <3> @@ -175,7 +177,7 @@ public class ReindexDocumentationIT extends ESIntegTestCase { // end::delete-by-query-sync // tag::delete-by-query-async - DeleteByQueryAction.INSTANCE.newRequestBuilder(client) + new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE) .filter(QueryBuilders.matchQuery("gender", "male")) // <1> .source("persons") // <2> .execute(new ActionListener() { // <3> diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java index 17345f5c85b..727710e8b6b 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -744,8 +744,8 @@ public class AsyncBulkByScrollActionTests extends ESTestCase { @Override @SuppressWarnings("unchecked") protected > void doExecute( - Action action, Request request, ActionListener listener) { + RequestBuilder extends ActionRequestBuilder> void doExecute( + Action action, Request request, ActionListener listener) { if (false == expectedHeaders.equals(threadPool().getThreadContext().getHeaders())) { listener.onFailure( new RuntimeException("Expected " + expectedHeaders + " but got " + threadPool().getThreadContext().getHeaders())); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java index f829c8f22d7..72ba651dff9 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java @@ -109,13 +109,13 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase { } public void testReindexFromRemoteWithAuthentication() throws Exception { - ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest") + ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") .setRemoteInfo(newRemoteInfo("Aladdin", "open sesame", emptyMap())); assertThat(request.get(), matcher().created(1)); } public void testReindexSendsHeaders() throws Exception { - ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest") + ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") .setRemoteInfo(newRemoteInfo(null, null, singletonMap(TestFilter.EXAMPLE_HEADER, "doesn't matter"))); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get()); assertEquals(RestStatus.BAD_REQUEST, e.status()); @@ -123,7 +123,7 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase { } public void testReindexWithoutAuthenticationWhenRequired() throws Exception { - ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest") + ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") .setRemoteInfo(newRemoteInfo(null, null, emptyMap())); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get()); assertEquals(RestStatus.UNAUTHORIZED, e.status()); @@ -132,7 +132,7 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase { } public void testReindexWithBadAuthentication() throws Exception { - ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest") + ReindexRequestBuilder request = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("source").destination("dest") .setRemoteInfo(newRemoteInfo("junk", "auth", emptyMap())); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get()); assertThat(e.getMessage(), containsString("\"reason\":\"Bad Authorization\"")); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexTestCase.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexTestCase.java index 54854afb35e..01b5539a23c 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexTestCase.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexTestCase.java @@ -47,19 +47,19 @@ public abstract class ReindexTestCase extends ESIntegTestCase { } protected ReindexRequestBuilder reindex() { - return ReindexAction.INSTANCE.newRequestBuilder(client()); + return new ReindexRequestBuilder(client(), ReindexAction.INSTANCE); } protected UpdateByQueryRequestBuilder updateByQuery() { - return UpdateByQueryAction.INSTANCE.newRequestBuilder(client()); + return new UpdateByQueryRequestBuilder(client(), UpdateByQueryAction.INSTANCE); } protected DeleteByQueryRequestBuilder deleteByQuery() { - return DeleteByQueryAction.INSTANCE.newRequestBuilder(client()); + return new DeleteByQueryRequestBuilder(client(), DeleteByQueryAction.INSTANCE); } protected RethrottleRequestBuilder rethrottle() { - return RethrottleAction.INSTANCE.newRequestBuilder(client()); + return new RethrottleRequestBuilder(client(), RethrottleAction.INSTANCE); } public static BulkIndexByScrollResponseMatcher matcher() { diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RetryTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RetryTests.java index aea720aeb21..4fe3d1a3a6e 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RetryTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RetryTests.java @@ -106,7 +106,7 @@ public class RetryTests extends ESIntegTestCase { public void testReindex() throws Exception { testCase( ReindexAction.NAME, - client -> ReindexAction.INSTANCE.newRequestBuilder(client).source("source").destination("dest"), + client -> new ReindexRequestBuilder(client, ReindexAction.INSTANCE).source("source").destination("dest"), matcher().created(DOC_COUNT)); } @@ -127,7 +127,7 @@ public class RetryTests extends ESIntegTestCase { TransportAddress address = masterNode.getHttp().getAddress().publishAddress(); RemoteInfo remote = new RemoteInfo("http", address.getAddress(), address.getPort(), new BytesArray("{\"match_all\":{}}"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT); - ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client).source("source").destination("dest") + ReindexRequestBuilder request = new ReindexRequestBuilder(client, ReindexAction.INSTANCE).source("source").destination("dest") .setRemoteInfo(remote); return request; }; @@ -135,12 +135,12 @@ public class RetryTests extends ESIntegTestCase { } public void testUpdateByQuery() throws Exception { - testCase(UpdateByQueryAction.NAME, client -> UpdateByQueryAction.INSTANCE.newRequestBuilder(client).source("source"), + testCase(UpdateByQueryAction.NAME, client -> new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE).source("source"), matcher().updated(DOC_COUNT)); } public void testDeleteByQuery() throws Exception { - testCase(DeleteByQueryAction.NAME, client -> DeleteByQueryAction.INSTANCE.newRequestBuilder(client).source("source") + testCase(DeleteByQueryAction.NAME, client -> new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE).source("source") .filter(QueryBuilders.matchAllQuery()), matcher().deleted(DOC_COUNT)); } diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java index 5194c762b7e..2ce6ffada67 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java @@ -119,7 +119,19 @@ public class Netty4HttpRequest extends RestRequest { return Method.OPTIONS; } - return Method.GET; + if (httpMethod == HttpMethod.PATCH) { + return Method.PATCH; + } + + if (httpMethod == HttpMethod.TRACE) { + return Method.TRACE; + } + + if (httpMethod == HttpMethod.CONNECT) { + return Method.CONNECT; + } + + throw new IllegalArgumentException("Unexpected http method: " + httpMethod); } @Override diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ESLoggingHandler.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ESLoggingHandler.java index 47a31f268a6..5ee79834740 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ESLoggingHandler.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ESLoggingHandler.java @@ -104,6 +104,10 @@ final class ESLoggingHandler extends LoggingHandler { try (ThreadContext context = new ThreadContext(Settings.EMPTY)) { context.readHeaders(in); } + // now we decode the features + if (in.getVersion().onOrAfter(Version.V_6_3_0)) { + in.readStringArray(); + } // now we can decode the action name sb.append(", action: ").append(in.readString()); } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index a4502a953db..c4c44222f47 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -135,14 +135,6 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { } } - @Override - public Query nullValueQuery() { - if (nullValue() == null) { - return null; - } - return termQuery(nullValue(), null); - } - @Override public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { failIfNoDocValues(); diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java index b5bfcc6b0cc..4dcd6ba19e0 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java @@ -84,7 +84,19 @@ public class NioHttpRequest extends RestRequest { return Method.OPTIONS; } - return Method.GET; + if (httpMethod == HttpMethod.PATCH) { + return Method.PATCH; + } + + if (httpMethod == HttpMethod.TRACE) { + return Method.TRACE; + } + + if (httpMethod == HttpMethod.CONNECT) { + return Method.CONNECT; + } + + throw new IllegalArgumentException("Unexpected http method: " + httpMethod); } @Override diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml index c40e7be1c64..ac47fe000dd 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml @@ -1,7 +1,7 @@ --- "Search with missing remote index pattern": - do: - catch: "request" + catch: "missing" search: index: "my_remote_cluster:foo" @@ -34,7 +34,7 @@ - match: { aggregations.cluster.buckets.0.doc_count: 6 } - do: - catch: "request" + catch: "missing" search: index: "my_remote_cluster:test_index,my_remote_cluster:foo" body: diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java index 99132f0c89d..81724bd72ab 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java @@ -31,6 +31,7 @@ import org.elasticsearch.action.support.ActionFilter; import org.elasticsearch.action.termvectors.MultiTermVectorsRequest; import org.elasticsearch.client.Client; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; @@ -221,8 +222,10 @@ public class ContextAndHeaderTransportIT extends HttpSmokeTestCase { public void testThatRelevantHttpHeadersBecomeRequestHeaders() throws IOException { final String IRRELEVANT_HEADER = "SomeIrrelevantHeader"; Request request = new Request("GET", "/" + queryIndex + "/_search"); - request.addHeader(CUSTOM_HEADER, randomHeaderValue); - request.addHeader(IRRELEVANT_HEADER, randomHeaderValue); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader(CUSTOM_HEADER, randomHeaderValue); + options.addHeader(IRRELEVANT_HEADER, randomHeaderValue); + request.setOptions(options); Response response = getRestClient().performRequest(request); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); List searchRequests = getRequests(SearchRequest.class); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java index 2d139e7955e..a1dd978df17 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java @@ -20,6 +20,7 @@ package org.elasticsearch.http; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import java.io.IOException; @@ -32,8 +33,10 @@ public class CorsNotSetIT extends HttpSmokeTestCase { public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws IOException { String corsValue = "http://localhost:9200"; Request request = new Request("GET", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); - request.addHeader("Origin", corsValue); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + options.addHeader("Origin", corsValue); + request.setOptions(options); Response response = getRestClient().performRequest(request); assertThat(response.getStatusLine().getStatusCode(), is(200)); assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue()); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java index e79e8031550..ad10ad80e4b 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.http; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.settings.Settings; @@ -55,16 +56,20 @@ public class CorsRegexIT extends HttpSmokeTestCase { { String corsValue = "http://localhost:9200"; Request request = new Request("GET", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); - request.addHeader("Origin", corsValue); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + options.addHeader("Origin", corsValue); + request.setOptions(options); Response response = getRestClient().performRequest(request); assertResponseWithOriginHeader(response, corsValue); } { String corsValue = "https://localhost:9201"; Request request = new Request("GET", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); - request.addHeader("Origin", corsValue); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + options.addHeader("Origin", corsValue); + request.setOptions(options); Response response = getRestClient().performRequest(request); assertResponseWithOriginHeader(response, corsValue); assertThat(response.getHeader("Access-Control-Allow-Credentials"), is("true")); @@ -73,8 +78,10 @@ public class CorsRegexIT extends HttpSmokeTestCase { public void testThatRegularExpressionReturnsForbiddenOnNonMatch() throws IOException { Request request = new Request("GET", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); - request.addHeader("Origin", "http://evil-host:9200"); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + options.addHeader("Origin", "http://evil-host:9200"); + request.setOptions(options); try { getRestClient().performRequest(request); fail("request should have failed"); @@ -88,7 +95,9 @@ public class CorsRegexIT extends HttpSmokeTestCase { public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws IOException { Request request = new Request("GET", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + request.setOptions(options); Response response = getRestClient().performRequest(request); assertThat(response.getStatusLine().getStatusCode(), is(200)); assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue()); @@ -103,9 +112,11 @@ public class CorsRegexIT extends HttpSmokeTestCase { public void testThatPreFlightRequestWorksOnMatch() throws IOException { String corsValue = "http://localhost:9200"; Request request = new Request("OPTIONS", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); - request.addHeader("Origin", corsValue); - request.addHeader("Access-Control-Request-Method", "GET"); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + options.addHeader("Origin", corsValue); + options.addHeader("Access-Control-Request-Method", "GET"); + request.setOptions(options); Response response = getRestClient().performRequest(request); assertResponseWithOriginHeader(response, corsValue); assertNotNull(response.getHeader("Access-Control-Allow-Methods")); @@ -114,9 +125,11 @@ public class CorsRegexIT extends HttpSmokeTestCase { public void testThatPreFlightRequestReturnsNullOnNonMatch() throws IOException { String corsValue = "http://evil-host:9200"; Request request = new Request("OPTIONS", "/"); - request.addHeader("User-Agent", "Mozilla Bar"); - request.addHeader("Origin", corsValue); - request.addHeader("Access-Control-Request-Method", "GET"); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("User-Agent", "Mozilla Bar"); + options.addHeader("Origin", corsValue); + options.addHeader("Access-Control-Request-Method", "GET"); + request.setOptions(options); try { getRestClient().performRequest(request); fail("request should have failed"); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java index a9a0a0c7ed9..b287b49527a 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java @@ -20,6 +20,7 @@ package org.elasticsearch.http; import org.apache.http.HttpHeaders; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.test.rest.ESRestTestCase; @@ -38,7 +39,9 @@ public class HttpCompressionIT extends ESRestTestCase { public void testCompressesResponseIfRequested() throws IOException { Request request = new Request("GET", "/"); - request.addHeader(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING); + request.setOptions(options); Response response = client().performRequest(request); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(GZIP_ENCODING, response.getHeader(HttpHeaders.CONTENT_ENCODING)); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/NoHandlerIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/NoHandlerIT.java index 976ba313115..d3707031f0e 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/NoHandlerIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/NoHandlerIT.java @@ -21,6 +21,7 @@ package org.elasticsearch.http; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; @@ -46,7 +47,9 @@ public class NoHandlerIT extends HttpSmokeTestCase { private void runTestNoHandlerRespectsAcceptHeader( final String accept, final String contentType, final String expect) throws IOException { Request request = new Request("GET", "/foo/bar/baz/qux/quux"); - request.addHeader("Accept", accept); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("Accept", accept); + request.setOptions(options); final ResponseException e = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request)); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java index ac2503f2c52..d73566c8038 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.http; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.plugins.Plugin; @@ -61,7 +62,9 @@ public class ResponseHeaderPluginIT extends HttpSmokeTestCase { } Request request = new Request("GET", "/_protected"); - request.addHeader("Secret", "password"); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("Secret", "password"); + request.setOptions(options); Response authResponse = getRestClient().performRequest(request); assertThat(authResponse.getStatusLine().getStatusCode(), equalTo(200)); assertThat(authResponse.getHeader("Secret"), equalTo("granted")); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get_repository/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get_repository/10_basic.yml index c70942f0c9d..b944fe43791 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get_repository/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get_repository/10_basic.yml @@ -51,9 +51,6 @@ setup: --- "Verify created repository": - - skip: - version: "all" - reason: AwaitsFix for https://github.com/elastic/elasticsearch/issues/30807 - do: snapshot.verify_repository: repository: test_repo_get_2 diff --git a/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java b/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java index c0c6bbb05d8..249b7fa83b5 100644 --- a/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java +++ b/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java @@ -19,12 +19,8 @@ package org.apache.lucene.queries; -import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermContext; import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.Query; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.index.mapper.MappedFieldType; /** * Extended version of {@link CommonTermsQuery} that allows to pass in a @@ -33,11 +29,8 @@ import org.elasticsearch.index.mapper.MappedFieldType; */ public class ExtendedCommonTermsQuery extends CommonTermsQuery { - private final MappedFieldType fieldType; - - public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency, MappedFieldType fieldType) { + public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency) { super(highFreqOccur, lowFreqOccur, maxTermFrequency); - this.fieldType = fieldType; } private String lowFreqMinNumShouldMatchSpec; @@ -80,16 +73,4 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery { return this.maxTermFrequency; } - @Override - protected Query newTermQuery(Term term, TermContext context) { - if (fieldType == null) { - return super.newTermQuery(term, context); - } - final Query query = fieldType.queryStringTermQuery(term); - if (query == null) { - return super.newTermQuery(term, context); - } else { - return query; - } - } } diff --git a/server/src/main/java/org/elasticsearch/ElasticsearchException.java b/server/src/main/java/org/elasticsearch/ElasticsearchException.java index db8263d1513..db26cb2a5e9 100644 --- a/server/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/server/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -269,7 +269,6 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } } - /** * Retrieve the innermost cause of this exception, if none, returns the current exception. */ @@ -292,7 +291,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte out.writeMapOfLists(headers, StreamOutput::writeString, StreamOutput::writeString); out.writeMapOfLists(metadata, StreamOutput::writeString, StreamOutput::writeString); } else { - HashMap> finalHeaders = new HashMap<>(headers.size() + metadata.size()); + Map> finalHeaders = new HashMap<>(headers.size() + metadata.size()); finalHeaders.putAll(headers); finalHeaders.putAll(metadata); out.writeMapOfLists(finalHeaders, StreamOutput::writeString, StreamOutput::writeString); diff --git a/server/src/main/java/org/elasticsearch/action/Action.java b/server/src/main/java/org/elasticsearch/action/Action.java index 51e3f5440ea..8d419f379d3 100644 --- a/server/src/main/java/org/elasticsearch/action/Action.java +++ b/server/src/main/java/org/elasticsearch/action/Action.java @@ -19,20 +19,13 @@ package org.elasticsearch.action; -import org.elasticsearch.client.ElasticsearchClient; - /** * Base action. Supports building the Request through a RequestBuilder. */ -public abstract class Action> +public abstract class Action extends GenericAction { protected Action(String name) { super(name); } - - /** - * Creates a new request builder given the client provided as argument - */ - public abstract RequestBuilder newRequestBuilder(ElasticsearchClient client); } diff --git a/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java index 964568fc472..208c609333c 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java @@ -24,14 +24,13 @@ import org.elasticsearch.common.unit.TimeValue; import java.util.Objects; -public abstract class ActionRequestBuilder> { +public abstract class ActionRequestBuilder { - protected final Action action; + protected final Action action; protected final Request request; protected final ElasticsearchClient client; - protected ActionRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected ActionRequestBuilder(ElasticsearchClient client, Action action, Request request) { Objects.requireNonNull(action, "action must not be null"); this.action = action; this.request = request; diff --git a/server/src/main/java/org/elasticsearch/action/FailedNodeException.java b/server/src/main/java/org/elasticsearch/action/FailedNodeException.java index bf9aad0d39e..475de7eae5f 100644 --- a/server/src/main/java/org/elasticsearch/action/FailedNodeException.java +++ b/server/src/main/java/org/elasticsearch/action/FailedNodeException.java @@ -22,6 +22,7 @@ package org.elasticsearch.action; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -48,4 +49,9 @@ public class FailedNodeException extends ElasticsearchException { super.writeTo(out); out.writeOptionalString(nodeId); } + + @Override + protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException { + builder.field("node_id", nodeId); + } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java index d34ac63602d..648429cbf5c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainAction.java @@ -25,9 +25,7 @@ import org.elasticsearch.client.ElasticsearchClient; /** * Action for explaining shard allocation for a shard in the cluster */ -public class ClusterAllocationExplainAction extends Action { +public class ClusterAllocationExplainAction extends Action { public static final ClusterAllocationExplainAction INSTANCE = new ClusterAllocationExplainAction(); public static final String NAME = "cluster:monitor/allocation/explain"; @@ -40,9 +38,4 @@ public class ClusterAllocationExplainAction extends Action { +public class ClusterHealthAction extends Action { public static final ClusterHealthAction INSTANCE = new ClusterHealthAction(); public static final String NAME = "cluster:monitor/health"; @@ -35,9 +34,4 @@ public class ClusterHealthAction extends Action { +public class NodesHotThreadsAction extends Action { public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction(); public static final String NAME = "cluster:monitor/nodes/hot_threads"; @@ -35,9 +34,4 @@ public class NodesHotThreadsAction extends Action { +public class NodesInfoAction extends Action { public static final NodesInfoAction INSTANCE = new NodesInfoAction(); public static final String NAME = "cluster:monitor/nodes/info"; @@ -35,9 +34,4 @@ public class NodesInfoAction extends Action { +public class NodesStatsAction extends Action { public static final NodesStatsAction INSTANCE = new NodesStatsAction(); public static final String NAME = "cluster:monitor/nodes/stats"; @@ -35,9 +34,4 @@ public class NodesStatsAction extends Action { +public class CancelTasksAction extends Action { public static final CancelTasksAction INSTANCE = new CancelTasksAction(); public static final String NAME = "cluster:admin/tasks/cancel"; @@ -38,9 +37,4 @@ public class CancelTasksAction extends Action { +public class GetTaskAction extends Action { public static final GetTaskAction INSTANCE = new GetTaskAction(); public static final String NAME = "cluster:monitor/task/get"; @@ -38,9 +37,4 @@ public class GetTaskAction extends Action { +public class GetTaskRequestBuilder extends ActionRequestBuilder { public GetTaskRequestBuilder(ElasticsearchClient client, GetTaskAction action) { super(client, action, new GetTaskRequest()); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksAction.java index acc11861108..e054f074aa2 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksAction.java @@ -20,12 +20,11 @@ package org.elasticsearch.action.admin.cluster.node.tasks.list; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for retrieving a list of currently running tasks */ -public class ListTasksAction extends Action { +public class ListTasksAction extends Action { public static final ListTasksAction INSTANCE = new ListTasksAction(); public static final String NAME = "cluster:monitor/tasks/lists"; @@ -38,9 +37,4 @@ public class ListTasksAction extends Action { +public class NodesUsageAction extends Action { public static final NodesUsageAction INSTANCE = new NodesUsageAction(); public static final String NAME = "cluster:monitor/nodes/usage"; @@ -31,11 +30,6 @@ public class NodesUsageAction extends Action { - public NodesUsageRequestBuilder(ElasticsearchClient client, - Action action) { + public NodesUsageRequestBuilder(ElasticsearchClient client, Action action) { super(client, action, new NodesUsageRequest()); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteInfoAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteInfoAction.java index aa546c7dffd..6e3c877156d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteInfoAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteInfoAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.admin.cluster.remote; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public final class RemoteInfoAction extends Action { +public final class RemoteInfoAction extends Action { public static final String NAME = "cluster:monitor/remote/info"; public static final RemoteInfoAction INSTANCE = new RemoteInfoAction(); @@ -31,11 +30,6 @@ public final class RemoteInfoAction extends Action { +public final class RemoteInfoRequestBuilder extends ActionRequestBuilder { public RemoteInfoRequestBuilder(ElasticsearchClient client, RemoteInfoAction action) { super(client, action, new RemoteInfoRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java index 83166753b27..3d7f9187ea2 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java @@ -20,12 +20,11 @@ package org.elasticsearch.action.admin.cluster.repositories.delete; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Unregister repository action */ -public class DeleteRepositoryAction extends Action { +public class DeleteRepositoryAction extends Action { public static final DeleteRepositoryAction INSTANCE = new DeleteRepositoryAction(); public static final String NAME = "cluster:admin/repository/delete"; @@ -38,10 +37,5 @@ public class DeleteRepositoryAction extends Action { +public class GetRepositoriesAction extends Action { public static final GetRepositoriesAction INSTANCE = new GetRepositoriesAction(); public static final String NAME = "cluster:admin/repository/get"; @@ -38,10 +37,5 @@ public class GetRepositoriesAction extends Action { +public class PutRepositoryAction extends Action { public static final PutRepositoryAction INSTANCE = new PutRepositoryAction(); public static final String NAME = "cluster:admin/repository/put"; @@ -38,10 +37,5 @@ public class PutRepositoryAction extends Action { +public class VerifyRepositoryAction extends Action { public static final VerifyRepositoryAction INSTANCE = new VerifyRepositoryAction(); public static final String NAME = "cluster:admin/repository/verify"; @@ -38,10 +37,5 @@ public class VerifyRepositoryAction extends Action= 6.4 a consumer of the response will only be able to retrieve a representation of {@link NodeView} - * objects. - * - * Effectively this will be used to hold the state of the object in 6.x so there is no need to have 2 backing objects that - * represent the state of the Response. In practice these will always be read by a consumer as a NodeView, but it eases the - * transition to master which will not contain any representation of a {@link DiscoveryNode}. - */ - DiscoveryNode convertToDiscoveryNode() { - return new DiscoveryNode(name, nodeId, "", "", "", new TransportAddress(TransportAddress.META_ADDRESS, 0), - Collections.emptyMap(), Collections.emptySet(), Version.CURRENT); - } - @Override public boolean equals(Object obj) { if (obj == null) { @@ -125,10 +107,7 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte } } - private List nodes; - - private ClusterName clusterName; - + private List nodes; private static final ObjectParser PARSER = new ObjectParser<>(VerifyRepositoryResponse.class.getName(), VerifyRepositoryResponse::new); @@ -139,43 +118,28 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte VerifyRepositoryResponse() { } - public VerifyRepositoryResponse(ClusterName clusterName, DiscoveryNode[] nodes) { - this.clusterName = clusterName; - this.nodes = Arrays.asList(nodes); + public VerifyRepositoryResponse(DiscoveryNode[] nodes) { + this.nodes = Arrays.stream(nodes).map(dn -> new NodeView(dn.getId(), dn.getName())).collect(Collectors.toList()); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - if (in.getVersion().onOrAfter(Version.V_6_4_0)) { - this.nodes = in.readList(NodeView::new).stream().map(n -> n.convertToDiscoveryNode()).collect(Collectors.toList()); - } else { - clusterName = new ClusterName(in); - this.nodes = in.readList(DiscoveryNode::new); - } + this.nodes = in.readList(NodeView::new); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_6_4_0)) { - out.writeList(getNodes()); - } else { - clusterName.writeTo(out); - out.writeList(nodes); - } + out.writeList(nodes); } public List getNodes() { - return nodes.stream().map(dn -> new NodeView(dn.getId(), dn.getName())).collect(Collectors.toList()); - } - - public ClusterName getClusterName() { - return clusterName; + return nodes; } protected void setNodes(List nodes) { - this.nodes = nodes.stream().map(n -> n.convertToDiscoveryNode()).collect(Collectors.toList()); + this.nodes = nodes; } @Override @@ -184,12 +148,8 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte { builder.startObject(NODES); { - for (DiscoveryNode node : nodes) { - builder.startObject(node.getId()); - { - builder.field(NAME, node.getName()); - } - builder.endObject(); + for (NodeView node : nodes) { + node.toXContent(builder, params); } } builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java index 70a39d2d329..4366465ac69 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.admin.cluster.reroute; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ClusterRerouteAction extends Action { +public class ClusterRerouteAction extends Action { public static final ClusterRerouteAction INSTANCE = new ClusterRerouteAction(); public static final String NAME = "cluster:admin/reroute"; @@ -35,9 +34,4 @@ public class ClusterRerouteAction extends Action { +public class ClusterUpdateSettingsAction extends Action { public static final ClusterUpdateSettingsAction INSTANCE = new ClusterUpdateSettingsAction(); public static final String NAME = "cluster:admin/settings/update"; @@ -35,9 +34,4 @@ public class ClusterUpdateSettingsAction extends Action { +public class ClusterSearchShardsAction extends Action { public static final ClusterSearchShardsAction INSTANCE = new ClusterSearchShardsAction(); public static final String NAME = "indices:admin/shards/search_shards"; @@ -35,9 +34,4 @@ public class ClusterSearchShardsAction extends Action { +public class CreateSnapshotAction extends Action { public static final CreateSnapshotAction INSTANCE = new CreateSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/create"; @@ -38,10 +37,5 @@ public class CreateSnapshotAction extends Action { +public class DeleteSnapshotAction extends Action { public static final DeleteSnapshotAction INSTANCE = new DeleteSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/delete"; @@ -38,10 +37,5 @@ public class DeleteSnapshotAction extends Action { +public class GetSnapshotsAction extends Action { public static final GetSnapshotsAction INSTANCE = new GetSnapshotsAction(); public static final String NAME = "cluster:admin/snapshot/get"; @@ -38,10 +37,5 @@ public class GetSnapshotsAction extends Action { +public class RestoreSnapshotAction extends Action { public static final RestoreSnapshotAction INSTANCE = new RestoreSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/restore"; @@ -38,10 +37,5 @@ public class RestoreSnapshotAction extends Action { +public class SnapshotsStatusAction extends Action { public static final SnapshotsStatusAction INSTANCE = new SnapshotsStatusAction(); public static final String NAME = "cluster:admin/snapshot/status"; @@ -38,10 +37,5 @@ public class SnapshotsStatusAction extends Action { +public class ClusterStateAction extends Action { public static final ClusterStateAction INSTANCE = new ClusterStateAction(); public static final String NAME = "cluster:monitor/state"; @@ -35,9 +34,4 @@ public class ClusterStateAction extends Action { +public class ClusterStatsAction extends Action { public static final ClusterStatsAction INSTANCE = new ClusterStatsAction(); public static final String NAME = "cluster:monitor/stats"; @@ -35,9 +34,4 @@ public class ClusterStatsAction extends Action { +public class DeleteStoredScriptAction extends Action { public static final DeleteStoredScriptAction INSTANCE = new DeleteStoredScriptAction(); public static final String NAME = "cluster:admin/script/delete"; @@ -36,9 +34,4 @@ public class DeleteStoredScriptAction extends Action { +public class GetStoredScriptAction extends Action { public static final GetStoredScriptAction INSTANCE = new GetStoredScriptAction(); public static final String NAME = "cluster:admin/script/get"; @@ -36,10 +34,4 @@ public class GetStoredScriptAction extends Action { +public class PutStoredScriptAction extends Action { public static final PutStoredScriptAction INSTANCE = new PutStoredScriptAction(); public static final String NAME = "cluster:admin/script/put"; @@ -39,9 +38,4 @@ public class PutStoredScriptAction extends Action { +public class PendingClusterTasksAction extends Action { public static final PendingClusterTasksAction INSTANCE = new PendingClusterTasksAction(); public static final String NAME = "cluster:monitor/task"; @@ -35,9 +34,4 @@ public class PendingClusterTasksAction extends Action { +public class IndicesAliasesAction extends Action { public static final IndicesAliasesAction INSTANCE = new IndicesAliasesAction(); public static final String NAME = "indices:admin/aliases"; @@ -35,9 +34,4 @@ public class IndicesAliasesAction extends Action { +public class AliasesExistAction extends Action { public static final AliasesExistAction INSTANCE = new AliasesExistAction(); public static final String NAME = "indices:admin/aliases/exists"; @@ -32,11 +31,6 @@ public class AliasesExistAction extends Action> extends MasterNodeReadOperationRequestBuilder { - public BaseAliasesRequestBuilder(ElasticsearchClient client, Action action, String... aliases) { + public BaseAliasesRequestBuilder(ElasticsearchClient client, Action action, String... aliases) { super(client, action, new GetAliasesRequest(aliases)); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java index 71badddacab..d8f2453c2cb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.admin.indices.alias.get; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class GetAliasesAction extends Action { +public class GetAliasesAction extends Action { public static final GetAliasesAction INSTANCE = new GetAliasesAction(); public static final String NAME = "indices:admin/aliases/get"; @@ -31,11 +30,6 @@ public class GetAliasesAction extends Action { +public class AnalyzeAction extends Action { public static final AnalyzeAction INSTANCE = new AnalyzeAction(); public static final String NAME = "indices:admin/analyze"; @@ -35,9 +34,4 @@ public class AnalyzeAction extends Action { +public class ClearIndicesCacheAction extends Action { public static final ClearIndicesCacheAction INSTANCE = new ClearIndicesCacheAction(); public static final String NAME = "indices:admin/cache/clear"; @@ -35,9 +34,4 @@ public class ClearIndicesCacheAction extends Action { +public class CloseIndexAction extends Action { public static final CloseIndexAction INSTANCE = new CloseIndexAction(); public static final String NAME = "indices:admin/close"; @@ -35,9 +34,4 @@ public class CloseIndexAction extends Action { +public class CreateIndexAction extends Action { public static final CreateIndexAction INSTANCE = new CreateIndexAction(); public static final String NAME = "indices:admin/create"; @@ -35,9 +34,4 @@ public class CreateIndexAction extends Action { +public class DeleteIndexAction extends Action { public static final DeleteIndexAction INSTANCE = new DeleteIndexAction(); public static final String NAME = "indices:admin/delete"; @@ -35,9 +34,4 @@ public class DeleteIndexAction extends Action { +public class IndicesExistsAction extends Action { public static final IndicesExistsAction INSTANCE = new IndicesExistsAction(); public static final String NAME = "indices:admin/exists"; @@ -35,9 +34,4 @@ public class IndicesExistsAction extends Action { +public class TypesExistsAction extends Action { public static final TypesExistsAction INSTANCE = new TypesExistsAction(); public static final String NAME = "indices:admin/types/exists"; @@ -34,9 +33,4 @@ public class TypesExistsAction extends Action { +public class FlushAction extends Action { public static final FlushAction INSTANCE = new FlushAction(); public static final String NAME = "indices:admin/flush"; @@ -35,9 +34,4 @@ public class FlushAction extends Action { +public class SyncedFlushAction extends Action { public static final SyncedFlushAction INSTANCE = new SyncedFlushAction(); public static final String NAME = "indices:admin/synced_flush"; @@ -36,9 +35,4 @@ public class SyncedFlushAction extends Action { +public class SyncedFlushRequestBuilder extends ActionRequestBuilder { public SyncedFlushRequestBuilder(ElasticsearchClient client, SyncedFlushAction action) { super(client, action, new SyncedFlushRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeAction.java index 656c5b91a70..524d4133301 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.admin.indices.forcemerge; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ForceMergeAction extends Action { +public class ForceMergeAction extends Action { public static final ForceMergeAction INSTANCE = new ForceMergeAction(); public static final String NAME = "indices:admin/forcemerge"; @@ -35,9 +34,4 @@ public class ForceMergeAction extends Action { +public class GetIndexAction extends Action { public static final GetIndexAction INSTANCE = new GetIndexAction(); public static final String NAME = "indices:admin/get"; @@ -31,11 +30,6 @@ public class GetIndexAction extends Action { +public class GetFieldMappingsAction extends Action { public static final GetFieldMappingsAction INSTANCE = new GetFieldMappingsAction(); public static final String NAME = "indices:admin/mappings/fields/get"; @@ -31,11 +30,6 @@ public class GetFieldMappingsAction extends Action { +public class GetFieldMappingsRequestBuilder extends ActionRequestBuilder { public GetFieldMappingsRequestBuilder(ElasticsearchClient client, GetFieldMappingsAction action, String... indices) { super(client, action, new GetFieldMappingsRequest().indices(indices)); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java index 5a9425cadec..08042baa803 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.admin.indices.mapping.get; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class GetMappingsAction extends Action { +public class GetMappingsAction extends Action { public static final GetMappingsAction INSTANCE = new GetMappingsAction(); public static final String NAME = "indices:admin/mappings/get"; @@ -31,11 +30,6 @@ public class GetMappingsAction extends Action { +public class PutMappingAction extends Action { public static final PutMappingAction INSTANCE = new PutMappingAction(); public static final String NAME = "indices:admin/mapping/put"; @@ -35,9 +34,4 @@ public class PutMappingAction extends Action { +public class OpenIndexAction extends Action { public static final OpenIndexAction INSTANCE = new OpenIndexAction(); public static final String NAME = "indices:admin/open"; @@ -35,9 +34,4 @@ public class OpenIndexAction extends Action { +public class RecoveryAction extends Action { public static final RecoveryAction INSTANCE = new RecoveryAction(); public static final String NAME = "indices:monitor/recovery"; @@ -34,11 +33,6 @@ public class RecoveryAction extends Action { +public class RefreshAction extends Action { public static final RefreshAction INSTANCE = new RefreshAction(); public static final String NAME = "indices:admin/refresh"; @@ -35,9 +34,4 @@ public class RefreshAction extends Action { +public class RolloverAction extends Action { public static final RolloverAction INSTANCE = new RolloverAction(); public static final String NAME = "indices:admin/rollover"; @@ -35,9 +34,4 @@ public class RolloverAction extends Action { +public class IndicesSegmentsAction extends Action { public static final IndicesSegmentsAction INSTANCE = new IndicesSegmentsAction(); public static final String NAME = "indices:monitor/segments"; @@ -35,9 +34,4 @@ public class IndicesSegmentsAction extends Action { +public class GetSettingsAction extends Action { public static final GetSettingsAction INSTANCE = new GetSettingsAction(); public static final String NAME = "indices:monitor/settings/get"; @@ -31,11 +30,6 @@ public class GetSettingsAction extends Action { +public class UpdateSettingsAction extends Action { public static final UpdateSettingsAction INSTANCE = new UpdateSettingsAction(); public static final String NAME = "indices:admin/settings/update"; @@ -35,9 +34,4 @@ public class UpdateSettingsAction extends Action { - public IndicesShardStoreRequestBuilder(ElasticsearchClient client, Action action, String... indices) { + public IndicesShardStoreRequestBuilder(ElasticsearchClient client, Action action, String... indices) { super(client, action, new IndicesShardStoresRequest(indices)); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresAction.java index 6475d92ccbd..8bb08ee0f09 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresAction.java @@ -20,7 +20,6 @@ package org.elasticsearch.action.admin.indices.shards; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for {@link TransportIndicesShardStoresAction} @@ -29,7 +28,7 @@ import org.elasticsearch.client.ElasticsearchClient; * Shard store information reports which nodes hold shard copies, how recent they are * and any exceptions on opening the shard index or from previous engine failures */ -public class IndicesShardStoresAction extends Action { +public class IndicesShardStoresAction extends Action { public static final IndicesShardStoresAction INSTANCE = new IndicesShardStoresAction(); public static final String NAME = "indices:monitor/shard_stores"; @@ -42,9 +41,4 @@ public class IndicesShardStoresAction extends Action { +public class ResizeAction extends Action { public static final ResizeAction INSTANCE = new ResizeAction(); public static final String NAME = "indices:admin/resize"; @@ -37,9 +36,4 @@ public class ResizeAction extends Action { - public ResizeRequestBuilder(ElasticsearchClient client, Action action) { + public ResizeRequestBuilder(ElasticsearchClient client, Action action) { super(client, action, new ResizeRequest()); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkAction.java index 48c23d643ba..cddc8390b54 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.admin.indices.shrink; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ShrinkAction extends Action { +public class ShrinkAction extends Action { public static final ShrinkAction INSTANCE = new ShrinkAction(); public static final String NAME = "indices:admin/shrink"; @@ -35,9 +34,4 @@ public class ShrinkAction extends Action { +public class IndicesStatsAction extends Action { public static final IndicesStatsAction INSTANCE = new IndicesStatsAction(); public static final String NAME = "indices:monitor/stats"; @@ -35,9 +34,4 @@ public class IndicesStatsAction extends Action { +public class DeleteIndexTemplateAction extends Action { public static final DeleteIndexTemplateAction INSTANCE = new DeleteIndexTemplateAction(); public static final String NAME = "indices:admin/template/delete"; @@ -35,9 +34,4 @@ public class DeleteIndexTemplateAction extends Action { +public class GetIndexTemplatesAction extends Action { public static final GetIndexTemplatesAction INSTANCE = new GetIndexTemplatesAction(); public static final String NAME = "indices:admin/template/get"; @@ -34,9 +33,4 @@ public class GetIndexTemplatesAction extends Action { +public class PutIndexTemplateAction extends Action { public static final PutIndexTemplateAction INSTANCE = new PutIndexTemplateAction(); public static final String NAME = "indices:admin/template/put"; @@ -35,9 +34,4 @@ public class PutIndexTemplateAction extends Action { +public class UpgradeStatusAction extends Action { public static final UpgradeStatusAction INSTANCE = new UpgradeStatusAction(); public static final String NAME = "indices:monitor/upgrade"; @@ -35,9 +34,4 @@ public class UpgradeStatusAction extends Action { +public class UpgradeAction extends Action { public static final UpgradeAction INSTANCE = new UpgradeAction(); public static final String NAME = "indices:admin/upgrade"; @@ -38,9 +37,4 @@ public class UpgradeAction extends Action { +public class UpgradeSettingsAction extends Action { public static final UpgradeSettingsAction INSTANCE = new UpgradeSettingsAction(); public static final String NAME = "internal:indices/admin/upgrade"; @@ -35,9 +34,4 @@ public class UpgradeSettingsAction extends Action { +public class ValidateQueryAction extends Action { public static final ValidateQueryAction INSTANCE = new ValidateQueryAction(); public static final String NAME = "indices:admin/validate/query"; @@ -35,9 +34,4 @@ public class ValidateQueryAction extends Action { +public class BulkAction extends Action { public static final BulkAction INSTANCE = new BulkAction(); public static final String NAME = "indices:data/write/bulk"; @@ -38,11 +37,6 @@ public class BulkAction extends Action +public class BulkRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public BulkRequestBuilder(ElasticsearchClient client, BulkAction action) { diff --git a/server/src/main/java/org/elasticsearch/action/delete/DeleteAction.java b/server/src/main/java/org/elasticsearch/action/delete/DeleteAction.java index 09aa9f58656..23306d5db11 100644 --- a/server/src/main/java/org/elasticsearch/action/delete/DeleteAction.java +++ b/server/src/main/java/org/elasticsearch/action/delete/DeleteAction.java @@ -22,7 +22,7 @@ package org.elasticsearch.action.delete; import org.elasticsearch.action.Action; import org.elasticsearch.client.ElasticsearchClient; -public class DeleteAction extends Action { +public class DeleteAction extends Action { public static final DeleteAction INSTANCE = new DeleteAction(); public static final String NAME = "indices:data/write/delete"; @@ -35,9 +35,4 @@ public class DeleteAction extends Action { +public class ExplainAction extends Action { public static final ExplainAction INSTANCE = new ExplainAction(); public static final String NAME = "indices:data/read/explain"; @@ -34,11 +33,6 @@ public class ExplainAction extends Action { +public class FieldCapabilitiesAction extends Action { public static final FieldCapabilitiesAction INSTANCE = new FieldCapabilitiesAction(); public static final String NAME = "indices:data/read/field_caps"; @@ -36,9 +34,4 @@ public class FieldCapabilitiesAction extends Action { +public class FieldCapabilitiesRequestBuilder extends ActionRequestBuilder { public FieldCapabilitiesRequestBuilder(ElasticsearchClient client, FieldCapabilitiesAction action, String... indices) { diff --git a/server/src/main/java/org/elasticsearch/action/get/GetAction.java b/server/src/main/java/org/elasticsearch/action/get/GetAction.java index 69c67b1be2b..c9df5ffb98e 100644 --- a/server/src/main/java/org/elasticsearch/action/get/GetAction.java +++ b/server/src/main/java/org/elasticsearch/action/get/GetAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.get; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class GetAction extends Action { +public class GetAction extends Action { public static final GetAction INSTANCE = new GetAction(); public static final String NAME = "indices:data/read/get"; @@ -35,9 +34,4 @@ public class GetAction extends Action { +public class MultiGetAction extends Action { public static final MultiGetAction INSTANCE = new MultiGetAction(); public static final String NAME = "indices:data/read/mget"; @@ -35,9 +34,4 @@ public class MultiGetAction extends Action { +public class MultiGetRequestBuilder extends ActionRequestBuilder { public MultiGetRequestBuilder(ElasticsearchClient client, MultiGetAction action) { super(client, action, new MultiGetRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexAction.java b/server/src/main/java/org/elasticsearch/action/index/IndexAction.java index fa2bd06f297..1f72369d9db 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexAction.java @@ -22,7 +22,7 @@ package org.elasticsearch.action.index; import org.elasticsearch.action.Action; import org.elasticsearch.client.ElasticsearchClient; -public class IndexAction extends Action { +public class IndexAction extends Action { public static final IndexAction INSTANCE = new IndexAction(); public static final String NAME = "indices:data/write/index"; @@ -35,9 +35,4 @@ public class IndexAction extends Action { +public class DeletePipelineAction extends Action { public static final DeletePipelineAction INSTANCE = new DeletePipelineAction(); public static final String NAME = "cluster:admin/ingest/pipeline/delete"; @@ -31,11 +30,6 @@ public class DeletePipelineAction extends Action { +public class DeletePipelineRequestBuilder extends ActionRequestBuilder { public DeletePipelineRequestBuilder(ElasticsearchClient client, DeletePipelineAction action) { super(client, action, new DeletePipelineRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/ingest/GetPipelineAction.java b/server/src/main/java/org/elasticsearch/action/ingest/GetPipelineAction.java index f6bc3d9a778..82e1a546b6e 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/GetPipelineAction.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/GetPipelineAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class GetPipelineAction extends Action { +public class GetPipelineAction extends Action { public static final GetPipelineAction INSTANCE = new GetPipelineAction(); public static final String NAME = "cluster:admin/ingest/pipeline/get"; @@ -31,11 +30,6 @@ public class GetPipelineAction extends Action pipelines() { - return pipelines; + return Collections.unmodifiableList(pipelines); } @Override @@ -83,4 +96,66 @@ public class GetPipelineResponse extends ActionResponse implements StatusToXCont builder.endObject(); return builder; } + + /** + * + * @param parser the parser for the XContent that contains the serialized GetPipelineResponse. + * @return an instance of GetPipelineResponse read from the parser + * @throws IOException If the parsing fails + */ + public static GetPipelineResponse fromXContent(XContentParser parser) throws IOException { + ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); + List pipelines = new ArrayList<>(); + while(parser.nextToken().equals(Token.FIELD_NAME)) { + String pipelineId = parser.currentName(); + parser.nextToken(); + XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent()); + contentBuilder.generator().copyCurrentStructure(parser); + PipelineConfiguration pipeline = + new PipelineConfiguration( + pipelineId, BytesReference.bytes(contentBuilder), contentBuilder.contentType() + ); + pipelines.add(pipeline); + } + ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.currentToken(), parser::getTokenLocation); + return new GetPipelineResponse(pipelines); + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } else if (other instanceof GetPipelineResponse){ + GetPipelineResponse otherResponse = (GetPipelineResponse)other; + if (pipelines == null) { + return otherResponse.pipelines == null; + } else { + // We need a map here because order does not matter for equality + Map otherPipelineMap = new HashMap<>(); + for (PipelineConfiguration pipeline: otherResponse.pipelines) { + otherPipelineMap.put(pipeline.getId(), pipeline); + } + for (PipelineConfiguration pipeline: pipelines) { + PipelineConfiguration otherPipeline = otherPipelineMap.get(pipeline.getId()); + if (!pipeline.equals(otherPipeline)) { + return false; + } + } + return true; + } + } else { + return false; + } + } + + @Override + public int hashCode() { + int result = 1; + for (PipelineConfiguration pipeline: pipelines) { + // We only take the sum here to ensure that the order does not matter. + result += (pipeline == null ? 0 : pipeline.hashCode()); + } + return result; + } + } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java index 8b163eb1eed..991e2332207 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java @@ -47,7 +47,7 @@ public final class IngestActionForwarder implements ClusterStateApplier { ingestNodes = new DiscoveryNode[0]; } - public void forwardIngestRequest(Action action, ActionRequest request, ActionListener listener) { + public void forwardIngestRequest(Action action, ActionRequest request, ActionListener listener) { transportService.sendRequest(randomIngestNode(), action.name(), request, new ActionListenerResponseHandler(listener, action::newResponse)); } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineAction.java b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineAction.java index 8f4b4170f51..068cbea0839 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineAction.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineAction.java @@ -20,10 +20,8 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.Action; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.client.ElasticsearchClient; -public class PutPipelineAction extends Action { +public class PutPipelineAction extends Action { public static final PutPipelineAction INSTANCE = new PutPipelineAction(); public static final String NAME = "cluster:admin/ingest/pipeline/put"; @@ -32,11 +30,6 @@ public class PutPipelineAction extends Action { +public class PutPipelineRequestBuilder extends ActionRequestBuilder { public PutPipelineRequestBuilder(ElasticsearchClient client, PutPipelineAction action) { super(client, action, new PutPipelineRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineResponse.java b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineResponse.java deleted file mode 100644 index 13960ca99ef..00000000000 --- a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineResponse.java +++ /dev/null @@ -1,62 +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.action.ingest; - -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.io.IOException; - -public class PutPipelineResponse extends AcknowledgedResponse implements ToXContentObject { - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "cluster_put_pipeline", true, args -> new PutPipelineResponse((boolean) args[0])); - - static { - declareAcknowledgedField(PARSER); - } - - public PutPipelineResponse() { - } - - public PutPipelineResponse(boolean acknowledged) { - super(acknowledged); - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - - public static PutPipelineResponse fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } -} diff --git a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineAction.java b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineAction.java index c1d219a4190..4da35ba25b7 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineAction.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class SimulatePipelineAction extends Action { +public class SimulatePipelineAction extends Action { public static final SimulatePipelineAction INSTANCE = new SimulatePipelineAction(); public static final String NAME = "cluster:admin/ingest/pipeline/simulate"; @@ -31,11 +30,6 @@ public class SimulatePipelineAction extends Action { +public class SimulatePipelineRequestBuilder extends ActionRequestBuilder { /** * Create a new builder for {@link SimulatePipelineRequest}s diff --git a/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java b/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java index ced6085e0ac..36301d6735a 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java @@ -22,10 +22,20 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -public class WritePipelineResponse extends AcknowledgedResponse { +public class WritePipelineResponse extends AcknowledgedResponse implements ToXContentObject { + + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "write_pipeline_response", true, args -> new WritePipelineResponse((boolean) args[0])); + + static { + declareAcknowledgedField(PARSER); + } WritePipelineResponse() { @@ -46,4 +56,8 @@ public class WritePipelineResponse extends AcknowledgedResponse { super.writeTo(out); writeAcknowledged(out); } + + public static WritePipelineResponse fromXContent(XContentParser parser) { + return PARSER.apply(parser, null); + } } diff --git a/server/src/main/java/org/elasticsearch/action/main/MainAction.java b/server/src/main/java/org/elasticsearch/action/main/MainAction.java index 355c2a3434c..10fd1f9887c 100644 --- a/server/src/main/java/org/elasticsearch/action/main/MainAction.java +++ b/server/src/main/java/org/elasticsearch/action/main/MainAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.main; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class MainAction extends Action { +public class MainAction extends Action { public static final String NAME = "cluster:monitor/main"; public static final MainAction INSTANCE = new MainAction(); @@ -31,11 +30,6 @@ public class MainAction extends Action { +public class MainRequestBuilder extends ActionRequestBuilder { public MainRequestBuilder(ElasticsearchClient client, MainAction action) { super(client, action, new MainRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java b/server/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java index 151635ac93f..4edda430c5c 100644 --- a/server/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ClearScrollAction extends Action { +public class ClearScrollAction extends Action { public static final ClearScrollAction INSTANCE = new ClearScrollAction(); public static final String NAME = "indices:data/read/scroll/clear"; @@ -35,9 +34,4 @@ public class ClearScrollAction extends Action { +public class ClearScrollRequestBuilder extends ActionRequestBuilder { public ClearScrollRequestBuilder(ElasticsearchClient client, ClearScrollAction action) { super(client, action, new ClearScrollRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java b/server/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java index 04651c00c02..c2c8c4ce232 100644 --- a/server/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class MultiSearchAction extends Action { +public class MultiSearchAction extends Action { public static final MultiSearchAction INSTANCE = new MultiSearchAction(); public static final String NAME = "indices:data/read/msearch"; @@ -35,9 +34,4 @@ public class MultiSearchAction extends Action { +public class MultiSearchRequestBuilder extends ActionRequestBuilder { public MultiSearchRequestBuilder(ElasticsearchClient client, MultiSearchAction action) { super(client, action, new MultiSearchRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchAction.java b/server/src/main/java/org/elasticsearch/action/search/SearchAction.java index 38a77fa772a..80bc1abcca8 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class SearchAction extends Action { +public class SearchAction extends Action { public static final SearchAction INSTANCE = new SearchAction(); public static final String NAME = "indices:data/read/search"; @@ -35,9 +34,4 @@ public class SearchAction extends Action { +public class SearchRequestBuilder extends ActionRequestBuilder { public SearchRequestBuilder(ElasticsearchClient client, SearchAction action) { super(client, action, new SearchRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java b/server/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java index 6bd23f7741a..209e3c7f583 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class SearchScrollAction extends Action { +public class SearchScrollAction extends Action { public static final SearchScrollAction INSTANCE = new SearchScrollAction(); public static final String NAME = "indices:data/read/scroll"; @@ -35,9 +34,4 @@ public class SearchScrollAction extends Action { +public class SearchScrollRequestBuilder extends ActionRequestBuilder { public SearchScrollRequestBuilder(ElasticsearchClient client, SearchScrollAction action) { super(client, action, new SearchScrollRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java index fb995513acb..056381cc7dc 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java @@ -25,9 +25,9 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.ElasticsearchClient; public abstract class BroadcastOperationRequestBuilder, Response extends BroadcastResponse, RequestBuilder extends BroadcastOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected BroadcastOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected BroadcastOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java index 6a4a2b9c0d7..45d92801170 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.unit.TimeValue; public abstract class AcknowledgedRequestBuilder, Response extends AcknowledgedResponse, RequestBuilder extends AcknowledgedRequestBuilder> extends MasterNodeOperationRequestBuilder { - protected AcknowledgedRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected AcknowledgedRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java index 0b3b5af36d2..1302d2003da 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java @@ -29,9 +29,9 @@ import org.elasticsearch.common.unit.TimeValue; * Base request builder for master node operations */ public abstract class MasterNodeOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected MasterNodeOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected MasterNodeOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java index 7955abfbe96..96735f101e6 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java @@ -29,7 +29,7 @@ import org.elasticsearch.client.ElasticsearchClient; public abstract class MasterNodeReadOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeReadOperationRequestBuilder> extends MasterNodeOperationRequestBuilder { - protected MasterNodeReadOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected MasterNodeReadOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java index 96e0ad8ee6b..26dedf15da8 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.util.ArrayUtils; public abstract class ClusterInfoRequestBuilder, Response extends ActionResponse, Builder extends ClusterInfoRequestBuilder> extends MasterNodeReadOperationRequestBuilder { - protected ClusterInfoRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected ClusterInfoRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java index ffb43e7ee04..37c06a41958 100644 --- a/server/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java @@ -25,9 +25,9 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; public abstract class NodesOperationRequestBuilder, Response extends BaseNodesResponse, RequestBuilder extends NodesOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected NodesOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected NodesOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/replication/ReplicationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/replication/ReplicationRequestBuilder.java index 15d36ad3467..32fbaf70ab3 100644 --- a/server/src/main/java/org/elasticsearch/action/support/replication/ReplicationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/replication/ReplicationRequestBuilder.java @@ -27,9 +27,9 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; public abstract class ReplicationRequestBuilder, Response extends ActionResponse, RequestBuilder extends ReplicationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected ReplicationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected ReplicationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java index 9e7a48dc49e..0c5d26b0aed 100644 --- a/server/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java @@ -26,9 +26,9 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; public abstract class InstanceShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends InstanceShardOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected InstanceShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected InstanceShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java index af6ee2287f2..1de3479fb5d 100644 --- a/server/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java @@ -25,9 +25,9 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.ElasticsearchClient; public abstract class SingleShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleShardOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected SingleShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected SingleShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java index 656dae99928..cda4497437a 100644 --- a/server/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/tasks/TasksRequestBuilder.java @@ -31,9 +31,9 @@ public class TasksRequestBuilder< Request extends BaseTasksRequest, Response extends BaseTasksResponse, RequestBuilder extends TasksRequestBuilder - > extends ActionRequestBuilder { + > extends ActionRequestBuilder { - protected TasksRequestBuilder(ElasticsearchClient client, Action action, Request request) { + protected TasksRequestBuilder(ElasticsearchClient client, Action action, Request request) { super(client, action, request); } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java index a84ba25f5bb..f7a9eda6cc2 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.termvectors; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class MultiTermVectorsAction extends Action { +public class MultiTermVectorsAction extends Action { public static final MultiTermVectorsAction INSTANCE = new MultiTermVectorsAction(); public static final String NAME = "indices:data/read/mtv"; @@ -35,9 +34,4 @@ public class MultiTermVectorsAction extends Action { +public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder { public MultiTermVectorsRequestBuilder(ElasticsearchClient client, MultiTermVectorsAction action) { super(client, action, new MultiTermVectorsRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java index 982f7ad52c1..ded987c52a0 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.action.termvectors; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class TermVectorsAction extends Action { +public class TermVectorsAction extends Action { public static final TermVectorsAction INSTANCE = new TermVectorsAction(); public static final String NAME = "indices:data/read/tv"; @@ -35,9 +34,4 @@ public class TermVectorsAction extends Action { +public class TermVectorsRequestBuilder extends ActionRequestBuilder { public TermVectorsRequestBuilder(ElasticsearchClient client, TermVectorsAction action) { super(client, action, new TermVectorsRequest()); diff --git a/server/src/main/java/org/elasticsearch/action/update/UpdateAction.java b/server/src/main/java/org/elasticsearch/action/update/UpdateAction.java index 7d7997a7a0b..039939e752b 100644 --- a/server/src/main/java/org/elasticsearch/action/update/UpdateAction.java +++ b/server/src/main/java/org/elasticsearch/action/update/UpdateAction.java @@ -22,7 +22,7 @@ package org.elasticsearch.action.update; import org.elasticsearch.action.Action; import org.elasticsearch.client.ElasticsearchClient; -public class UpdateAction extends Action { +public class UpdateAction extends Action { public static final UpdateAction INSTANCE = new UpdateAction(); public static final String NAME = "indices:data/write/update"; @@ -35,9 +35,4 @@ public class UpdateAction extends Action The request type. * @param the response type. - * @param The request builder type. * @return A future allowing to get back the response. */ - > ActionFuture execute( - Action action, Request request); + ActionFuture execute( + Action action, Request request); /** * Executes a generic action, denoted by an {@link Action}. @@ -51,22 +50,9 @@ public interface ElasticsearchClient { * @param listener The listener to receive the response back. * @param The request type. * @param The response type. - * @param The request builder type. */ - > void execute( - Action action, Request request, ActionListener listener); - - /** - * Prepares a request builder to execute, specified by {@link Action}. - * - * @param action The action type to execute. - * @param The request type. - * @param The response type. - * @param The request builder. - * @return The request builder, that can, at a later stage, execute the request. - */ - > RequestBuilder prepareExecute( - Action action); + void execute( + Action action, Request request, ActionListener listener); /** * Returns the threadpool used to execute requests on this client diff --git a/server/src/main/java/org/elasticsearch/client/FilterClient.java b/server/src/main/java/org/elasticsearch/client/FilterClient.java index 92f6817b74b..ac94cdf0176 100644 --- a/server/src/main/java/org/elasticsearch/client/FilterClient.java +++ b/server/src/main/java/org/elasticsearch/client/FilterClient.java @@ -62,8 +62,8 @@ public abstract class FilterClient extends AbstractClient { } @Override - protected > void doExecute( - Action action, Request request, ActionListener listener) { + protected > void doExecute( + Action action, Request request, ActionListener listener) { in().execute(action, request, listener); } diff --git a/server/src/main/java/org/elasticsearch/client/ParentTaskAssigningClient.java b/server/src/main/java/org/elasticsearch/client/ParentTaskAssigningClient.java index 62843c41b70..180c0f21b8d 100644 --- a/server/src/main/java/org/elasticsearch/client/ParentTaskAssigningClient.java +++ b/server/src/main/java/org/elasticsearch/client/ParentTaskAssigningClient.java @@ -60,8 +60,8 @@ public class ParentTaskAssigningClient extends FilterClient { @Override protected < Request extends ActionRequest, Response extends ActionResponse, - RequestBuilder extends ActionRequestBuilder - > void doExecute(Action action, Request request, ActionListener listener) { + RequestBuilder extends ActionRequestBuilder + > void doExecute(Action action, Request request, ActionListener listener) { request.setParentTask(parentTask); super.doExecute(action, request, listener); } diff --git a/server/src/main/java/org/elasticsearch/client/node/NodeClient.java b/server/src/main/java/org/elasticsearch/client/node/NodeClient.java index 69bf5d21f7a..3f214c90b67 100644 --- a/server/src/main/java/org/elasticsearch/client/node/NodeClient.java +++ b/server/src/main/java/org/elasticsearch/client/node/NodeClient.java @@ -70,8 +70,8 @@ public class NodeClient extends AbstractClient { @Override public < Request extends ActionRequest, Response extends ActionResponse, - RequestBuilder extends ActionRequestBuilder - > void doExecute(Action action, Request request, ActionListener listener) { + RequestBuilder extends ActionRequestBuilder + > void doExecute(Action action, Request request, ActionListener listener) { // Discard the task because the Client interface doesn't use it. executeLocally(action, request, listener); } diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index c0da35a3079..41c1d245d39 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -382,14 +382,8 @@ public abstract class AbstractClient extends AbstractComponent implements Client } @Override - public final > RequestBuilder prepareExecute( - final Action action) { - return action.newRequestBuilder(this); - } - - @Override - public final > ActionFuture execute( - Action action, Request request) { + public final ActionFuture execute( + Action action, Request request) { PlainActionFuture actionFuture = PlainActionFuture.newFuture(); execute(action, request, actionFuture); return actionFuture; @@ -399,13 +393,13 @@ public abstract class AbstractClient extends AbstractComponent implements Client * This is the single execution point of *all* clients. */ @Override - public final > void execute( - Action action, Request request, ActionListener listener) { + public final void execute( + Action action, Request request, ActionListener listener) { listener = threadedWrapper.wrap(listener); doExecute(action, request, listener); } - protected abstract > void doExecute(Action action, Request request, ActionListener listener); + protected abstract > void doExecute(Action action, Request request, ActionListener listener); @Override public ActionFuture index(final IndexRequest request) { @@ -701,23 +695,17 @@ public abstract class AbstractClient extends AbstractComponent implements Client } @Override - public > ActionFuture execute( - Action action, Request request) { + public ActionFuture execute( + Action action, Request request) { return client.execute(action, request); } @Override - public > void execute( - Action action, Request request, ActionListener listener) { + public void execute( + Action action, Request request, ActionListener listener) { client.execute(action, request, listener); } - @Override - public > RequestBuilder prepareExecute( - Action action) { - return client.prepareExecute(action); - } - @Override public ThreadPool threadPool() { return client.threadPool(); @@ -1224,7 +1212,7 @@ public abstract class AbstractClient extends AbstractComponent implements Client @Override public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(){ - return DeleteStoredScriptAction.INSTANCE.newRequestBuilder(this); + return new DeleteStoredScriptRequestBuilder(client, DeleteStoredScriptAction.INSTANCE); } @Override @@ -1242,23 +1230,17 @@ public abstract class AbstractClient extends AbstractComponent implements Client } @Override - public > ActionFuture execute( - Action action, Request request) { + public ActionFuture execute( + Action action, Request request) { return client.execute(action, request); } @Override - public > void execute( - Action action, Request request, ActionListener listener) { + public void execute( + Action action, Request request, ActionListener listener) { client.execute(action, request, listener); } - @Override - public > RequestBuilder prepareExecute( - Action action) { - return client.prepareExecute(action); - } - @Override public ThreadPool threadPool() { return client.threadPool(); @@ -1775,7 +1757,7 @@ public abstract class AbstractClient extends AbstractComponent implements Client public Client filterWithHeader(Map headers) { return new FilterClient(this) { @Override - protected > void doExecute(Action action, Request request, ActionListener listener) { + protected > void doExecute(Action action, Request request, ActionListener listener) { ThreadContext threadContext = threadPool().getThreadContext(); try (ThreadContext.StoredContext ctx = threadContext.stashAndMergeHeaders(headers)) { super.doExecute(action, request, listener); diff --git a/server/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/server/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 2aeea08d1a5..40904e9a824 100644 --- a/server/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/server/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -98,6 +98,8 @@ public abstract class TransportClient extends AbstractClient { public static final Setting CLIENT_TRANSPORT_SNIFF = Setting.boolSetting("client.transport.sniff", false, Setting.Property.NodeScope); + public static final String TRANSPORT_CLIENT_FEATURE = "transport_client"; + private static PluginsService newPluginService(final Settings settings, Collection> plugins) { final Settings.Builder settingsBuilder = Settings.builder() .put(TcpTransport.PING_SCHEDULE.getKey(), "5s") // enable by default the transport schedule ping interval @@ -130,8 +132,12 @@ public abstract class TransportClient extends AbstractClient { providedSettings = Settings.builder().put(providedSettings).put(Node.NODE_NAME_SETTING.getKey(), "_client_").build(); } final PluginsService pluginsService = newPluginService(providedSettings, plugins); - final Settings settings = Settings.builder().put(defaultSettings).put(pluginsService.updatedSettings()).put(ThreadContext.PREFIX - + "." + "transport_client", true).build(); + final Settings settings = + Settings.builder() + .put(defaultSettings) + .put(pluginsService.updatedSettings()) + .put(TcpTransport.FEATURE_PREFIX + "." + TRANSPORT_CLIENT_FEATURE, true) + .build(); final List resourcesToClose = new ArrayList<>(); final ThreadPool threadPool = new ThreadPool(settings); resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); @@ -370,7 +376,7 @@ public abstract class TransportClient extends AbstractClient { } @Override - protected > void doExecute(Action action, Request request, ActionListener listener) { + protected > void doExecute(Action action, Request request, ActionListener listener) { proxy.execute(action, request, listener); } diff --git a/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index 109efb400bc..aa0672d80ba 100644 --- a/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -21,7 +21,7 @@ package org.elasticsearch.client.transport; import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.logging.log4j.util.Supplier; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; @@ -56,6 +56,7 @@ import org.elasticsearch.transport.TransportResponseHandler; import org.elasticsearch.transport.TransportService; import java.io.Closeable; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -89,6 +90,7 @@ final class TransportClientNodesService extends AbstractComponent implements Clo private final Object mutex = new Object(); private volatile List nodes = Collections.emptyList(); + // Filtered nodes are nodes whose cluster name does not match the configured cluster name private volatile List filteredNodes = Collections.emptyList(); private final AtomicInteger tempNodeIdGenerator = new AtomicInteger(); @@ -268,7 +270,7 @@ final class TransportClientNodesService extends AbstractComponent implements Clo private volatile int i; RetryListener(NodeListenerCallback callback, ActionListener listener, - List nodes, int index, TransportClient.HostFailureListener hostFailureListener) { + List nodes, int index, TransportClient.HostFailureListener hostFailureListener) { this.callback = callback; this.listener = listener; this.nodes = nodes; @@ -361,10 +363,10 @@ final class TransportClientNodesService extends AbstractComponent implements Clo protected abstract void doSample(); /** - * validates a set of potentially newly discovered nodes and returns an immutable - * list of the nodes that has passed. + * Establishes the node connections. If validateInHandshake is set to true, the connection will fail if + * node returned in the handshake response is different than the discovery node. */ - protected List validateNewNodes(Set nodes) { + List establishNodeConnections(Set nodes) { for (Iterator it = nodes.iterator(); it.hasNext(); ) { DiscoveryNode node = it.next(); if (!transportService.nodeConnected(node)) { @@ -380,7 +382,6 @@ final class TransportClientNodesService extends AbstractComponent implements Clo return Collections.unmodifiableList(new ArrayList<>(nodes)); } - } class ScheduledNodeSampler implements Runnable { @@ -402,14 +403,16 @@ final class TransportClientNodesService extends AbstractComponent implements Clo @Override protected void doSample() { HashSet newNodes = new HashSet<>(); - HashSet newFilteredNodes = new HashSet<>(); + ArrayList newFilteredNodes = new ArrayList<>(); for (DiscoveryNode listedNode : listedNodes) { try (Transport.Connection connection = transportService.openConnection(listedNode, LISTED_NODES_PROFILE)){ final PlainTransportFuture handler = new PlainTransportFuture<>( new FutureTransportResponseHandler() { @Override - public LivenessResponse newInstance() { - return new LivenessResponse(); + public LivenessResponse read(StreamInput in) throws IOException { + LivenessResponse response = new LivenessResponse(); + response.readFrom(in); + return response; } }); transportService.sendRequest(connection, TransportLivenessAction.NAME, new LivenessRequest(), @@ -435,8 +438,8 @@ final class TransportClientNodesService extends AbstractComponent implements Clo } } - nodes = validateNewNodes(newNodes); - filteredNodes = Collections.unmodifiableList(new ArrayList<>(newFilteredNodes)); + nodes = establishNodeConnections(newNodes); + filteredNodes = Collections.unmodifiableList(newFilteredNodes); } } @@ -557,7 +560,7 @@ final class TransportClientNodesService extends AbstractComponent implements Clo } } - nodes = validateNewNodes(newNodes); + nodes = establishNodeConnections(newNodes); filteredNodes = Collections.unmodifiableList(new ArrayList<>(newFilteredNodes)); } } diff --git a/server/src/main/java/org/elasticsearch/client/transport/TransportProxyClient.java b/server/src/main/java/org/elasticsearch/client/transport/TransportProxyClient.java index e07fab0092d..249fd54ef69 100644 --- a/server/src/main/java/org/elasticsearch/client/transport/TransportProxyClient.java +++ b/server/src/main/java/org/elasticsearch/client/transport/TransportProxyClient.java @@ -53,7 +53,7 @@ final class TransportProxyClient { } public > void execute(final Action action, + ActionRequestBuilder> void execute(final Action action, final Request request, ActionListener listener) { final TransportActionNodeProxy proxy = proxies.get(action); assert proxy != null : "no proxy found for action: " + action; diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java index 7f16c3f85ff..9c5c642df6b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -66,6 +66,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.gateway.GatewayAllocator; import org.elasticsearch.ingest.IngestMetadata; @@ -84,6 +85,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; @@ -150,6 +152,35 @@ public class ClusterModule extends AbstractModule { return entries; } + static final Set PRE_6_3_METADATA_CUSTOMS_WHITE_LIST = Collections.unmodifiableSet(Sets.newHashSet( + IndexGraveyard.TYPE, IngestMetadata.TYPE, RepositoriesMetaData.TYPE, ScriptMetaData.TYPE)); + + static final Set PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST = Collections.unmodifiableSet(Sets.newHashSet( + RestoreInProgress.TYPE, SnapshotDeletionsInProgress.TYPE, SnapshotsInProgress.TYPE)); + + /** + * For interoperability with transport clients older than 6.3, we need to strip customs + * from the cluster state that the client might not be able to deserialize + * + * @param clusterState the cluster state to filter the customs from + * @return the adapted cluster state + */ + public static ClusterState filterCustomsForPre63Clients(ClusterState clusterState) { + final ClusterState.Builder builder = ClusterState.builder(clusterState); + clusterState.customs().keysIt().forEachRemaining(name -> { + if (PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST.contains(name) == false) { + builder.removeCustom(name); + } + }); + final MetaData.Builder metaBuilder = MetaData.builder(clusterState.metaData()); + clusterState.metaData().customs().keysIt().forEachRemaining(name -> { + if (PRE_6_3_METADATA_CUSTOMS_WHITE_LIST.contains(name) == false) { + metaBuilder.removeCustom(name); + } + }); + return builder.metaData(metaBuilder).build(); + } + public static List getNamedXWriteables() { List entries = new ArrayList<>(); // Metadata diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java index 2b991d1dc61..6bc555eae0b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -23,6 +23,7 @@ import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -61,6 +62,7 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.Set; /** @@ -90,7 +92,51 @@ public class ClusterState implements ToXContentFragment, Diffable public static final ClusterState EMPTY_STATE = builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).build(); - public interface Custom extends NamedDiffable, ToXContentFragment { + /** + * An interface that implementors use when a class requires a client to maybe have a feature. + */ + public interface FeatureAware { + + /** + * An optional feature that is required for the client to have. + * + * @return an empty optional if no feature is required otherwise a string representing the required feature + */ + default Optional getRequiredFeature() { + return Optional.empty(); + } + + /** + * Tests whether or not the custom should be serialized. The criteria are: + *
    + *
  • the output stream must be at least the minimum supported version of the custom
  • + *
  • the output stream must have the feature required by the custom (if any) or not be a transport client
  • + *
+ *

+ * That is, we only serialize customs to clients than can understand the custom based on the version of the client and the features + * that the client has. For transport clients we can be lenient in requiring a feature in which case we do not send the custom but + * for connected nodes we always require that the node has the required feature. + * + * @param out the output stream + * @param custom the custom to serialize + * @param the type of the custom + * @return true if the custom should be serialized and false otherwise + */ + static boolean shouldSerializeCustom(final StreamOutput out, final T custom) { + if (out.getVersion().before(custom.getMinimalSupportedVersion())) { + return false; + } + if (custom.getRequiredFeature().isPresent()) { + final String requiredFeature = custom.getRequiredFeature().get(); + // if it is a transport client we are lenient yet for a connected node it must have the required feature + return out.hasFeature(requiredFeature) || out.hasFeature(TransportClient.TRANSPORT_CLIENT_FEATURE) == false; + } + return true; + } + + } + + public interface Custom extends NamedDiffable, ToXContentFragment, FeatureAware { /** * Returns true iff this {@link Custom} is private to the cluster and should never be send to a client. @@ -99,6 +145,7 @@ public class ClusterState implements ToXContentFragment, Diffable default boolean isPrivate() { return false; } + } private static final NamedDiffableValueSerializer CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer<>(Custom.class); @@ -244,6 +291,15 @@ public class ClusterState implements ToXContentFragment, Diffable sb.append("isa_ids ").append(indexMetaData.inSyncAllocationIds(shard)).append("\n"); } } + if (metaData.customs().isEmpty() == false) { + sb.append("metadata customs:\n"); + for (final ObjectObjectCursor cursor : metaData.customs()) { + final String type = cursor.key; + final MetaData.Custom custom = cursor.value; + sb.append(TAB).append(type).append(": ").append(custom); + } + sb.append("\n"); + } sb.append(blocks()); sb.append(nodes()); sb.append(routingTable()); @@ -691,14 +747,14 @@ public class ClusterState implements ToXContentFragment, Diffable blocks.writeTo(out); // filter out custom states not supported by the other node int numberOfCustoms = 0; - for (ObjectCursor cursor : customs.values()) { - if (out.getVersion().onOrAfter(cursor.value.getMinimalSupportedVersion())) { + for (final ObjectCursor cursor : customs.values()) { + if (FeatureAware.shouldSerializeCustom(out, cursor.value)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); - for (ObjectCursor cursor : customs.values()) { - if (out.getVersion().onOrAfter(cursor.value.getMinimalSupportedVersion())) { + for (final ObjectCursor cursor : customs.values()) { + if (FeatureAware.shouldSerializeCustom(out, cursor.value)) { out.writeNamedWriteable(cursor.value); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index b18c82712b3..8c732225195 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -24,6 +24,8 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.CollectionUtil; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ClusterState.FeatureAware; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; import org.elasticsearch.cluster.DiffableUtils; @@ -117,9 +119,10 @@ public class MetaData implements Iterable, Diffable, To */ public static EnumSet ALL_CONTEXTS = EnumSet.allOf(XContentContext.class); - public interface Custom extends NamedDiffable, ToXContentFragment { + public interface Custom extends NamedDiffable, ToXContentFragment, ClusterState.FeatureAware { EnumSet context(); + } public static final Setting SETTING_READ_ONLY_SETTING = @@ -782,14 +785,14 @@ public class MetaData implements Iterable, Diffable, To } // filter out custom states not supported by the other node int numberOfCustoms = 0; - for (ObjectCursor cursor : customs.values()) { - if (out.getVersion().onOrAfter(cursor.value.getMinimalSupportedVersion())) { + for (final ObjectCursor cursor : customs.values()) { + if (FeatureAware.shouldSerializeCustom(out, cursor.value)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); - for (ObjectCursor cursor : customs.values()) { - if (out.getVersion().onOrAfter(cursor.value.getMinimalSupportedVersion())) { + for (final ObjectCursor cursor : customs.values()) { + if (FeatureAware.shouldSerializeCustom(out, cursor.value)) { out.writeNamedWriteable(cursor.value); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index 6d18f5e01b5..3ab20f62237 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -186,7 +186,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { return Collections.emptySet(); } }; - try (IndexAnalyzers fakeIndexAnalzyers = new IndexAnalyzers(indexSettings, fakeDefault, fakeDefault, fakeDefault, analyzerMap, analyzerMap)) { + try (IndexAnalyzers fakeIndexAnalzyers = new IndexAnalyzers(indexSettings, fakeDefault, fakeDefault, fakeDefault, analyzerMap, analyzerMap, analyzerMap)) { MapperService mapperService = new MapperService(indexSettings, fakeIndexAnalzyers, xContentRegistry, similarityService, mapperRegistry, () -> null); mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY); diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index ab0f47bf14d..e8c4d197fda 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -30,6 +30,8 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.geo.GeoPoint; @@ -58,10 +60,12 @@ import java.util.Date; import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.IntFunction; @@ -98,6 +102,7 @@ public abstract class StreamOutput extends OutputStream { } private Version version = Version.CURRENT; + private Set features = Collections.emptySet(); /** * The version of the node on the other side of this stream. @@ -113,6 +118,27 @@ public abstract class StreamOutput extends OutputStream { this.version = version; } + /** + * Test if the stream has the specified feature. Features are used when serializing {@link ClusterState.Custom} or + * {@link MetaData.Custom}; see also {@link ClusterState.FeatureAware}. + * + * @param feature the feature to test + * @return true if the stream has the specified feature + */ + public boolean hasFeature(final String feature) { + return this.features.contains(feature); + } + + /** + * Set the features on the stream. See {@link StreamOutput#hasFeature(String)}. + * + * @param features the features on the stream + */ + public void setFeatures(final Set features) { + assert this.features.isEmpty() : this.features; + this.features = Collections.unmodifiableSet(new HashSet<>(features)); + } + public long position() throws IOException { throw new UnsupportedOperationException(); } diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index d9cf0f630c0..e616613a425 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -379,6 +379,7 @@ public final class ClusterSettings extends AbstractScopedSettings { ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING, EsExecutors.PROCESSORS_SETTING, ThreadContext.DEFAULT_HEADERS_SETTING, + TcpTransport.DEFAULT_FEATURES_SETTING, Loggers.LOG_DEFAULT_LEVEL_SETTING, Loggers.LOG_LEVEL_SETTING, NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING, diff --git a/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java b/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java index 77be68fbbe2..e421a19b2ac 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.WhitespaceTokenizer; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; @@ -453,13 +454,16 @@ public final class AnalysisRegistry implements Closeable { analyzerProviders = new HashMap<>(analyzerProviders); Map analyzers = new HashMap<>(); Map normalizers = new HashMap<>(); + Map whitespaceNormalizers = new HashMap<>(); for (Map.Entry> entry : analyzerProviders.entrySet()) { processAnalyzerFactory(indexSettings, entry.getKey(), entry.getValue(), analyzers, tokenFilterFactoryFactories, charFilterFactoryFactories, tokenizerFactoryFactories); } for (Map.Entry> entry : normalizerProviders.entrySet()) { processNormalizerFactory(entry.getKey(), entry.getValue(), normalizers, - tokenizerFactoryFactories.get("keyword"), tokenFilterFactoryFactories, charFilterFactoryFactories); + "keyword", tokenizerFactoryFactories.get("keyword"), tokenFilterFactoryFactories, charFilterFactoryFactories); + processNormalizerFactory(entry.getKey(), entry.getValue(), whitespaceNormalizers, + "whitespace", () -> new WhitespaceTokenizer(), tokenFilterFactoryFactories, charFilterFactoryFactories); } if (!analyzers.containsKey("default")) { @@ -489,7 +493,7 @@ public final class AnalysisRegistry implements Closeable { } } return new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultSearchAnalyzer, defaultSearchQuoteAnalyzer, - unmodifiableMap(analyzers), unmodifiableMap(normalizers)); + unmodifiableMap(analyzers), unmodifiableMap(normalizers), unmodifiableMap(whitespaceNormalizers)); } private void processAnalyzerFactory(IndexSettings indexSettings, @@ -545,15 +549,16 @@ public final class AnalysisRegistry implements Closeable { String name, AnalyzerProvider normalizerFactory, Map normalizers, - TokenizerFactory keywordTokenizerFactory, + String tokenizerName, + TokenizerFactory tokenizerFactory, Map tokenFilters, Map charFilters) { - if (keywordTokenizerFactory == null) { + if (tokenizerFactory == null) { throw new IllegalStateException("keyword tokenizer factory is null, normalizers require analysis-common module"); } if (normalizerFactory instanceof CustomNormalizerProvider) { - ((CustomNormalizerProvider) normalizerFactory).build(keywordTokenizerFactory, charFilters, tokenFilters); + ((CustomNormalizerProvider) normalizerFactory).build(tokenizerName, tokenizerFactory, charFilters, tokenFilters); } Analyzer normalizerF = normalizerFactory.get(); if (normalizerF == null) { diff --git a/server/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java b/server/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java index a0a7859d50c..13946be3a8d 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java @@ -38,15 +38,14 @@ public final class CustomNormalizerProvider extends AbstractIndexAnalyzerProvide private CustomAnalyzer customAnalyzer; public CustomNormalizerProvider(IndexSettings indexSettings, - String name, Settings settings) { + String name, Settings settings) { super(indexSettings, name, settings); this.analyzerSettings = settings; } - public void build(final TokenizerFactory keywordTokenizerFactory, final Map charFilters, + public void build(final String tokenizerName, final TokenizerFactory tokenizerFactory, final Map charFilters, final Map tokenFilters) { - String tokenizerName = analyzerSettings.get("tokenizer"); - if (tokenizerName != null) { + if (analyzerSettings.get("tokenizer") != null) { throw new IllegalArgumentException("Custom normalizer [" + name() + "] cannot configure a tokenizer"); } @@ -82,8 +81,8 @@ public final class CustomNormalizerProvider extends AbstractIndexAnalyzerProvide } this.customAnalyzer = new CustomAnalyzer( - "keyword", - keywordTokenizerFactory, + tokenizerName, + tokenizerFactory, charFiltersList.toArray(new CharFilterFactory[charFiltersList.size()]), tokenFilterList.toArray(new TokenFilterFactory[tokenFilterList.size()]) ); diff --git a/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java b/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java index 5131c51213f..f205fd05994 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java @@ -40,11 +40,12 @@ public final class IndexAnalyzers extends AbstractIndexComponent implements Clos private final NamedAnalyzer defaultSearchQuoteAnalyzer; private final Map analyzers; private final Map normalizers; + private final Map whitespaceNormalizers; private final IndexSettings indexSettings; public IndexAnalyzers(IndexSettings indexSettings, NamedAnalyzer defaultIndexAnalyzer, NamedAnalyzer defaultSearchAnalyzer, NamedAnalyzer defaultSearchQuoteAnalyzer, Map analyzers, - Map normalizers) { + Map normalizers, Map whitespaceNormalizers) { super(indexSettings); if (defaultIndexAnalyzer.name().equals("default") == false) { throw new IllegalStateException("default analyzer must have the name [default] but was: [" + defaultIndexAnalyzer.name() + "]"); @@ -54,6 +55,7 @@ public final class IndexAnalyzers extends AbstractIndexComponent implements Clos this.defaultSearchQuoteAnalyzer = defaultSearchQuoteAnalyzer; this.analyzers = analyzers; this.normalizers = normalizers; + this.whitespaceNormalizers = whitespaceNormalizers; this.indexSettings = indexSettings; } @@ -71,6 +73,13 @@ public final class IndexAnalyzers extends AbstractIndexComponent implements Clos return normalizers.get(name); } + /** + * Returns a normalizer that splits on whitespace mapped to the given name or null if not present + */ + public NamedAnalyzer getWhitespaceNormalizer(String name) { + return whitespaceNormalizers.get(name); + } + /** * Returns the default index analyzer for this index */ diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index 76163929e68..de2aee326c7 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedSetDocValuesField; @@ -35,6 +36,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; +import org.elasticsearch.index.analysis.AnalyzerScope; +import org.elasticsearch.index.analysis.IndexAnalyzers; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData; @@ -73,6 +76,8 @@ public final class KeywordFieldMapper extends FieldMapper { protected String nullValue = Defaults.NULL_VALUE; protected int ignoreAbove = Defaults.IGNORE_ABOVE; + private IndexAnalyzers indexAnalyzers; + private String normalizerName; public Builder(String name) { super(name, Defaults.FIELD_TYPE, Defaults.FIELD_TYPE); @@ -106,15 +111,36 @@ public final class KeywordFieldMapper extends FieldMapper { return builder; } - public Builder normalizer(NamedAnalyzer normalizer) { - fieldType().setNormalizer(normalizer); - fieldType().setSearchAnalyzer(normalizer); + public Builder splitQueriesOnWhitespace(boolean splitQueriesOnWhitespace) { + fieldType().setSplitQueriesOnWhitespace(splitQueriesOnWhitespace); + return builder; + } + + public Builder normalizer(IndexAnalyzers indexAnalyzers, String name) { + this.indexAnalyzers = indexAnalyzers; + this.normalizerName = name; return builder; } @Override public KeywordFieldMapper build(BuilderContext context) { setupFieldType(context); + if (normalizerName != null) { + NamedAnalyzer normalizer = indexAnalyzers.getNormalizer(normalizerName); + if (normalizer == null) { + throw new MapperParsingException("normalizer [" + normalizerName + "] not found for field [" + name + "]"); + } + fieldType().setNormalizer(normalizer); + final NamedAnalyzer searchAnalyzer; + if (fieldType().splitQueriesOnWhitespace) { + searchAnalyzer = indexAnalyzers.getWhitespaceNormalizer(normalizerName); + } else { + searchAnalyzer = normalizer; + } + fieldType().setSearchAnalyzer(searchAnalyzer); + } else if (fieldType().splitQueriesOnWhitespace) { + fieldType().setSearchAnalyzer(new NamedAnalyzer("whitespace", AnalyzerScope.INDEX, new WhitespaceAnalyzer())); + } return new KeywordFieldMapper( name, fieldType, defaultFieldType, ignoreAbove, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo); @@ -147,13 +173,12 @@ public final class KeywordFieldMapper extends FieldMapper { iterator.remove(); } else if (propName.equals("normalizer")) { if (propNode != null) { - NamedAnalyzer normalizer = parserContext.getIndexAnalyzers().getNormalizer(propNode.toString()); - if (normalizer == null) { - throw new MapperParsingException("normalizer [" + propNode.toString() + "] not found for field [" + name + "]"); - } - builder.normalizer(normalizer); + builder.normalizer(parserContext.getIndexAnalyzers(), propNode.toString()); } iterator.remove(); + } else if (propName.equals("split_queries_on_whitespace")) { + builder.splitQueriesOnWhitespace(XContentMapValues.nodeBooleanValue(propNode, "split_queries_on_whitespace")); + iterator.remove(); } } return builder; @@ -163,6 +188,7 @@ public final class KeywordFieldMapper extends FieldMapper { public static final class KeywordFieldType extends StringFieldType { private NamedAnalyzer normalizer = null; + private boolean splitQueriesOnWhitespace; public KeywordFieldType() { setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); @@ -172,6 +198,7 @@ public final class KeywordFieldMapper extends FieldMapper { protected KeywordFieldType(KeywordFieldType ref) { super(ref); this.normalizer = ref.normalizer; + this.splitQueriesOnWhitespace = splitQueriesOnWhitespace; } public KeywordFieldType clone() { @@ -183,7 +210,9 @@ public final class KeywordFieldMapper extends FieldMapper { if (super.equals(o) == false) { return false; } - return Objects.equals(normalizer, ((KeywordFieldType) o).normalizer); + KeywordFieldType other = (KeywordFieldType) o; + return Objects.equals(normalizer, other.normalizer) && + splitQueriesOnWhitespace == other.splitQueriesOnWhitespace; } @Override @@ -197,7 +226,7 @@ public final class KeywordFieldMapper extends FieldMapper { @Override public int hashCode() { - return 31 * super.hashCode() + Objects.hashCode(normalizer); + return 31 * super.hashCode() + Objects.hash(normalizer, splitQueriesOnWhitespace); } @Override @@ -214,6 +243,15 @@ public final class KeywordFieldMapper extends FieldMapper { this.normalizer = normalizer; } + public boolean splitQueriesOnWhitespace() { + return splitQueriesOnWhitespace; + } + + public void setSplitQueriesOnWhitespace(boolean splitQueriesOnWhitespace) { + checkIfFrozen(); + this.splitQueriesOnWhitespace = splitQueriesOnWhitespace; + } + @Override public Query existsQuery(QueryShardContext context) { if (hasDocValues()) { @@ -223,14 +261,6 @@ public final class KeywordFieldMapper extends FieldMapper { } } - @Override - public Query nullValueQuery() { - if (nullValue() == null) { - return null; - } - return termQuery(nullValue(), null); - } - @Override public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { failIfNoDocValues(); @@ -271,7 +301,8 @@ public final class KeywordFieldMapper extends FieldMapper { private int ignoreAbove; protected KeywordFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, - int ignoreAbove, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) { + int ignoreAbove, Settings indexSettings, + MultiFields multiFields, CopyTo copyTo) { super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo); assert fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) <= 0; this.ignoreAbove = ignoreAbove; @@ -374,5 +405,9 @@ public final class KeywordFieldMapper extends FieldMapper { } else if (includeDefaults) { builder.nullField("normalizer"); } + + if (includeDefaults || fieldType().splitQueriesOnWhitespace) { + builder.field("split_queries_on_whitespace", fieldType().splitQueriesOnWhitespace); + } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java index fb92c576e01..facf669cb5d 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java @@ -351,13 +351,6 @@ public abstract class MappedFieldType extends FieldType { throw new QueryShardException(context, "Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"); } - public Query nullValueQuery() { - if (nullValue == null) { - return null; - } - return new ConstantScoreQuery(termQuery(nullValue, null)); - } - public abstract Query existsQuery(QueryShardContext context); /** @@ -382,12 +375,6 @@ public abstract class MappedFieldType extends FieldType { return Relation.INTERSECTS; } - /** A term query to use when parsing a query string. Can return {@code null}. */ - @Nullable - public Query queryStringTermQuery(Term term) { - return null; - } - /** @throws IllegalArgumentException if the fielddata is not supported on this type. * An IllegalArgumentException is needed in order to return an http error 400 * when this error occurs in a request. see: {@link org.elasticsearch.ExceptionsHelper#status} diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index d71d2ad579c..9e2063adb14 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -24,7 +24,6 @@ import org.apache.lucene.analysis.AnalyzerWrapper; import org.apache.lucene.analysis.TokenFilter; import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter; import org.apache.lucene.document.Field; -import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; @@ -289,18 +288,6 @@ public class TextFieldMapper extends FieldMapper { return super.toString() + ",prefixChars=" + minChars + ":" + maxChars; } - @Override - public void checkCompatibility(MappedFieldType other, List conflicts) { - super.checkCompatibility(other, conflicts); - PrefixFieldType otherFieldType = (PrefixFieldType) other; - if (otherFieldType.minChars != this.minChars) { - conflicts.add("mapper [" + name() + "] has different min_chars values"); - } - if (otherFieldType.maxChars != this.maxChars) { - conflicts.add("mapper [" + name() + "] has different max_chars values"); - } - } - @Override public Query existsQuery(QueryShardContext context) { throw new UnsupportedOperationException(); @@ -471,14 +458,6 @@ public class TextFieldMapper extends FieldMapper { } } - @Override - public Query nullValueQuery() { - if (nullValue() == null) { - return null; - } - return termQuery(nullValue(), null); - } - @Override public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { if (fielddata == false) { @@ -488,6 +467,25 @@ public class TextFieldMapper extends FieldMapper { } return new PagedBytesIndexFieldData.Builder(fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize); } + + @Override + public void checkCompatibility(MappedFieldType other, List conflicts) { + super.checkCompatibility(other, conflicts); + TextFieldType tft = (TextFieldType) other; + if (Objects.equals(this.prefixFieldType, tft.prefixFieldType) == false) { + if (this.prefixFieldType == null) { + conflicts.add("mapper [" + name() + + "] has different [index_prefixes] settings, cannot change from disabled to enabled"); + } + else if (tft.prefixFieldType == null) { + conflicts.add("mapper [" + name() + + "] has different [index_prefixes] settings, cannot change from enabled to disabled"); + } + else { + conflicts.add("mapper [" + name() + "] has different [index_prefixes] settings"); + } + } + } } private int positionIncrementGap; diff --git a/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java index 974466a3161..2fd4d710f96 100644 --- a/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java @@ -371,8 +371,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder, Self extends AbstractBulkByScrollRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { private final SearchRequestBuilder source; protected AbstractBulkByScrollRequestBuilder(ElasticsearchClient client, - Action action, SearchRequestBuilder source, Request request) { + Action action, SearchRequestBuilder source, Request request) { super(client, action, request); this.source = source; } diff --git a/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkIndexByScrollRequestBuilder.java b/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkIndexByScrollRequestBuilder.java index ca1c980995b..d8cf2f49149 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkIndexByScrollRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/AbstractBulkIndexByScrollRequestBuilder.java @@ -30,7 +30,7 @@ public abstract class AbstractBulkIndexByScrollRequestBuilder< extends AbstractBulkByScrollRequestBuilder { protected AbstractBulkIndexByScrollRequestBuilder(ElasticsearchClient client, - Action action, SearchRequestBuilder search, Request request) { + Action action, SearchRequestBuilder search, Request request) { super(client, action, search, request); } diff --git a/server/src/main/java/org/elasticsearch/index/reindex/DeleteByQueryAction.java b/server/src/main/java/org/elasticsearch/index/reindex/DeleteByQueryAction.java index c1abb16ca39..639c615727f 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/DeleteByQueryAction.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/DeleteByQueryAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class DeleteByQueryAction extends Action { +public class DeleteByQueryAction extends Action { public static final DeleteByQueryAction INSTANCE = new DeleteByQueryAction(); public static final String NAME = "indices:data/write/delete/byquery"; @@ -31,11 +30,6 @@ public class DeleteByQueryAction extends Action { - public DeleteByQueryRequestBuilder(ElasticsearchClient client, - Action action) { + public DeleteByQueryRequestBuilder(ElasticsearchClient client, Action action) { this(client, action, new SearchRequestBuilder(client, SearchAction.INSTANCE)); } private DeleteByQueryRequestBuilder(ElasticsearchClient client, - Action action, + Action action, SearchRequestBuilder search) { super(client, action, search, new DeleteByQueryRequest(search.request())); } diff --git a/server/src/main/java/org/elasticsearch/index/reindex/ReindexAction.java b/server/src/main/java/org/elasticsearch/index/reindex/ReindexAction.java index 1c53a925f0d..c4e4a68d114 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/ReindexAction.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/ReindexAction.java @@ -20,9 +20,8 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ReindexAction extends Action { +public class ReindexAction extends Action { public static final ReindexAction INSTANCE = new ReindexAction(); public static final String NAME = "indices:data/write/reindex"; @@ -30,11 +29,6 @@ public class ReindexAction extends Action action) { + Action action) { this(client, action, new SearchRequestBuilder(client, SearchAction.INSTANCE), new IndexRequestBuilder(client, IndexAction.INSTANCE)); } private ReindexRequestBuilder(ElasticsearchClient client, - Action action, + Action action, SearchRequestBuilder search, IndexRequestBuilder destination) { super(client, action, search, new ReindexRequest(search.request(), destination.request())); this.destination = destination; diff --git a/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryAction.java b/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryAction.java index 1058f7f1307..b2fb0a205eb 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryAction.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryAction.java @@ -20,10 +20,8 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class UpdateByQueryAction extends - Action { +public class UpdateByQueryAction extends Action { public static final UpdateByQueryAction INSTANCE = new UpdateByQueryAction(); public static final String NAME = "indices:data/write/update/byquery"; @@ -31,11 +29,6 @@ public class UpdateByQueryAction extends super(NAME); } - @Override - public UpdateByQueryRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new UpdateByQueryRequestBuilder(client, this); - } - @Override public BulkByScrollResponse newResponse() { return new BulkByScrollResponse(); diff --git a/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryRequestBuilder.java b/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryRequestBuilder.java index 06e04268641..dc56bb9cf9d 100644 --- a/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/reindex/UpdateByQueryRequestBuilder.java @@ -27,13 +27,12 @@ import org.elasticsearch.client.ElasticsearchClient; public class UpdateByQueryRequestBuilder extends AbstractBulkIndexByScrollRequestBuilder { - public UpdateByQueryRequestBuilder(ElasticsearchClient client, - Action action) { + public UpdateByQueryRequestBuilder(ElasticsearchClient client, Action action) { this(client, action, new SearchRequestBuilder(client, SearchAction.INSTANCE)); } private UpdateByQueryRequestBuilder(ElasticsearchClient client, - Action action, + Action action, SearchRequestBuilder search) { super(client, action, search, new UpdateByQueryRequest(search.request())); } diff --git a/server/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/server/src/main/java/org/elasticsearch/index/search/MatchQuery.java index 03b4715c4b1..7765be215aa 100644 --- a/server/src/main/java/org/elasticsearch/index/search/MatchQuery.java +++ b/server/src/main/java/org/elasticsearch/index/search/MatchQuery.java @@ -20,8 +20,8 @@ package org.elasticsearch.index.search; import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute; import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.Term; import org.apache.lucene.queries.ExtendedCommonTermsQuery; @@ -29,7 +29,6 @@ import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BoostQuery; -import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.MultiPhraseQuery; import org.apache.lucene.search.MultiTermQuery; @@ -53,6 +52,7 @@ import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.index.analysis.ShingleTokenFilterFactory; +import org.elasticsearch.index.mapper.KeywordFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.support.QueryParsers; @@ -263,7 +263,8 @@ public class MatchQuery { * passing through QueryBuilder. */ boolean noForcedAnalyzer = this.analyzer == null; - if (fieldType.tokenized() == false && noForcedAnalyzer) { + if (fieldType.tokenized() == false && noForcedAnalyzer && + fieldType instanceof KeywordFieldMapper.KeywordFieldType == false) { return blendTermQuery(new Term(fieldName, value.toString()), fieldType); } @@ -283,7 +284,7 @@ public class MatchQuery { if (commonTermsCutoff == null) { query = builder.createBooleanQuery(field, value.toString(), occur); } else { - query = builder.createCommonTermsQuery(field, value.toString(), occur, occur, commonTermsCutoff, fieldType); + query = builder.createCommonTermsQuery(field, value.toString(), occur, occur, commonTermsCutoff); } break; case PHRASE: @@ -463,20 +464,23 @@ public class MatchQuery { } } - public Query createCommonTermsQuery(String field, String queryText, Occur highFreqOccur, Occur lowFreqOccur, float - maxTermFrequency, MappedFieldType fieldType) { + public Query createCommonTermsQuery(String field, String queryText, + Occur highFreqOccur, + Occur lowFreqOccur, + float maxTermFrequency) { Query booleanQuery = createBooleanQuery(field, queryText, lowFreqOccur); if (booleanQuery != null && booleanQuery instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) booleanQuery; - return boolToExtendedCommonTermsQuery(bq, highFreqOccur, lowFreqOccur, maxTermFrequency, fieldType); + return boolToExtendedCommonTermsQuery(bq, highFreqOccur, lowFreqOccur, maxTermFrequency); } return booleanQuery; } - private Query boolToExtendedCommonTermsQuery(BooleanQuery bq, Occur highFreqOccur, Occur lowFreqOccur, float - maxTermFrequency, MappedFieldType fieldType) { - ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, - fieldType); + private Query boolToExtendedCommonTermsQuery(BooleanQuery bq, + Occur highFreqOccur, + Occur lowFreqOccur, + float maxTermFrequency) { + ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency); for (BooleanClause clause : bq.clauses()) { if (!(clause.getQuery() instanceof TermQuery)) { return bq; diff --git a/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java b/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java index 398f2240a5c..590bcf5e4e0 100644 --- a/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java +++ b/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java @@ -272,17 +272,6 @@ public class QueryStringQueryParser extends XQueryParser { } } - @Override - protected Query newTermQuery(Term term) { - if (currentFieldType != null) { - Query termQuery = currentFieldType.queryStringTermQuery(term); - if (termQuery != null) { - return termQuery; - } - } - return super.newTermQuery(term); - } - @Override protected Query newMatchAllDocsQuery() { return Queries.newMatchAllQuery(); diff --git a/server/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java b/server/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java index 737bad8ee5b..3b296bf52d3 100644 --- a/server/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java +++ b/server/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; +import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -148,14 +149,14 @@ public final class PipelineConfiguration extends AbstractDiffable { +public class CompletionPersistentTaskAction extends Action { public static final CompletionPersistentTaskAction INSTANCE = new CompletionPersistentTaskAction(); public static final String NAME = "cluster:admin/persistent/completion"; @@ -59,11 +57,6 @@ public class CompletionPersistentTaskAction extends Action * The origin is set in the context and the listener is wrapped to ensure the proper context is restored */ - private > - void execute(final Req request, final Action action, final ActionListener> listener) { + private + void execute(final Req request, final Action action, final ActionListener> listener) { try { final ThreadContext threadContext = client.threadPool().getThreadContext(); final Supplier supplier = threadContext.newRestorableContext(false); diff --git a/server/src/main/java/org/elasticsearch/persistent/RemovePersistentTaskAction.java b/server/src/main/java/org/elasticsearch/persistent/RemovePersistentTaskAction.java index d0a4575a103..f278b5bcc5e 100644 --- a/server/src/main/java/org/elasticsearch/persistent/RemovePersistentTaskAction.java +++ b/server/src/main/java/org/elasticsearch/persistent/RemovePersistentTaskAction.java @@ -42,9 +42,7 @@ import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask import java.io.IOException; import java.util.Objects; -public class RemovePersistentTaskAction extends Action { +public class RemovePersistentTaskAction extends Action { public static final RemovePersistentTaskAction INSTANCE = new RemovePersistentTaskAction(); public static final String NAME = "cluster:admin/persistent/remove"; @@ -53,11 +51,6 @@ public class RemovePersistentTaskAction extends Action { +public class StartPersistentTaskAction extends Action { public static final StartPersistentTaskAction INSTANCE = new StartPersistentTaskAction(); public static final String NAME = "cluster:admin/persistent/start"; @@ -59,11 +57,6 @@ public class StartPersistentTaskAction extends Action { +public class UpdatePersistentTaskStatusAction extends Action { public static final UpdatePersistentTaskStatusAction INSTANCE = new UpdatePersistentTaskStatusAction(); public static final String NAME = "cluster:admin/persistent/update_status"; @@ -56,11 +54,6 @@ public class UpdatePersistentTaskStatusAction extends Action getFeature() { + return Optional.empty(); + } + /** * Node level guice modules. */ diff --git a/server/src/main/java/org/elasticsearch/plugins/PluginsService.java b/server/src/main/java/org/elasticsearch/plugins/PluginsService.java index 68a19bb9bca..5b64b5be639 100644 --- a/server/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/server/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -41,8 +41,10 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.IndexModule; import org.elasticsearch.threadpool.ExecutorBuilder; +import org.elasticsearch.transport.TcpTransport; import java.io.IOException; import java.lang.reflect.Constructor; @@ -57,16 +59,17 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory; @@ -196,6 +199,7 @@ public class PluginsService extends AbstractComponent { public Settings updatedSettings() { Map foundSettings = new HashMap<>(); + final Map features = new TreeMap<>(); final Settings.Builder builder = Settings.builder(); for (Tuple plugin : plugins) { Settings settings = plugin.v2().additionalSettings(); @@ -207,6 +211,23 @@ public class PluginsService extends AbstractComponent { } } builder.put(settings); + final Optional maybeFeature = plugin.v2().getFeature(); + if (maybeFeature.isPresent()) { + final String feature = maybeFeature.get(); + if (features.containsKey(feature)) { + final String message = String.format( + Locale.ROOT, + "duplicate feature [%s] in plugin [%s], already added in [%s]", + feature, + plugin.v1().getName(), + features.get(feature)); + throw new IllegalArgumentException(message); + } + features.put(feature, plugin.v1().getName()); + } + } + for (final String feature : features.keySet()) { + builder.put(TcpTransport.FEATURE_PREFIX + "." + feature, true); } return builder.put(this.settings).build(); } diff --git a/server/src/main/java/org/elasticsearch/rest/RestRequest.java b/server/src/main/java/org/elasticsearch/rest/RestRequest.java index bd46a20f312..65b4f9d1d36 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/server/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -130,7 +130,7 @@ public abstract class RestRequest implements ToXContent.Params { } public enum Method { - GET, POST, PUT, DELETE, OPTIONS, HEAD + GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, CONNECT } public abstract Method method(); diff --git a/server/src/main/java/org/elasticsearch/tasks/TaskInfo.java b/server/src/main/java/org/elasticsearch/tasks/TaskInfo.java index 26aabec3e9f..d01b8cfaa3c 100644 --- a/server/src/main/java/org/elasticsearch/tasks/TaskInfo.java +++ b/server/src/main/java/org/elasticsearch/tasks/TaskInfo.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ObjectParserHelper; -import org.elasticsearch.common.xcontent.ToXContent.Params; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -259,7 +258,7 @@ public final class TaskInfo implements Writeable, ToXContentFragment { @Override public String toString() { - return Strings.toString(this); + return Strings.toString(this, true, true); } // Implements equals and hashCode for testing diff --git a/server/src/main/java/org/elasticsearch/transport/RemoteClusterAwareClient.java b/server/src/main/java/org/elasticsearch/transport/RemoteClusterAwareClient.java index aa476bf4dd2..70a07db1247 100644 --- a/server/src/main/java/org/elasticsearch/transport/RemoteClusterAwareClient.java +++ b/server/src/main/java/org/elasticsearch/transport/RemoteClusterAwareClient.java @@ -44,8 +44,8 @@ final class RemoteClusterAwareClient extends AbstractClient { @Override protected > - void doExecute(Action action, Request request, ActionListener listener) { + ActionRequestBuilder> + void doExecute(Action action, Request request, ActionListener listener) { remoteClusterService.ensureConnected(clusterAlias, ActionListener.wrap(res -> { Transport.Connection connection = remoteClusterService.getConnection(clusterAlias); service.sendRequest(connection, action.name(), request, TransportRequestOptions.EMPTY, diff --git a/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java b/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java index 7673a02b2d0..a07de63d537 100644 --- a/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java +++ b/server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java @@ -215,7 +215,7 @@ public final class RemoteClusterService extends RemoteClusterAware implements Cl ActionListener> listener) { final CountDown responsesCountDown = new CountDown(remoteIndicesByCluster.size()); final Map searchShardsResponses = new ConcurrentHashMap<>(); - final AtomicReference transportException = new AtomicReference<>(); + final AtomicReference transportException = new AtomicReference<>(); for (Map.Entry entry : remoteIndicesByCluster.entrySet()) { final String clusterName = entry.getKey(); RemoteClusterConnection remoteClusterConnection = remoteClusters.get(clusterName); @@ -232,7 +232,7 @@ public final class RemoteClusterService extends RemoteClusterAware implements Cl public void onResponse(ClusterSearchShardsResponse clusterSearchShardsResponse) { searchShardsResponses.put(clusterName, clusterSearchShardsResponse); if (responsesCountDown.countDown()) { - TransportException exception = transportException.get(); + RemoteTransportException exception = transportException.get(); if (exception == null) { listener.onResponse(searchShardsResponses); } else { @@ -243,8 +243,8 @@ public final class RemoteClusterService extends RemoteClusterAware implements Cl @Override public void onFailure(Exception e) { - TransportException exception = new TransportException("unable to communicate with remote cluster [" + - clusterName + "]", e); + RemoteTransportException exception = new RemoteTransportException("error while communicating with remote cluster [" + + clusterName + "]", e); if (transportException.compareAndSet(null, exception) == false) { exception = transportException.accumulateAndGet(exception, (previous, current) -> { current.addSuppressed(previous); diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java index 0b3d4e1b0a1..c577fae4867 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransport.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransport.java @@ -21,6 +21,7 @@ package org.elasticsearch.transport; import com.carrotsearch.hppc.IntHashSet; import com.carrotsearch.hppc.IntSet; import org.apache.logging.log4j.message.ParameterizedMessage; +import org.elasticsearch.common.Booleans; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; @@ -93,6 +94,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; @@ -189,6 +191,10 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements private static final long NINETY_PER_HEAP_SIZE = (long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.9); private static final BytesReference EMPTY_BYTES_REFERENCE = new BytesArray(new byte[0]); + public static final String FEATURE_PREFIX = "transport.features"; + public static final Setting DEFAULT_FEATURES_SETTING = Setting.groupSetting(FEATURE_PREFIX + ".", Setting.Property.NodeScope); + private final String[] features; + private final CircuitBreakerService circuitBreakerService; // package visibility for tests protected final ScheduledPing scheduledPing; @@ -240,6 +246,18 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements this.networkService = networkService; this.transportName = transportName; defaultConnectionProfile = buildDefaultConnectionProfile(settings); + final Settings defaultFeatures = DEFAULT_FEATURES_SETTING.get(settings); + if (defaultFeatures == null) { + this.features = new String[0]; + } else { + defaultFeatures.names().forEach(key -> { + if (Booleans.parseBoolean(defaultFeatures.get(key)) == false) { + throw new IllegalArgumentException("feature settings must have default [true] value"); + } + }); + // use a sorted set to present the features in a consistent order + this.features = new TreeSet<>(defaultFeatures.names()).toArray(new String[defaultFeatures.names().size()]); + } } static ConnectionProfile buildDefaultConnectionProfile(Settings settings) { @@ -1103,6 +1121,9 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements stream.setVersion(version); threadPool.getThreadContext().writeTo(stream); + if (version.onOrAfter(Version.V_6_3_0)) { + stream.writeStringArray(features); + } stream.writeString(action); BytesReference message = buildMessage(requestId, status, node.getVersion(), request, stream); final TransportRequestOptions finalOptions = options; @@ -1135,15 +1156,22 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements * Sends back an error response to the caller via the given channel * * @param nodeVersion the caller node version + * @param features the caller features * @param channel the channel to send the response to * @param error the error to return * @param requestId the request ID this response replies to * @param action the action this response replies to */ - public void sendErrorResponse(Version nodeVersion, TcpChannel channel, final Exception error, final long requestId, - final String action) throws IOException { + public void sendErrorResponse( + final Version nodeVersion, + final Set features, + final TcpChannel channel, + final Exception error, + final long requestId, + final String action) throws IOException { try (BytesStreamOutput stream = new BytesStreamOutput()) { stream.setVersion(nodeVersion); + stream.setFeatures(features); RemoteTransportException tx = new RemoteTransportException( nodeName(), new TransportAddress(channel.getLocalAddress()), action, error); threadPool.getThreadContext().writeTo(stream); @@ -1163,15 +1191,28 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements /** * Sends the response to the given channel. This method should be used to send {@link TransportResponse} objects back to the caller. * - * @see #sendErrorResponse(Version, TcpChannel, Exception, long, String) for sending back errors to the caller + * @see #sendErrorResponse(Version, Set, TcpChannel, Exception, long, String) for sending back errors to the caller */ - public void sendResponse(Version nodeVersion, TcpChannel channel, final TransportResponse response, final long requestId, - final String action, TransportResponseOptions options) throws IOException { - sendResponse(nodeVersion, channel, response, requestId, action, options, (byte) 0); + public void sendResponse( + final Version nodeVersion, + final Set features, + final TcpChannel channel, + final TransportResponse response, + final long requestId, + final String action, + final TransportResponseOptions options) throws IOException { + sendResponse(nodeVersion, features, channel, response, requestId, action, options, (byte) 0); } - private void sendResponse(Version nodeVersion, TcpChannel channel, final TransportResponse response, final long requestId, - final String action, TransportResponseOptions options, byte status) throws IOException { + private void sendResponse( + final Version nodeVersion, + final Set features, + final TcpChannel channel, + final TransportResponse response, + final long requestId, + final String action, + TransportResponseOptions options, + byte status) throws IOException { if (compress) { options = TransportResponseOptions.builder(options).withCompress(true).build(); } @@ -1185,6 +1226,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements } threadPool.getThreadContext().writeTo(stream); stream.setVersion(nodeVersion); + stream.setFeatures(features); BytesReference message = buildMessage(requestId, status, nodeVersion, response, stream); final TransportResponseOptions finalOptions = options; @@ -1546,13 +1588,19 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements protected String handleRequest(TcpChannel channel, String profileName, final StreamInput stream, long requestId, int messageLengthBytes, Version version, InetSocketAddress remoteAddress, byte status) throws IOException { + final Set features; + if (version.onOrAfter(Version.V_6_3_0)) { + features = Collections.unmodifiableSet(new TreeSet<>(Arrays.asList(stream.readStringArray()))); + } else { + features = Collections.emptySet(); + } final String action = stream.readString(); transportService.onRequestReceived(requestId, action); TransportChannel transportChannel = null; try { if (TransportStatus.isHandshake(status)) { final VersionHandshakeResponse response = new VersionHandshakeResponse(getCurrentVersion()); - sendResponse(version, channel, response, requestId, HANDSHAKE_ACTION_NAME, TransportResponseOptions.EMPTY, + sendResponse(version, features, channel, response, requestId, HANDSHAKE_ACTION_NAME, TransportResponseOptions.EMPTY, TransportStatus.setHandshake((byte) 0)); } else { final RequestHandlerRegistry reg = transportService.getRequestHandler(action); @@ -1564,7 +1612,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements } else { getInFlightRequestBreaker().addWithoutBreaking(messageLengthBytes); } - transportChannel = new TcpTransportChannel(this, channel, transportName, action, requestId, version, profileName, + transportChannel = new TcpTransportChannel(this, channel, transportName, action, requestId, version, features, profileName, messageLengthBytes); final TransportRequest request = reg.newRequest(stream); request.remoteAddress(new TransportAddress(remoteAddress)); @@ -1575,7 +1623,8 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements } catch (Exception e) { // the circuit breaker tripped if (transportChannel == null) { - transportChannel = new TcpTransportChannel(this, channel, transportName, action, requestId, version, profileName, 0); + transportChannel = + new TcpTransportChannel(this, channel, transportName, action, requestId, version, features, profileName, 0); } try { transportChannel.sendResponse(e); diff --git a/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java b/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java index eb4c244c7a9..1bf1d027329 100644 --- a/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java +++ b/server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java @@ -16,16 +16,20 @@ * specific language governing permissions and limitations * under the License. */ + package org.elasticsearch.transport; import org.elasticsearch.Version; import java.io.IOException; +import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; public final class TcpTransportChannel implements TransportChannel { private final TcpTransport transport; private final Version version; + private final Set features; private final String action; private final long requestId; private final String profileName; @@ -34,9 +38,10 @@ public final class TcpTransportChannel implements TransportChannel { private final String channelType; private final TcpChannel channel; - TcpTransportChannel(TcpTransport transport, TcpChannel channel, String channelType, String action, - long requestId, Version version, String profileName, long reservedBytes) { + TcpTransportChannel(TcpTransport transport, TcpChannel channel, String channelType, String action, long requestId, Version version, + Set features, String profileName, long reservedBytes) { this.version = version; + this.features = features; this.channel = channel; this.transport = transport; this.action = action; @@ -59,7 +64,7 @@ public final class TcpTransportChannel implements TransportChannel { @Override public void sendResponse(TransportResponse response, TransportResponseOptions options) throws IOException { try { - transport.sendResponse(version, channel, response, requestId, action, options); + transport.sendResponse(version, features, channel, response, requestId, action, options); } finally { release(false); } @@ -68,7 +73,7 @@ public final class TcpTransportChannel implements TransportChannel { @Override public void sendResponse(Exception exception) throws IOException { try { - transport.sendErrorResponse(version, channel, exception, requestId, action); + transport.sendErrorResponse(version, features, channel, exception, requestId, action); } finally { release(true); } @@ -100,5 +105,6 @@ public final class TcpTransportChannel implements TransportChannel { public TcpChannel getChannel() { return channel; } + } diff --git a/server/src/main/java/org/elasticsearch/transport/TransportService.java b/server/src/main/java/org/elasticsearch/transport/TransportService.java index 44dac1d8eae..9755898be5f 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportService.java @@ -21,6 +21,8 @@ package org.elasticsearch.transport; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.liveness.TransportLivenessAction; @@ -124,6 +126,8 @@ public class TransportService extends AbstractLifecycleComponent { private final RemoteClusterService remoteClusterService; + private final boolean validateConnections; + /** if set will call requests sent to this id to shortcut and executed locally */ volatile DiscoveryNode localNode = null; private final Transport.Connection localNodeConnection = new Transport.Connection() { @@ -153,6 +157,9 @@ public class TransportService extends AbstractLifecycleComponent { Function localNodeFactory, @Nullable ClusterSettings clusterSettings, Set taskHeaders) { super(settings); + // The only time we do not want to validate node connections is when this is a transport client using the simple node sampler + this.validateConnections = TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())) == false || + TransportClient.CLIENT_TRANSPORT_SNIFF.get(settings); this.transport = transport; this.threadPool = threadPool; this.localNodeFactory = localNodeFactory; @@ -314,6 +321,11 @@ public class TransportService extends AbstractLifecycleComponent { return isLocalNode(node) || transport.nodeConnected(node); } + /** + * Connect to the specified node with the default connection profile + * + * @param node the node to connect to + */ public void connectToNode(DiscoveryNode node) throws ConnectTransportException { connectToNode(node, null); } @@ -331,7 +343,7 @@ public class TransportService extends AbstractLifecycleComponent { transport.connectToNode(node, connectionProfile, (newConnection, actualProfile) -> { // We don't validate cluster names to allow for CCS connections. final DiscoveryNode remote = handshake(newConnection, actualProfile.getHandshakeTimeout().millis(), cn -> true); - if (node.equals(remote) == false) { + if (validateConnections && node.equals(remote) == false) { throw new ConnectTransportException(node, "handshake failed. unexpected remote node " + remote); } }); diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java index 4ab54cdd206..bdddaf69cfe 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java @@ -497,7 +497,8 @@ public class TasksIT extends ESIntegTestCase { public void testTasksCancellation() throws Exception { // Start blocking test task // Get real client (the plugin is not registered on transport nodes) - ActionFuture future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()).execute(); + ActionFuture future = new TestTaskPlugin.NodesRequestBuilder(client(), + TestTaskPlugin.TestTaskAction.INSTANCE).execute(); logger.info("--> started test tasks"); // Wait for the task to start on all nodes @@ -518,12 +519,13 @@ public class TasksIT extends ESIntegTestCase { public void testTasksUnblocking() throws Exception { // Start blocking test task - ActionFuture future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()).execute(); + ActionFuture future = + new TestTaskPlugin.NodesRequestBuilder(client(), TestTaskPlugin.TestTaskAction.INSTANCE).execute(); // Wait for the task to start on all nodes assertBusy(() -> assertEquals(internalCluster().size(), client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "[n]").get().getTasks().size())); - TestTaskPlugin.UnblockTestTasksAction.INSTANCE.newRequestBuilder(client()).get(); + new TestTaskPlugin.UnblockTestTasksRequestBuilder(client(), TestTaskPlugin.UnblockTestTasksAction.INSTANCE).get(); future.get(); assertEquals(0, client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "[n]").get() @@ -581,8 +583,8 @@ public class TasksIT extends ESIntegTestCase { private void waitForCompletionTestCase(boolean storeResult, Function> wait, Consumer validator) throws Exception { // Start blocking test task - ActionFuture future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()) - .setShouldStoreResult(storeResult).execute(); + ActionFuture future = new TestTaskPlugin.NodesRequestBuilder(client(), + TestTaskPlugin.TestTaskAction.INSTANCE).setShouldStoreResult(storeResult).execute(); ActionFuture waitResponseFuture; TaskId taskId; @@ -620,7 +622,7 @@ public class TasksIT extends ESIntegTestCase { waitForWaitingToStart.await(); } finally { // Unblock the request so the wait for completion request can finish - TestTaskPlugin.UnblockTestTasksAction.INSTANCE.newRequestBuilder(client()).get(); + new TestTaskPlugin.UnblockTestTasksRequestBuilder(client(), TestTaskPlugin.UnblockTestTasksAction.INSTANCE).get(); } // Now that the task is unblocked the list response will come back @@ -655,7 +657,8 @@ public class TasksIT extends ESIntegTestCase { */ private void waitForTimeoutTestCase(Function> wait) throws Exception { // Start blocking test task - ActionFuture future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()).execute(); + ActionFuture future = new TestTaskPlugin.NodesRequestBuilder(client(), + TestTaskPlugin.TestTaskAction.INSTANCE).execute(); try { TaskId taskId = waitForTestTaskStartOnAllNodes(); @@ -672,7 +675,7 @@ public class TasksIT extends ESIntegTestCase { } } finally { // Now we can unblock those requests - TestTaskPlugin.UnblockTestTasksAction.INSTANCE.newRequestBuilder(client()).get(); + new TestTaskPlugin.UnblockTestTasksRequestBuilder(client(), TestTaskPlugin.UnblockTestTasksAction.INSTANCE).get(); } future.get(); } @@ -732,7 +735,8 @@ public class TasksIT extends ESIntegTestCase { registerTaskManageListeners(TestTaskPlugin.TestTaskAction.NAME); // we need this to get task id of the process // Start non-blocking test task - TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()).setShouldStoreResult(true).setShouldBlock(false).get(); + new TestTaskPlugin.NodesRequestBuilder(client(), TestTaskPlugin.TestTaskAction.INSTANCE) + .setShouldStoreResult(true).setShouldBlock(false).get(); List events = findEvents(TestTaskPlugin.TestTaskAction.NAME, Tuple::v1); @@ -782,7 +786,7 @@ public class TasksIT extends ESIntegTestCase { // Start non-blocking test task that should fail assertThrows( - TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()) + new TestTaskPlugin.NodesRequestBuilder(client(), TestTaskPlugin.TestTaskAction.INSTANCE) .setShouldFail(true) .setShouldStoreResult(true) .setShouldBlock(false), diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java index 5bf000a17ba..a98c9088b8d 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TestTaskPlugin.java @@ -323,7 +323,7 @@ public class TestTaskPlugin extends Plugin implements ActionPlugin { } - public static class TestTaskAction extends Action { + public static class TestTaskAction extends Action { public static final TestTaskAction INSTANCE = new TestTaskAction(); public static final String NAME = "cluster:admin/tasks/test"; @@ -336,16 +336,11 @@ public class TestTaskPlugin extends Plugin implements ActionPlugin { public NodesResponse newResponse() { return new NodesResponse(); } - - @Override - public NodesRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new NodesRequestBuilder(client, this); - } } public static class NodesRequestBuilder extends NodesOperationRequestBuilder { - protected NodesRequestBuilder(ElasticsearchClient client, Action action) { + protected NodesRequestBuilder(ElasticsearchClient client, Action action) { super(client, action, new NodesRequest("test")); } @@ -459,8 +454,7 @@ public class TestTaskPlugin extends Plugin implements ActionPlugin { } - public static class UnblockTestTasksAction extends Action { + public static class UnblockTestTasksAction extends Action { public static final UnblockTestTasksAction INSTANCE = new UnblockTestTasksAction(); public static final String NAME = "cluster:admin/tasks/testunblock"; @@ -473,18 +467,12 @@ public class TestTaskPlugin extends Plugin implements ActionPlugin { public UnblockTestTasksResponse newResponse() { return new UnblockTestTasksResponse(); } - - @Override - public UnblockTestTasksRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new UnblockTestTasksRequestBuilder(client, this); - } } - public static class UnblockTestTasksRequestBuilder extends ActionRequestBuilder { + public static class UnblockTestTasksRequestBuilder extends ActionRequestBuilder { - protected UnblockTestTasksRequestBuilder(ElasticsearchClient client, Action action) { + protected UnblockTestTasksRequestBuilder(ElasticsearchClient client, + Action action) { super(client, action, new UnblockTestTasksRequest()); } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java index 577a8b55e61..c21e6b3c225 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java @@ -150,7 +150,9 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase { + + private XContentBuilder getRandomXContentBuilder() throws IOException { + XContentType xContentType = randomFrom(XContentType.values()); + return XContentBuilder.builder(xContentType.xContent()); + } + + private PipelineConfiguration createRandomPipeline(String pipelineId) throws IOException { + String field = "field_" + randomInt(); + String value = "value_" + randomInt(); + XContentBuilder builder = getRandomXContentBuilder(); + builder.startObject(); + // We only use a single SetProcessor here in each pipeline to test. + // Since the contents are returned as a configMap anyway this does not matter for fromXContent + builder.startObject("set"); + builder.field("field", field); + builder.field("value", value); + builder.endObject(); + builder.endObject(); + return + new PipelineConfiguration( + pipelineId, BytesReference.bytes(builder), builder.contentType() + ); + } + + private Map createPipelineConfigMap() throws IOException { + int numPipelines = randomInt(5); + Map pipelinesMap = new HashMap<>(); + for (int i=0; i pipelinesMap = createPipelineConfigMap(); + GetPipelineResponse response = new GetPipelineResponse(new ArrayList<>(pipelinesMap.values())); + XContentBuilder builder = response.toXContent(getRandomXContentBuilder(), ToXContent.EMPTY_PARAMS); + XContentParser parser = + builder + .generator() + .contentType() + .xContent() + .createParser( + xContentRegistry(), + LoggingDeprecationHandler.INSTANCE, + BytesReference.bytes(builder).streamInput() + ); + GetPipelineResponse parsedResponse = GetPipelineResponse.fromXContent(parser); + List actualPipelines = response.pipelines(); + List parsedPipelines = parsedResponse.pipelines(); + assertEquals(actualPipelines.size(), parsedPipelines.size()); + for (PipelineConfiguration pipeline: parsedPipelines) { + assertTrue(pipelinesMap.containsKey(pipeline.getId())); + assertEquals(pipelinesMap.get(pipeline.getId()).getConfigAsMap(), pipeline.getConfigAsMap()); + } + } + + @Override + protected GetPipelineResponse doParseInstance(XContentParser parser) throws IOException { + return GetPipelineResponse.fromXContent(parser); + } + + @Override + protected GetPipelineResponse createBlankInstance() { + return new GetPipelineResponse(); + } + + @Override + protected GetPipelineResponse createTestInstance() { + try { + return new GetPipelineResponse(new ArrayList<>(createPipelineConfigMap().values())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected GetPipelineResponse mutateInstance(GetPipelineResponse response) { + try { + List clonePipelines = new ArrayList<>(response.pipelines()); + clonePipelines.add(createRandomPipeline("pipeline_" + clonePipelines.size() + 1)); + return new GetPipelineResponse(clonePipelines); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/server/src/test/java/org/elasticsearch/action/ingest/PutPipelineResponseTests.java b/server/src/test/java/org/elasticsearch/action/ingest/PutPipelineResponseTests.java deleted file mode 100644 index 438d3e55044..00000000000 --- a/server/src/test/java/org/elasticsearch/action/ingest/PutPipelineResponseTests.java +++ /dev/null @@ -1,53 +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.action.ingest; - -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; - -public class PutPipelineResponseTests extends AbstractStreamableXContentTestCase { - - public void testToXContent() { - PutPipelineResponse response = new PutPipelineResponse(true); - String output = Strings.toString(response); - assertEquals("{\"acknowledged\":true}", output); - } - - @Override - protected PutPipelineResponse doParseInstance(XContentParser parser) { - return PutPipelineResponse.fromXContent(parser); - } - - @Override - protected PutPipelineResponse createTestInstance() { - return new PutPipelineResponse(randomBoolean()); - } - - @Override - protected PutPipelineResponse createBlankInstance() { - return new PutPipelineResponse(); - } - - @Override - protected PutPipelineResponse mutateInstance(PutPipelineResponse response) { - return new PutPipelineResponse(response.isAcknowledged() == false); - } -} diff --git a/server/src/test/java/org/elasticsearch/action/ingest/WritePipelineResponseTests.java b/server/src/test/java/org/elasticsearch/action/ingest/WritePipelineResponseTests.java index 00327603ba8..f68545c3f79 100644 --- a/server/src/test/java/org/elasticsearch/action/ingest/WritePipelineResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/ingest/WritePipelineResponseTests.java @@ -19,15 +19,17 @@ package org.elasticsearch.action.ingest; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; import java.io.IOException; import static org.hamcrest.CoreMatchers.equalTo; -public class WritePipelineResponseTests extends ESTestCase { +public class WritePipelineResponseTests extends AbstractStreamableXContentTestCase { public void testSerializationWithoutError() throws IOException { boolean isAcknowledged = randomBoolean(); @@ -52,4 +54,30 @@ public class WritePipelineResponseTests extends ESTestCase { assertThat(otherResponse.isAcknowledged(), equalTo(response.isAcknowledged())); } + + public void testToXContent() { + WritePipelineResponse response = new WritePipelineResponse(true); + String output = Strings.toString(response); + assertEquals("{\"acknowledged\":true}", output); + } + + @Override + protected WritePipelineResponse doParseInstance(XContentParser parser) { + return WritePipelineResponse.fromXContent(parser); + } + + @Override + protected WritePipelineResponse createTestInstance() { + return new WritePipelineResponse(randomBoolean()); + } + + @Override + protected WritePipelineResponse createBlankInstance() { + return new WritePipelineResponse(); + } + + @Override + protected WritePipelineResponse mutateInstance(WritePipelineResponse response) { + return new WritePipelineResponse(response.isAcknowledged() == false); + } } diff --git a/server/src/test/java/org/elasticsearch/client/ParentTaskAssigningClientTests.java b/server/src/test/java/org/elasticsearch/client/ParentTaskAssigningClientTests.java index ee577d4df2f..00b293bcffb 100644 --- a/server/src/test/java/org/elasticsearch/client/ParentTaskAssigningClientTests.java +++ b/server/src/test/java/org/elasticsearch/client/ParentTaskAssigningClientTests.java @@ -40,8 +40,8 @@ public class ParentTaskAssigningClientTests extends ESTestCase { @Override protected < Request extends ActionRequest, Response extends ActionResponse, - RequestBuilder extends ActionRequestBuilder - > void doExecute( Action action, Request request, + RequestBuilder extends ActionRequestBuilder + > void doExecute( Action action, Request request, ActionListener listener) { assertEquals(parentTaskId[0], request.getParentTask()); super.doExecute(action, request, listener); diff --git a/server/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/server/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index 1830698d90c..1dc30e951b6 100644 --- a/server/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/server/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.transport.MockTransportClient; +import org.elasticsearch.transport.TcpTransport; import java.io.IOException; import java.util.Arrays; @@ -38,6 +39,8 @@ import java.util.List; import java.util.concurrent.ExecutionException; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.object.HasToString.hasToString; public class TransportClientTests extends ESTestCase { @@ -64,13 +67,23 @@ public class TransportClientTests extends ESTestCase { } } - public void testDefaultHeaderContainsPlugins() { - Settings baseSettings = Settings.builder() + public void testSettingsContainsTransportClient() { + final Settings baseSettings = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); try (TransportClient client = new MockTransportClient(baseSettings, Arrays.asList(MockPlugin.class))) { - ThreadContext threadContext = client.threadPool().getThreadContext(); - assertEquals("true", threadContext.getHeader("transport_client")); + final Settings settings = TcpTransport.DEFAULT_FEATURES_SETTING.get(client.settings()); + assertThat(settings.keySet(), hasItem("transport_client")); + assertThat(settings.get("transport_client"), equalTo("true")); + } + } + + public void testDefaultHeader() { + final Settings baseSettings = Settings.builder() + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) + .build(); + try (TransportClient client = new MockTransportClient(baseSettings, Arrays.asList(MockPlugin.class))) { + final ThreadContext threadContext = client.threadPool().getThreadContext(); assertEquals("true", threadContext.getHeader("test")); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 176616690f0..efd80266452 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -19,6 +19,8 @@ package org.elasticsearch.cluster; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.metadata.RepositoriesMetaData; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision; @@ -251,4 +253,29 @@ public class ClusterModuleTests extends ModuleTestCase { assertEquals(ise.getMessage(), "custom supplier key [foo] is registered more than once"); } } + + public void testPre63CustomsFiltering() { + final String whiteListedClusterCustom = randomFrom(ClusterModule.PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST); + final String whiteListedMetaDataCustom = randomFrom(ClusterModule.PRE_6_3_METADATA_CUSTOMS_WHITE_LIST); + final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) + .putCustom(whiteListedClusterCustom, new RestoreInProgress()) + .putCustom("other", new RestoreInProgress()) + .metaData(MetaData.builder() + .putCustom(whiteListedMetaDataCustom, new RepositoriesMetaData(Collections.emptyList())) + .putCustom("other", new RepositoriesMetaData(Collections.emptyList())) + .build()) + .build(); + + assertNotNull(clusterState.custom(whiteListedClusterCustom)); + assertNotNull(clusterState.custom("other")); + assertNotNull(clusterState.metaData().custom(whiteListedMetaDataCustom)); + assertNotNull(clusterState.metaData().custom("other")); + + final ClusterState fixedClusterState = ClusterModule.filterCustomsForPre63Clients(clusterState); + + assertNotNull(fixedClusterState.custom(whiteListedClusterCustom)); + assertNull(fixedClusterState.custom("other")); + assertNotNull(fixedClusterState.metaData().custom(whiteListedMetaDataCustom)); + assertNull(fixedClusterState.metaData().custom("other")); + } } diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/ClusterStateIT.java new file mode 100644 index 00000000000..07a974a2ca7 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterStateIT.java @@ -0,0 +1,340 @@ +/* + * 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.cluster; + +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.IndexGraveyard; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.CheckedFunction; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.Priority; +import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.script.ScriptService; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TcpTransport; +import org.elasticsearch.watcher.ResourceWatcherService; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; +import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.instanceOf; + +/** + * This test suite sets up a situation where the cluster has two plugins installed (node, and node-and-transport-client), and a transport + * client only has node-and-transport-client plugin installed. Each of these plugins inject customs into the cluster state and we want to + * check that the client can de-serialize a cluster state response based on the fact that the response should not contain customs that the + * transport client does not understand based on the fact that it only presents the node-and-transport-client-feature. + */ +@ESIntegTestCase.ClusterScope(scope = TEST) +public class ClusterStateIT extends ESIntegTestCase { + + public abstract static class Custom implements MetaData.Custom { + + private static final ParseField VALUE = new ParseField("value"); + + private final int value; + + int value() { + return value; + } + + Custom(final int value) { + this.value = value; + } + + Custom(final StreamInput in) throws IOException { + value = in.readInt(); + } + + @Override + public EnumSet context() { + return MetaData.ALL_CONTEXTS; + } + + @Override + public Diff diff(final MetaData.Custom previousState) { + return null; + } + + @Override + public void writeTo(final StreamOutput out) throws IOException { + out.writeInt(value); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(VALUE.getPreferredName(), value); + return builder; + } + + } + + public static class NodeCustom extends Custom { + + public static final String TYPE = "node"; + + NodeCustom(final int value) { + super(value); + } + + NodeCustom(final StreamInput in) throws IOException { + super(in); + } + + @Override + public String getWriteableName() { + return TYPE; + } + + @Override + public Optional getRequiredFeature() { + return Optional.of("node"); + } + + } + + public static class NodeAndTransportClientCustom extends Custom { + + public static final String TYPE = "node-and-transport-client"; + + NodeAndTransportClientCustom(final int value) { + super(value); + } + + public NodeAndTransportClientCustom(final StreamInput in) throws IOException { + super(in); + } + + @Override + public String getWriteableName() { + return TYPE; + } + + /* + * This custom should always be returned yet we randomize whether it has a required feature that the client is expected to have + * versus not requiring any feature. We use a field to make the random choice exactly once. + */ + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + private final Optional requiredFeature = randomBoolean() ? Optional.empty() : Optional.of("node-and-transport-client"); + + @Override + public Optional getRequiredFeature() { + return requiredFeature; + } + + } + + public abstract static class CustomPlugin extends Plugin { + + private final List namedWritables = new ArrayList<>(); + private final List namedXContents = new ArrayList<>(); + + public CustomPlugin() { + registerBuiltinWritables(); + } + + protected void registerMetaDataCustom( + final String name, final Writeable.Reader reader, final CheckedFunction parser) { + namedWritables.add(new NamedWriteableRegistry.Entry(MetaData.Custom.class, name, reader)); + namedXContents.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(name), parser)); + } + + protected abstract void registerBuiltinWritables(); + + protected abstract String getType(); + + protected abstract Custom getInstance(); + + @Override + public List getNamedWriteables() { + return namedWritables; + } + + @Override + public List getNamedXContent() { + return namedXContents; + } + + private final AtomicBoolean installed = new AtomicBoolean(); + + @Override + public Collection createComponents( + final Client client, + final ClusterService clusterService, + final ThreadPool threadPool, + final ResourceWatcherService resourceWatcherService, + final ScriptService scriptService, + final NamedXContentRegistry xContentRegistry, + final Environment environment, + final NodeEnvironment nodeEnvironment, + final NamedWriteableRegistry namedWriteableRegistry) { + clusterService.addListener(event -> { + final ClusterState state = event.state(); + if (state.getBlocks().hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK)) { + return; + } + + final MetaData metaData = state.metaData(); + if (state.nodes().isLocalNodeElectedMaster()) { + if (metaData.custom(getType()) == null) { + if (installed.compareAndSet(false, true)) { + clusterService.submitStateUpdateTask("install-metadata-custom", new ClusterStateUpdateTask(Priority.URGENT) { + + @Override + public ClusterState execute(ClusterState currentState) { + if (currentState.custom(getType()) == null) { + final MetaData.Builder builder = MetaData.builder(currentState.metaData()); + builder.putCustom(getType(), getInstance()); + return ClusterState.builder(currentState).metaData(builder).build(); + } else { + return currentState; + } + } + + @Override + public void onFailure(String source, Exception e) { + throw new AssertionError(e); + } + + }); + } + } + } + + }); + return Collections.emptyList(); + } + } + + public static class NodePlugin extends CustomPlugin { + + public Optional getFeature() { + return Optional.of("node"); + } + + static final int VALUE = randomInt(); + + @Override + protected void registerBuiltinWritables() { + registerMetaDataCustom( + NodeCustom.TYPE, + NodeCustom::new, + parser -> { + throw new IOException(new UnsupportedOperationException()); + }); + } + + @Override + protected String getType() { + return NodeCustom.TYPE; + } + + @Override + protected Custom getInstance() { + return new NodeCustom(VALUE); + } + + } + + public static class NodeAndTransportClientPlugin extends CustomPlugin { + + @Override + protected Optional getFeature() { + return Optional.of("node-and-transport-client"); + } + + static final int VALUE = randomInt(); + + @Override + protected void registerBuiltinWritables() { + registerMetaDataCustom( + NodeAndTransportClientCustom.TYPE, + NodeAndTransportClientCustom::new, + parser -> { + throw new IOException(new UnsupportedOperationException()); + }); + } + + @Override + protected String getType() { + return NodeAndTransportClientCustom.TYPE; + } + + @Override + protected Custom getInstance() { + return new NodeAndTransportClientCustom(VALUE); + } + + } + + @Override + protected Collection> nodePlugins() { + return Arrays.asList(NodePlugin.class, NodeAndTransportClientPlugin.class); + } + + @Override + protected Collection> transportClientPlugins() { + return Collections.singletonList(NodeAndTransportClientPlugin.class); + } + + public void testOptionalCustoms() throws Exception { + // ensure that the customs are injected into the cluster state + assertBusy(() -> assertTrue(clusterService().state().metaData().customs().containsKey(NodeCustom.TYPE))); + assertBusy(() -> assertTrue(clusterService().state().metaData().customs().containsKey(NodeAndTransportClientCustom.TYPE))); + final ClusterStateResponse state = internalCluster().transportClient().admin().cluster().prepareState().get(); + final ImmutableOpenMap customs = state.getState().metaData().customs(); + final Set keys = new HashSet<>(Arrays.asList(customs.keys().toArray(String.class))); + assertThat(keys, hasItem(IndexGraveyard.TYPE)); + assertThat(keys, not(hasItem(NodeCustom.TYPE))); + assertThat(keys, hasItem(NodeAndTransportClientCustom.TYPE)); + final MetaData.Custom actual = customs.get(NodeAndTransportClientCustom.TYPE); + assertThat(actual, instanceOf(NodeAndTransportClientCustom.class)); + assertThat(((NodeAndTransportClientCustom)actual).value(), equalTo(NodeAndTransportClientPlugin.VALUE)); + } + +} diff --git a/server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java b/server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java new file mode 100644 index 00000000000..0f826e65248 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/FeatureAwareTests.java @@ -0,0 +1,175 @@ +/* + * 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.cluster; + +import org.elasticsearch.Version; +import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.cluster.ClusterState.FeatureAware; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.VersionUtils; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Optional; + +import static org.elasticsearch.test.VersionUtils.randomVersionBetween; + +public class FeatureAwareTests extends ESTestCase { + + abstract static class Custom implements MetaData.Custom { + + private final Version version; + + Custom(final Version version) { + this.version = version; + } + + @Override + public EnumSet context() { + return MetaData.ALL_CONTEXTS; + } + + @Override + public Diff diff(final MetaData.Custom previousState) { + return null; + } + + @Override + public void writeTo(final StreamOutput out) throws IOException { + + } + + @Override + public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { + return builder; + } + + @Override + public Version getMinimalSupportedVersion() { + return version; + } + + } + + static class NoRequiredFeatureCustom extends Custom { + + NoRequiredFeatureCustom(final Version version) { + super(version); + } + + @Override + public String getWriteableName() { + return "no-required-feature"; + } + + } + + static class RequiredFeatureCustom extends Custom { + + RequiredFeatureCustom(final Version version) { + super(version); + } + + @Override + public String getWriteableName() { + return null; + } + + @Override + public Optional getRequiredFeature() { + return Optional.of("required-feature"); + } + + } + + public void testVersion() { + final Version version = randomValueOtherThan(VersionUtils.getFirstVersion(), () -> VersionUtils.randomVersion(random())); + for (final Custom custom : Arrays.asList(new NoRequiredFeatureCustom(version), new RequiredFeatureCustom(version))) { + { + final BytesStreamOutput out = new BytesStreamOutput(); + final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT); + out.setVersion(afterVersion); + if (custom.getRequiredFeature().isPresent()) { + out.setFeatures(Collections.singleton(custom.getRequiredFeature().get())); + } + assertTrue(FeatureAware.shouldSerializeCustom(out, custom)); + } + { + final BytesStreamOutput out = new BytesStreamOutput(); + final Version beforeVersion = + randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion(version)); + out.setVersion(beforeVersion); + if (custom.getRequiredFeature().isPresent() && randomBoolean()) { + out.setFeatures(Collections.singleton(custom.getRequiredFeature().get())); + } + assertFalse(FeatureAware.shouldSerializeCustom(out, custom)); + } + } + } + + public void testFeature() { + final Version version = VersionUtils.randomVersion(random()); + final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT); + final Custom custom = new RequiredFeatureCustom(version); + { + // the feature is present and the client is not a transport client + final BytesStreamOutput out = new BytesStreamOutput(); + out.setVersion(afterVersion); + assertTrue(custom.getRequiredFeature().isPresent()); + out.setFeatures(Collections.singleton(custom.getRequiredFeature().get())); + assertTrue(FeatureAware.shouldSerializeCustom(out, custom)); + } + { + // the feature is present and the client is a transport client + final BytesStreamOutput out = new BytesStreamOutput(); + out.setVersion(afterVersion); + assertTrue(custom.getRequiredFeature().isPresent()); + out.setFeatures(new HashSet<>(Arrays.asList(custom.getRequiredFeature().get(), TransportClient.TRANSPORT_CLIENT_FEATURE))); + assertTrue(FeatureAware.shouldSerializeCustom(out, custom)); + } + } + + public void testMissingFeature() { + final Version version = VersionUtils.randomVersion(random()); + final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT); + final Custom custom = new RequiredFeatureCustom(version); + { + // the feature is missing but we should serialize it anyway because the client is not a transport client + final BytesStreamOutput out = new BytesStreamOutput(); + out.setVersion(afterVersion); + assertTrue(FeatureAware.shouldSerializeCustom(out, custom)); + } + { + // the feature is missing and we should not serialize it because the client is a transport client + final BytesStreamOutput out = new BytesStreamOutput(); + out.setVersion(afterVersion); + out.setFeatures(Collections.singleton(TransportClient.TRANSPORT_CLIENT_FEATURE)); + assertFalse(FeatureAware.shouldSerializeCustom(out, custom)); + } + } + +} diff --git a/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java b/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java index a271f7415d4..b8a5e26d5c9 100644 --- a/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java @@ -139,7 +139,7 @@ public class NoMasterNodeIT extends ESIntegTestCase { client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet(); } - void checkUpdateAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder builder) { + void checkUpdateAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder builder) { // we clean the metadata when loosing a master, therefore all operations on indices will auto create it, if allowed try { builder.get(); @@ -154,7 +154,7 @@ public class NoMasterNodeIT extends ESIntegTestCase { } } - void checkWriteAction(ActionRequestBuilder builder) { + void checkWriteAction(ActionRequestBuilder builder) { try { builder.get(); fail("Expected ClusterBlockException"); diff --git a/server/src/test/java/org/elasticsearch/index/analysis/CustomNormalizerTests.java b/server/src/test/java/org/elasticsearch/index/analysis/CustomNormalizerTests.java index e2025145241..0a1f625f203 100644 --- a/server/src/test/java/org/elasticsearch/index/analysis/CustomNormalizerTests.java +++ b/server/src/test/java/org/elasticsearch/index/analysis/CustomNormalizerTests.java @@ -54,6 +54,12 @@ public class CustomNormalizerTests extends ESTokenStreamTestCase { assertEquals("my_normalizer", normalizer.name()); assertTokenStreamContents(normalizer.tokenStream("foo", "Cet été-là"), new String[] {"cet été-là"}); assertEquals(new BytesRef("cet été-là"), normalizer.normalize("foo", "Cet été-là")); + + normalizer = analysis.indexAnalyzers.getWhitespaceNormalizer("my_normalizer"); + assertNotNull(normalizer); + assertEquals("my_normalizer", normalizer.name()); + assertTokenStreamContents(normalizer.tokenStream("foo", "Cet été-là"), new String[] {"cet", "été-là"}); + assertEquals(new BytesRef("cet été-là"), normalizer.normalize("foo", "Cet été-là")); } public void testUnknownType() { @@ -88,7 +94,13 @@ public class CustomNormalizerTests extends ESTokenStreamTestCase { NamedAnalyzer normalizer = analysis.indexAnalyzers.getNormalizer("my_normalizer"); assertNotNull(normalizer); assertEquals("my_normalizer", normalizer.name()); - assertTokenStreamContents(normalizer.tokenStream("foo", "abc"), new String[] {"zbc"}); + assertTokenStreamContents(normalizer.tokenStream("foo", "abc acd"), new String[] {"zbc zcd"}); + assertEquals(new BytesRef("zbc"), normalizer.normalize("foo", "abc")); + + normalizer = analysis.indexAnalyzers.getWhitespaceNormalizer("my_normalizer"); + assertNotNull(normalizer); + assertEquals("my_normalizer", normalizer.name()); + assertTokenStreamContents(normalizer.tokenStream("foo", "abc acd"), new String[] {"zbc", "zcd"}); assertEquals(new BytesRef("zbc"), normalizer.normalize("foo", "abc")); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java index efb2023ee69..8d8a2f98866 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java @@ -105,14 +105,6 @@ public class FakeStringFieldMapper extends FieldMapper { return CONTENT_TYPE; } - @Override - public Query nullValueQuery() { - if (nullValue() == null) { - return null; - } - return termQuery(nullValue(), null); - } - @Override public Query existsQuery(QueryShardContext context) { if (hasDocValues()) { @@ -136,7 +128,7 @@ public class FakeStringFieldMapper extends FieldMapper { } else { value = context.parser().textOrNull(); } - + if (value == null) { return; } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java index 86cf7b4b766..56e587dc995 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java @@ -51,9 +51,11 @@ import java.util.List; import java.util.Map; import static java.util.Collections.singletonList; +import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertTokenStreamContents; import static java.util.Collections.singletonMap; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; public class KeywordFieldMapperTests extends ESSingleNodeTestCase { /** @@ -411,4 +413,59 @@ public class KeywordFieldMapperTests extends ESSingleNodeTestCase { ); assertThat(e.getMessage(), containsString("name cannot be empty string")); } + + public void testSplitQueriesOnWhitespace() throws IOException { + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() + .startObject("type") + .startObject("properties") + .startObject("field") + .field("type", "keyword") + .endObject() + .startObject("field_with_normalizer") + .field("type", "keyword") + .field("normalizer", "my_lowercase") + .field("split_queries_on_whitespace", true) + .endObject() + .endObject() + .endObject().endObject()); + indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + + MappedFieldType fieldType = indexService.mapperService().fullName("field"); + assertThat(fieldType, instanceOf(KeywordFieldMapper.KeywordFieldType.class)); + KeywordFieldMapper.KeywordFieldType ft = (KeywordFieldMapper.KeywordFieldType) fieldType; + assertTokenStreamContents(ft.searchAnalyzer().analyzer().tokenStream("", "Hello World"), new String[] {"Hello World"}); + + fieldType = indexService.mapperService().fullName("field_with_normalizer"); + assertThat(fieldType, instanceOf(KeywordFieldMapper.KeywordFieldType.class)); + ft = (KeywordFieldMapper.KeywordFieldType) fieldType; + assertThat(ft.searchAnalyzer().name(), equalTo("my_lowercase")); + assertTokenStreamContents(ft.searchAnalyzer().analyzer().tokenStream("", "Hello World"), new String[] {"hello", "world"}); + + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() + .startObject("type") + .startObject("properties") + .startObject("field") + .field("type", "keyword") + .field("split_queries_on_whitespace", true) + .endObject() + .startObject("field_with_normalizer") + .field("type", "keyword") + .field("normalizer", "my_lowercase") + .field("split_queries_on_whitespace", false) + .endObject() + .endObject() + .endObject().endObject()); + indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + + fieldType = indexService.mapperService().fullName("field"); + assertThat(fieldType, instanceOf(KeywordFieldMapper.KeywordFieldType.class)); + ft = (KeywordFieldMapper.KeywordFieldType) fieldType; + assertTokenStreamContents(ft.searchAnalyzer().analyzer().tokenStream("", "Hello World"), new String[] {"Hello", "World"}); + + fieldType = indexService.mapperService().fullName("field_with_normalizer"); + assertThat(fieldType, instanceOf(KeywordFieldMapper.KeywordFieldType.class)); + ft = (KeywordFieldMapper.KeywordFieldType) fieldType; + assertThat(ft.searchAnalyzer().name(), equalTo("my_lowercase")); + assertTokenStreamContents(ft.searchAnalyzer().analyzer().tokenStream("", "Hello World"), new String[] {"hello world"}); + } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java index d9ebca3a3a1..772762997fa 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java @@ -734,25 +734,6 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase { Query q6 = mapper.mappers().getMapper("field").fieldType().prefixQuery("goings", CONSTANT_SCORE_REWRITE, queryShardContext); assertThat(q6, instanceOf(PrefixQuery.class)); - - indexService.mapperService().merge("type", json, MergeReason.MAPPING_UPDATE); - - String badUpdate = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") - .startObject("properties").startObject("field") - .field("type", "text") - .field("analyzer", "english") - .startObject("index_prefixes") - .field("min_chars", 1) - .field("max_chars", 10) - .endObject() - .endObject().endObject() - .endObject().endObject()); - - IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { - indexService.mapperService() - .merge("type", new CompressedXContent(badUpdate), MergeReason.MAPPING_UPDATE); - }); - assertThat(e.getMessage(), containsString("mapper [field._index_prefix] has different min_chars values")); } { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java index 815e946e023..d0eacfad440 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java @@ -18,23 +18,20 @@ */ package org.elasticsearch.index.mapper; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.lucene.document.LongPoint; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.RegexpQuery; +import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.unit.Fuzziness; -import org.elasticsearch.index.mapper.MappedFieldType; -import org.elasticsearch.index.mapper.TextFieldMapper; import org.junit.Before; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class TextFieldTypeTests extends FieldTypeTestCase { @Override protected MappedFieldType createDefaultFieldType() { @@ -71,7 +68,7 @@ public class TextFieldTypeTests extends FieldTypeTestCase { tft.setFielddataMinSegmentSize(1000); } }); - addModifier(new Modifier("index_prefixes", true) { + addModifier(new Modifier("index_prefixes", false) { @Override public void modify(MappedFieldType ft) { TextFieldMapper.TextFieldType tft = (TextFieldMapper.TextFieldType)ft; diff --git a/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java b/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java index dbc6294920e..19973f4eb98 100644 --- a/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java +++ b/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.search; import org.apache.lucene.analysis.MockSynonymAnalyzer; import org.apache.lucene.index.Term; import org.apache.lucene.queries.BlendedTermQuery; +import org.apache.lucene.queryparser.xml.builders.DisjunctionMaxQueryBuilder; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BoostQuery; @@ -33,9 +34,12 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.SynonymQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContent; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.mapper.MapperService; @@ -43,12 +47,16 @@ import org.elasticsearch.index.mapper.MockFieldMapper.FakeFieldType; import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.MockKeywordPlugin; import org.junit.Before; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,6 +68,11 @@ public class MultiMatchQueryTests extends ESSingleNodeTestCase { private IndexService indexService; + @Override + protected Collection> getPlugins() { + return Collections.singleton(MockKeywordPlugin.class); + } + @Before public void setup() throws IOException { Settings settings = Settings.builder() @@ -276,4 +289,58 @@ public class MultiMatchQueryTests extends ESSingleNodeTestCase { .build(); assertEquals(expected, query); } + + public void testKeywordSplitQueriesOnWhitespace() throws IOException { + IndexService indexService = createIndex("test_keyword", Settings.builder() + .put("index.analysis.normalizer.my_lowercase.type", "custom") + .putList("index.analysis.normalizer.my_lowercase.filter", "lowercase").build()); + MapperService mapperService = indexService.mapperService(); + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() + .startObject("type") + .startObject("properties") + .startObject("field") + .field("type", "keyword") + .endObject() + .startObject("field_normalizer") + .field("type", "keyword") + .field("normalizer", "my_lowercase") + .endObject() + .startObject("field_split") + .field("type", "keyword") + .field("split_queries_on_whitespace", true) + .endObject() + .startObject("field_split_normalizer") + .field("type", "keyword") + .field("normalizer", "my_lowercase") + .field("split_queries_on_whitespace", true) + .endObject() + .endObject() + .endObject().endObject()); + mapperService.merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); + QueryShardContext queryShardContext = indexService.newQueryShardContext( + randomInt(20), null, () -> { + throw new UnsupportedOperationException(); + }, null); + MultiMatchQuery parser = new MultiMatchQuery(queryShardContext); + Map fieldNames = new HashMap<>(); + fieldNames.put("field", 1.0f); + fieldNames.put("field_split", 1.0f); + fieldNames.put("field_normalizer", 1.0f); + fieldNames.put("field_split_normalizer", 1.0f); + Query query = parser.parse(MultiMatchQueryBuilder.Type.BEST_FIELDS, fieldNames, "Foo Bar", null); + DisjunctionMaxQuery expected = new DisjunctionMaxQuery( + Arrays.asList( + new TermQuery(new Term("field_normalizer", "foo bar")), + new TermQuery(new Term("field", "Foo Bar")), + new BooleanQuery.Builder() + .add(new TermQuery(new Term("field_split", "Foo")), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term("field_split", "Bar")), BooleanClause.Occur.SHOULD) + .build(), + new BooleanQuery.Builder() + .add(new TermQuery(new Term("field_split_normalizer", "foo")), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term("field_split_normalizer", "bar")), BooleanClause.Occur.SHOULD) + .build() + ), 0.0f); + assertThat(query, equalTo(expected)); + } } diff --git a/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java b/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java index 556d6d1983e..63ef871c0e3 100644 --- a/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java +++ b/server/src/test/java/org/elasticsearch/persistent/TestPersistentTasksPlugin.java @@ -360,7 +360,7 @@ public class TestPersistentTasksPlugin extends Plugin implements ActionPlugin, P } } - public static class TestTaskAction extends Action { + public static class TestTaskAction extends Action { public static final TestTaskAction INSTANCE = new TestTaskAction(); public static final String NAME = "cluster:admin/persistent/task_test"; @@ -373,11 +373,6 @@ public class TestPersistentTasksPlugin extends Plugin implements ActionPlugin, P public TestTasksResponse newResponse() { return new TestTasksResponse(); } - - @Override - public TestTasksRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new TestTasksRequestBuilder(client); - } } diff --git a/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java b/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java index 23cb579bfdc..d39d33b9d3e 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/RepositoriesIT.java @@ -40,7 +40,6 @@ import java.util.List; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; diff --git a/server/src/test/java/org/elasticsearch/tasks/ListTasksResponseTests.java b/server/src/test/java/org/elasticsearch/tasks/ListTasksResponseTests.java index 295ff955e41..b280446db1c 100644 --- a/server/src/test/java/org/elasticsearch/tasks/ListTasksResponseTests.java +++ b/server/src/test/java/org/elasticsearch/tasks/ListTasksResponseTests.java @@ -23,29 +23,29 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.TaskOperationFailure; import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractXContentTestCase; import java.io.IOException; +import java.net.ConnectException; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; +import java.util.function.Predicate; +import java.util.function.Supplier; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.instanceOf; public class ListTasksResponseTests extends AbstractXContentTestCase { public void testEmptyToString() { - assertEquals("{\"tasks\":[]}", new ListTasksResponse().toString()); + assertEquals("{\n" + + " \"tasks\" : [ ]\n" + + "}", new ListTasksResponse().toString()); } public void testNonEmptyToString() { @@ -53,48 +53,113 @@ public class ListTasksResponseTests extends AbstractXContentTestCase randomTasks() { List tasks = new ArrayList<>(); for (int i = 0; i < randomInt(10); i++) { tasks.add(TaskInfoTests.randomTaskInfo()); } - List taskFailures = new ArrayList<>(); - for (int i = 0; i < randomInt(5); i++) { - taskFailures.add(new TaskOperationFailure( - randomAlphaOfLength(5), randomNonNegativeLong(), new IllegalStateException("message"))); - } - return new ListTasksResponse(tasks, taskFailures, Collections.singletonList(new FailedNodeException("", "message", null))); + return tasks; } @Override - protected ListTasksResponse doParseInstance(XContentParser parser) throws IOException { + protected ListTasksResponse doParseInstance(XContentParser parser) { return ListTasksResponse.fromXContent(parser); } @Override protected boolean supportsUnknownFields() { - return false; + return true; + } + + @Override + protected Predicate getRandomFieldsExcludeFilter() { + //status and headers hold arbitrary content, we can't inject random fields in them + return field -> field.endsWith("status") || field.endsWith("headers"); } @Override protected void assertEqualInstances(ListTasksResponse expectedInstance, ListTasksResponse newInstance) { assertNotSame(expectedInstance, newInstance); assertThat(newInstance.getTasks(), equalTo(expectedInstance.getTasks())); - assertThat(newInstance.getNodeFailures().size(), equalTo(1)); - for (ElasticsearchException failure : newInstance.getNodeFailures()) { - assertThat(failure, notNullValue()); - assertThat(failure.getMessage(), equalTo("Elasticsearch exception [type=failed_node_exception, reason=message]")); + assertThat(newInstance.getNodeFailures().size(), equalTo(expectedInstance.getNodeFailures().size())); + for (int i = 0; i < newInstance.getNodeFailures().size(); i++) { + ElasticsearchException newException = newInstance.getNodeFailures().get(i); + ElasticsearchException expectedException = expectedInstance.getNodeFailures().get(i); + assertThat(newException.getMetadata("es.node_id").get(0), equalTo(((FailedNodeException)expectedException).nodeId())); + assertThat(newException.getMessage(), equalTo("Elasticsearch exception [type=failed_node_exception, reason=error message]")); + assertThat(newException.getCause(), instanceOf(ElasticsearchException.class)); + ElasticsearchException cause = (ElasticsearchException) newException.getCause(); + assertThat(cause.getMessage(), equalTo("Elasticsearch exception [type=connect_exception, reason=null]")); + } + assertThat(newInstance.getTaskFailures().size(), equalTo(expectedInstance.getTaskFailures().size())); + for (int i = 0; i < newInstance.getTaskFailures().size(); i++) { + TaskOperationFailure newFailure = newInstance.getTaskFailures().get(i); + TaskOperationFailure expectedFailure = expectedInstance.getTaskFailures().get(i); + assertThat(newFailure.getNodeId(), equalTo(expectedFailure.getNodeId())); + assertThat(newFailure.getTaskId(), equalTo(expectedFailure.getTaskId())); + assertThat(newFailure.getStatus(), equalTo(expectedFailure.getStatus())); + assertThat(newFailure.getCause(), instanceOf(ElasticsearchException.class)); + ElasticsearchException cause = (ElasticsearchException) newFailure.getCause(); + assertThat(cause.getMessage(), equalTo("Elasticsearch exception [type=illegal_state_exception, reason=null]")); } } - @Override - protected boolean assertToXContentEquivalence() { - return false; + /** + * Test parsing {@link ListTasksResponse} with inner failures as they don't support asserting on xcontent equivalence, given that + * exceptions are not parsed back as the same original class. We run the usual {@link AbstractXContentTestCase#testFromXContent()} + * without failures, and this other test with failures where we disable asserting on xcontent equivalence at the end. + */ + public void testFromXContentWithFailures() throws IOException { + Supplier instanceSupplier = ListTasksResponseTests::createTestInstanceWithFailures; + //with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata, + //but that does not bother our assertions, as we only want to test that we don't break. + boolean supportsUnknownFields = true; + //exceptions are not of the same type whenever parsed back + boolean assertToXContentEquivalence = false; + AbstractXContentTestCase.testFromXContent(NUMBER_OF_TEST_RUNS, instanceSupplier, supportsUnknownFields, Strings.EMPTY_ARRAY, + getRandomFieldsExcludeFilter(), this::createParser, this::doParseInstance, + this::assertEqualInstances, assertToXContentEquivalence); + } + + private static ListTasksResponse createTestInstanceWithFailures() { + int numNodeFailures = randomIntBetween(0, 3); + List nodeFailures = new ArrayList<>(numNodeFailures); + for (int i = 0; i < numNodeFailures; i++) { + nodeFailures.add(new FailedNodeException(randomAlphaOfLength(5), "error message", new ConnectException())); + } + int numTaskFailures = randomIntBetween(0, 3); + List taskFailures = new ArrayList<>(numTaskFailures); + for (int i = 0; i < numTaskFailures; i++) { + taskFailures.add(new TaskOperationFailure(randomAlphaOfLength(5), randomLong(), new IllegalStateException())); + } + return new ListTasksResponse(randomTasks(), taskFailures, nodeFailures); } } diff --git a/server/src/test/java/org/elasticsearch/tasks/TaskInfoTests.java b/server/src/test/java/org/elasticsearch/tasks/TaskInfoTests.java index 616ac105387..bc57109802a 100644 --- a/server/src/test/java/org/elasticsearch/tasks/TaskInfoTests.java +++ b/server/src/test/java/org/elasticsearch/tasks/TaskInfoTests.java @@ -63,11 +63,12 @@ public class TaskInfoTests extends AbstractSerializingTestCase { @Override protected Predicate getRandomFieldsExcludeFilter() { + //status and headers hold arbitrary content, we can't inject random fields in them return field -> "status".equals(field) || "headers".equals(field); } @Override - protected TaskInfo mutateInstance(TaskInfo info) throws IOException { + protected TaskInfo mutateInstance(TaskInfo info) { switch (between(0, 9)) { case 0: TaskId taskId = new TaskId(info.getTaskId().getNodeId() + randomAlphaOfLength(5), info.getTaskId().getId()); diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java index 69096677664..0739ff5633b 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java @@ -19,15 +19,9 @@ package org.elasticsearch.transport; import org.apache.lucene.store.AlreadyClosedException; -import org.elasticsearch.core.internal.io.IOUtils; -import org.elasticsearch.Build; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.LatchedActionListener; -import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsGroup; import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; @@ -42,17 +36,16 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Strings; import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.CancellableThreads; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.http.HttpInfo; +import org.elasticsearch.core.internal.io.IOUtils; +import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.mocksocket.MockServerSocket; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.VersionUtils; @@ -121,8 +114,12 @@ public class RemoteClusterConnectionTests extends ESTestCase { try { newService.registerRequestHandler(ClusterSearchShardsAction.NAME,ThreadPool.Names.SAME, ClusterSearchShardsRequest::new, (request, channel) -> { - channel.sendResponse(new ClusterSearchShardsResponse(new ClusterSearchShardsGroup[0], - knownNodes.toArray(new DiscoveryNode[0]), Collections.emptyMap())); + if ("index_not_found".equals(request.preference())) { + channel.sendResponse(new IndexNotFoundException("index")); + } else { + channel.sendResponse(new ClusterSearchShardsResponse(new ClusterSearchShardsGroup[0], + knownNodes.toArray(new DiscoveryNode[0]), Collections.emptyMap())); + } }); newService.registerRequestHandler(ClusterStateAction.NAME, ThreadPool.Names.SAME, ClusterStateRequest::new, (request, channel) -> { diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java index 5529f98af33..03d76b5a953 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.core.internal.io.IOUtils; +import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.transport.MockTransportService; @@ -469,7 +470,6 @@ public class RemoteClusterServiceTests extends ESTestCase { assertEquals("no such remote cluster: [no such cluster]", ex.get().getMessage()); } { - logger.info("closing all source nodes"); // close all targets and check for the transport level failure path IOUtils.close(c1N1, c1N2, c2N1, c2N2); @@ -559,7 +559,20 @@ public class RemoteClusterServiceTests extends ESTestCase { assertEquals(1, shardsResponse.getNodes().length); } } - + { + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference> response = new AtomicReference<>(); + AtomicReference failure = new AtomicReference<>(); + remoteClusterService.collectSearchShards(IndicesOptions.lenientExpandOpen(), "index_not_found", + null, remoteIndicesByCluster, + new LatchedActionListener<>(ActionListener.wrap(response::set, failure::set), latch)); + assertTrue(latch.await(1, TimeUnit.SECONDS)); + assertNull(response.get()); + assertNotNull(failure.get()); + assertThat(failure.get(), instanceOf(RemoteTransportException.class)); + RemoteTransportException remoteTransportException = (RemoteTransportException) failure.get(); + assertEquals(RestStatus.NOT_FOUND, remoteTransportException.status()); + } int numDisconnectedClusters = randomIntBetween(1, numClusters); Set disconnectedNodes = new HashSet<>(numDisconnectedClusters); Set disconnectedNodesIndices = new HashSet<>(numDisconnectedClusters); @@ -593,8 +606,9 @@ public class RemoteClusterServiceTests extends ESTestCase { assertTrue(latch.await(1, TimeUnit.SECONDS)); assertNull(response.get()); assertNotNull(failure.get()); - assertThat(failure.get(), instanceOf(TransportException.class)); - assertThat(failure.get().getMessage(), containsString("unable to communicate with remote cluster")); + assertThat(failure.get(), instanceOf(RemoteTransportException.class)); + assertThat(failure.get().getMessage(), containsString("error while communicating with remote cluster [")); + assertThat(failure.get().getCause(), instanceOf(NodeDisconnectedException.class)); } //setting skip_unavailable to true for all the disconnected clusters will make the request succeed again diff --git a/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java b/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java index 2cedb5419e0..7e83e1cdc0b 100644 --- a/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java @@ -227,6 +227,7 @@ public class TcpTransportTests extends ESTestCase { .streamInput(streamIn); } threadPool.getThreadContext().readHeaders(streamIn); + assertThat(streamIn.readStringArray(), equalTo(new String[0])); // features assertEquals("foobar", streamIn.readString()); Req readReq = new Req(""); readReq.readFrom(streamIn); diff --git a/server/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java b/server/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java index 08d88ad2e04..ed1dfded078 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java @@ -20,6 +20,8 @@ package org.elasticsearch.transport; import org.elasticsearch.Version; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; @@ -178,6 +180,42 @@ public class TransportServiceHandshakeTests extends ESTestCase { assertFalse(handleA.transportService.nodeConnected(discoveryNode)); } + public void testNodeConnectWithDifferentNodeIdSucceedsIfThisIsTransportClientOfSimpleNodeSampler() { + Settings.Builder settings = Settings.builder().put("cluster.name", "test"); + Settings transportClientSettings = settings.put(Client.CLIENT_TYPE_SETTING_S.getKey(), TransportClient.CLIENT_TYPE).build(); + NetworkHandle handleA = startServices("TS_A", transportClientSettings, Version.CURRENT); + NetworkHandle handleB = startServices("TS_B", settings.build(), Version.CURRENT); + DiscoveryNode discoveryNode = new DiscoveryNode( + randomAlphaOfLength(10), + handleB.discoveryNode.getAddress(), + emptyMap(), + emptySet(), + handleB.discoveryNode.getVersion()); + + handleA.transportService.connectToNode(discoveryNode, MockTcpTransport.LIGHT_PROFILE); + assertTrue(handleA.transportService.nodeConnected(discoveryNode)); + } + + public void testNodeConnectWithDifferentNodeIdFailsWhenSnifferTransportClient() { + Settings.Builder settings = Settings.builder().put("cluster.name", "test"); + Settings transportClientSettings = settings.put(Client.CLIENT_TYPE_SETTING_S.getKey(), TransportClient.CLIENT_TYPE) + .put(TransportClient.CLIENT_TRANSPORT_SNIFF.getKey(), true) + .build(); + NetworkHandle handleA = startServices("TS_A", transportClientSettings, Version.CURRENT); + NetworkHandle handleB = startServices("TS_B", settings.build(), Version.CURRENT); + DiscoveryNode discoveryNode = new DiscoveryNode( + randomAlphaOfLength(10), + handleB.discoveryNode.getAddress(), + emptyMap(), + emptySet(), + handleB.discoveryNode.getVersion()); + ConnectTransportException ex = expectThrows(ConnectTransportException.class, () -> { + handleA.transportService.connectToNode(discoveryNode, MockTcpTransport.LIGHT_PROFILE); + }); + assertThat(ex.getMessage(), containsString("unexpected remote node")); + assertFalse(handleA.transportService.nodeConnected(discoveryNode)); + } + private static class NetworkHandle { private TransportService transportService; diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java b/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java index 4fe18fa9738..53fe89ac17e 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java @@ -61,7 +61,7 @@ public class TranslogHandler implements EngineConfig.TranslogRecoveryRunner { public TranslogHandler(NamedXContentRegistry xContentRegistry, IndexSettings indexSettings) { NamedAnalyzer defaultAnalyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer()); IndexAnalyzers indexAnalyzers = - new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, emptyMap(), emptyMap()); + new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, emptyMap(), emptyMap(), emptyMap()); SimilarityService similarityService = new SimilarityService(indexSettings, null, emptyMap()); MapperRegistry mapperRegistry = new IndicesModule(emptyList()).getMapperRegistry(); mapperService = new MapperService(indexSettings, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry, diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 505a5937d29..8b58cea4d0a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -26,7 +26,6 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.apache.http.HttpHost; import org.apache.lucene.search.Sort; -import org.elasticsearch.core.internal.io.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; @@ -68,12 +67,18 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; +import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.RestoreInProgress; +import org.elasticsearch.cluster.SnapshotDeletionsInProgress; +import org.elasticsearch.cluster.SnapshotsInProgress; import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.metadata.IndexGraveyard; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.metadata.RepositoriesMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; @@ -105,6 +110,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; +import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.zen.ElectMasterService; import org.elasticsearch.discovery.zen.ZenDiscovery; @@ -130,9 +136,11 @@ import org.elasticsearch.indices.IndicesQueryCache; import org.elasticsearch.indices.IndicesRequestCache; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.store.IndicesStore; +import org.elasticsearch.ingest.IngestMetadata; import org.elasticsearch.node.NodeMocksPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.script.ScriptMetaData; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.MockSearchService; import org.elasticsearch.search.SearchHit; @@ -1108,7 +1116,8 @@ public abstract class ESIntegTestCase extends ESTestCase { protected void ensureClusterStateConsistency() throws IOException { if (cluster() != null && cluster().size() > 0) { final NamedWriteableRegistry namedWriteableRegistry = cluster().getNamedWriteableRegistry(); - ClusterState masterClusterState = client().admin().cluster().prepareState().all().get().getState(); + final Client masterClient = client(); + ClusterState masterClusterState = masterClient.admin().cluster().prepareState().all().get().getState(); byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState); // remove local node reference masterClusterState = ClusterState.Builder.fromBytes(masterClusterStateBytes, null, namedWriteableRegistry); @@ -1124,16 +1133,37 @@ public abstract class ESIntegTestCase extends ESTestCase { final int localClusterStateSize = ClusterState.Builder.toBytes(localClusterState).length; // Check that the non-master node has the same version of the cluster state as the master and // that the master node matches the master (otherwise there is no requirement for the cluster state to match) - if (masterClusterState.version() == localClusterState.version() && masterId.equals(localClusterState.nodes().getMasterNodeId())) { + if (masterClusterState.version() == localClusterState.version() + && masterId.equals(localClusterState.nodes().getMasterNodeId())) { try { - assertEquals("clusterstate UUID does not match", masterClusterState.stateUUID(), localClusterState.stateUUID()); - // We cannot compare serialization bytes since serialization order of maps is not guaranteed - // but we can compare serialization sizes - they should be the same - assertEquals("clusterstate size does not match", masterClusterStateSize, localClusterStateSize); - // Compare JSON serialization - assertNull("clusterstate JSON serialization does not match", differenceBetweenMapsIgnoringArrayOrder(masterStateMap, localStateMap)); - } catch (AssertionError error) { - logger.error("Cluster state from master:\n{}\nLocal cluster state:\n{}", masterClusterState.toString(), localClusterState.toString()); + assertEquals("cluster state UUID does not match", masterClusterState.stateUUID(), localClusterState.stateUUID()); + /* + * The cluster state received by the transport client can miss customs that the client does not understand. This + * means that we only expect equality in the cluster state including customs if the master client and the local + * client are of the same type (both or neither are transport clients). Otherwise, we can only assert equality + * modulo non-core customs. + */ + if (isTransportClient(masterClient) == isTransportClient(client)) { + // We cannot compare serialization bytes since serialization order of maps is not guaranteed + // but we can compare serialization sizes - they should be the same + assertEquals("cluster state size does not match", masterClusterStateSize, localClusterStateSize); + // Compare JSON serialization + assertNull( + "cluster state JSON serialization does not match", + differenceBetweenMapsIgnoringArrayOrder(masterStateMap, localStateMap)); + } else { + // remove non-core customs and compare the cluster states + assertNull( + "cluster state JSON serialization does not match (after removing some customs)", + differenceBetweenMapsIgnoringArrayOrder( + convertToMap(removePluginCustoms(masterClusterState)), + convertToMap(removePluginCustoms(localClusterState)))); + } + } catch (final AssertionError error) { + logger.error( + "Cluster state from master:\n{}\nLocal cluster state:\n{}", + masterClusterState.toString(), + localClusterState.toString()); throw error; } } @@ -1142,6 +1172,52 @@ public abstract class ESIntegTestCase extends ESTestCase { } + /** + * Tests if the client is a transport client or wraps a transport client. + * + * @param client the client to test + * @return true if the client is a transport client or a wrapped transport client + */ + private boolean isTransportClient(final Client client) { + if (TransportClient.class.isAssignableFrom(client.getClass())) { + return true; + } else if (client instanceof RandomizingClient) { + return isTransportClient(((RandomizingClient) client).in()); + } + return false; + } + + private static final Set SAFE_METADATA_CUSTOMS = + Collections.unmodifiableSet( + new HashSet<>(Arrays.asList(IndexGraveyard.TYPE, IngestMetadata.TYPE, RepositoriesMetaData.TYPE, ScriptMetaData.TYPE))); + + private static final Set SAFE_CUSTOMS = + Collections.unmodifiableSet( + new HashSet<>(Arrays.asList(RestoreInProgress.TYPE, SnapshotDeletionsInProgress.TYPE, SnapshotsInProgress.TYPE))); + + /** + * Remove any customs except for customs that we know all clients understand. + * + * @param clusterState the cluster state to remove possibly-unknown customs from + * @return the cluster state with possibly-unknown customs removed + */ + private ClusterState removePluginCustoms(final ClusterState clusterState) { + final ClusterState.Builder builder = ClusterState.builder(clusterState); + clusterState.customs().keysIt().forEachRemaining(key -> { + if (SAFE_CUSTOMS.contains(key) == false) { + builder.removeCustom(key); + } + }); + final MetaData.Builder mdBuilder = MetaData.builder(clusterState.metaData()); + clusterState.metaData().customs().keysIt().forEachRemaining(key -> { + if (SAFE_METADATA_CUSTOMS.contains(key) == false) { + mdBuilder.removeCustom(key); + } + }); + builder.metaData(mdBuilder); + return builder.build(); + } + /** * Ensures the cluster is in a searchable state for the given indices. This means a searchable copy of each * shard is available on the cluster. diff --git a/test/framework/src/main/java/org/elasticsearch/test/client/NoOpClient.java b/test/framework/src/main/java/org/elasticsearch/test/client/NoOpClient.java index c393e19653f..93cb3475a12 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/client/NoOpClient.java +++ b/test/framework/src/main/java/org/elasticsearch/test/client/NoOpClient.java @@ -53,8 +53,8 @@ public class NoOpClient extends AbstractClient { @Override protected > - void doExecute(Action action, Request request, ActionListener listener) { + RequestBuilder extends ActionRequestBuilder> + void doExecute(Action action, Request request, ActionListener listener) { listener.onResponse(null); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/client/RandomizingClient.java b/test/framework/src/main/java/org/elasticsearch/test/client/RandomizingClient.java index e1a6ba030fd..4c826101780 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/client/RandomizingClient.java +++ b/test/framework/src/main/java/org/elasticsearch/test/client/RandomizingClient.java @@ -93,4 +93,8 @@ public class RandomizingClient extends FilterClient { return "randomized(" + super.toString() + ")"; } + public Client in() { + return super.in(); + } + } diff --git a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 723184410f2..30b24c0daa5 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -490,14 +490,14 @@ public class ElasticsearchAssertions { /** * Run the request from a given builder and check that it throws an exception of the right type */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass) { assertThrows(builder.execute(), exceptionClass); } /** * Run the request from a given builder and check that it throws an exception of the right type, with a given {@link org.elasticsearch.rest.RestStatus} */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, RestStatus status) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, RestStatus status) { assertThrows(builder.execute(), exceptionClass, status); } @@ -506,7 +506,7 @@ public class ElasticsearchAssertions { * * @param extraInfo extra information to add to the failure message */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, String extraInfo) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, String extraInfo) { assertThrows(builder.execute(), exceptionClass, extraInfo); } @@ -570,11 +570,11 @@ public class ElasticsearchAssertions { } } - public static void assertThrows(ActionRequestBuilder builder, RestStatus status) { + public static void assertThrows(ActionRequestBuilder builder, RestStatus status) { assertThrows(builder.execute(), status); } - public static void assertThrows(ActionRequestBuilder builder, RestStatus status, String extraInfo) { + public static void assertThrows(ActionRequestBuilder builder, RestStatus status, String extraInfo) { assertThrows(builder.execute(), status, extraInfo); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 30ac94e3432..a9f64b3f78b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -322,8 +322,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { if (useDefaultNumberOfShards == false && testCandidate.getTestSection().getSkipSection().getFeatures().contains("default_shards") == false) { final Request request = new Request("PUT", "/_template/global"); - request.addHeader("Content-Type", XContentType.JSON.mediaTypeWithoutParameters()); - request.setEntity(new StringEntity("{\"index_patterns\":[\"*\"],\"settings\":{\"index.number_of_shards\":2}}")); + request.setJsonEntity("{\"index_patterns\":[\"*\"],\"settings\":{\"index.number_of_shards\":2}}"); adminClient().performRequest(request); } diff --git a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index 9a44f99c7c6..6c53ca6edb3 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -23,7 +23,6 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.Constants; -import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; @@ -32,7 +31,6 @@ import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.network.NetworkService; @@ -45,6 +43,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; +import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.mocksocket.MockServerSocket; import org.elasticsearch.node.Node; diff --git a/x-pack/docs/en/ml/architecture.asciidoc b/x-pack/docs/en/ml/architecture.asciidoc index d16a8301da1..6fc3e36964f 100644 --- a/x-pack/docs/en/ml/architecture.asciidoc +++ b/x-pack/docs/en/ml/architecture.asciidoc @@ -6,4 +6,5 @@ A {ml} node is a node that has `xpack.ml.enabled` and `node.ml` set to `true`, which is the default behavior. If you set `node.ml` to `false`, the node can service API requests but it cannot run jobs. If you want to use {xpackml} features, there must be at least one {ml} node in your cluster. For more -information about this setting, see <>. +information about this setting, see +{ref}/ml-settings.html[{ml} settings in {es}]. diff --git a/x-pack/docs/en/ml/configuring.asciidoc b/x-pack/docs/en/ml/configuring.asciidoc index b794d3ebd33..ba965a08b04 100644 --- a/x-pack/docs/en/ml/configuring.asciidoc +++ b/x-pack/docs/en/ml/configuring.asciidoc @@ -3,8 +3,8 @@ If you want to use {xpackml} features, there must be at least one {ml} node in your cluster and all master-eligible nodes must have {ml} enabled. By default, -all nodes are {ml} nodes. For more information about these settings, see -<>. +all nodes are {ml} nodes. For more information about these settings, see +{ref}/modules-node.html#modules-node-xpack[{ml} nodes]. To use the {xpackml} features to analyze your data, you must create a job and send your data to that job. diff --git a/x-pack/docs/en/ml/getting-started-next.asciidoc b/x-pack/docs/en/ml/getting-started-next.asciidoc index 87174747592..90d1e7798ee 100644 --- a/x-pack/docs/en/ml/getting-started-next.asciidoc +++ b/x-pack/docs/en/ml/getting-started-next.asciidoc @@ -51,5 +51,5 @@ multi-metric jobs and split the data or create more complex analysis functions as necessary. For examples of more complicated configuration options, see <>. -If you encounter problems, we're here to help. See <> and +If you encounter problems, we're here to help. See <> and <>. diff --git a/x-pack/docs/en/ml/getting-started.asciidoc b/x-pack/docs/en/ml/getting-started.asciidoc index 2fd4f1ebe49..0f1b7164d4a 100644 --- a/x-pack/docs/en/ml/getting-started.asciidoc +++ b/x-pack/docs/en/ml/getting-started.asciidoc @@ -1,7 +1,7 @@ [[ml-getting-started]] -== Getting Started with Machine Learning +== Getting started with machine learning ++++ -Getting Started +Getting started ++++ Ready to get some hands-on experience with the {xpackml} features? This @@ -50,7 +50,8 @@ you can try all of the {xpack} features with a <>. +activity related to jobs, see +{ref}/modules-node.html#modules-node-xpack[{ml} node settings]. [float] [[ml-gs-users]] diff --git a/x-pack/docs/en/ml/troubleshooting.asciidoc b/x-pack/docs/en/ml/troubleshooting.asciidoc index 3412845e980..d5244cebdae 100644 --- a/x-pack/docs/en/ml/troubleshooting.asciidoc +++ b/x-pack/docs/en/ml/troubleshooting.asciidoc @@ -10,7 +10,7 @@ answers for frequently asked questions. * <> * <> -To get help, see <>. +To get help, see <>. [[ml-rollingupgrade]] === Machine learning features unavailable after rolling upgrade diff --git a/x-pack/docs/en/security/securing-communications/node-certificates.asciidoc b/x-pack/docs/en/security/securing-communications/node-certificates.asciidoc index 604355e21bf..44ef8278fb9 100644 --- a/x-pack/docs/en/security/securing-communications/node-certificates.asciidoc +++ b/x-pack/docs/en/security/securing-communications/node-certificates.asciidoc @@ -4,7 +4,7 @@ TLS requires X.509 certificates to perform encryption and authentication of the application that is being communicated with. In order for the communication between nodes to be truly secure, the certificates must be validated. The -recommended approach for validating certificate authenticity in a {es} cluster +recommended approach for validating certificate authenticity in an {es} cluster is to trust the certificate authority (CA) that signed the certificate. By doing this, as nodes are added to your cluster they just need to use a certificate signed by the same CA and the node is automatically allowed to join the cluster. diff --git a/x-pack/docs/en/security/securing-communications/tls-transport.asciidoc b/x-pack/docs/en/security/securing-communications/tls-transport.asciidoc index 2e20a20f907..c186aebbe24 100644 --- a/x-pack/docs/en/security/securing-communications/tls-transport.asciidoc +++ b/x-pack/docs/en/security/securing-communications/tls-transport.asciidoc @@ -30,9 +30,13 @@ See <> for a description of the <2> If you created a separate certificate for each node, then you might need to customize this path on each node. If the filename matches the node name, you can use the `certs/${node.name}.p12` format, for example. -<3> The `elasticsearch-certutil` output includes the CA certificate inside the -PKCS#12 keystore, therefore the keystore can also be used as the truststore. -This name should match the `keystore.path` value. +<3> The `elasticsearch-certutil` outputs a PKCS#12 keystore which includes the +CA certificate as a trusted certificate entry. This allows for the keystore to +also be used as a truststore. In this case, the path value should match +the `keystore.path` value. +Note, however, that this is not the general rule. There are keystores that cannot be +used as trustores, only +{ref}/security-settings.html#pkcs12-truststore-note[specifically crafted ones can] -- ** If the certificate is in PEM format, add the following information to the diff --git a/x-pack/docs/en/security/troubleshooting.asciidoc b/x-pack/docs/en/security/troubleshooting.asciidoc index c202ed9dbed..622bc753d2a 100644 --- a/x-pack/docs/en/security/troubleshooting.asciidoc +++ b/x-pack/docs/en/security/troubleshooting.asciidoc @@ -19,7 +19,7 @@ answers for frequently asked questions. * <> -To get help, see <>. +To get help, see <>. [[security-trb-settings]] === Some settings are not returned via the nodes settings API diff --git a/x-pack/docs/en/settings/security-settings.asciidoc b/x-pack/docs/en/settings/security-settings.asciidoc index 587cbb79417..a98bca67615 100644 --- a/x-pack/docs/en/settings/security-settings.asciidoc +++ b/x-pack/docs/en/settings/security-settings.asciidoc @@ -1225,6 +1225,19 @@ Password to the truststore. `xpack.ssl.truststore.secure_password` (<>):: Password to the truststore. +[[pkcs12-truststore-note]] +[NOTE] +Storing trusted certificates in a PKCS#12 file, although supported, is +uncommon in practice. The {ref}/certutil.html[`elasticsearch-certutil`] tool, +as well as Java's `keytool`, are designed to generate PKCS#12 files that +can be used both as a keystore and as a truststore, but this may not be the +case for container files that are created using other tools. Usually, +PKCS#12 files only contain secret and private entries. To confirm that +a PKCS#12 container includes trusted certificate ("anchor") entries look for +`2.16.840.1.113894.746875.1.1: ` in the +`openssl pkcs12 -info` output, or `trustedCertEntry` in the +`keytool -list` output. + [[http-tls-ssl-settings]] :ssl-prefix: xpack.security.http :component: HTTP diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java index de356870fbb..309246ca9d7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.license; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class DeleteLicenseAction extends Action { +public class DeleteLicenseAction extends Action { public static final DeleteLicenseAction INSTANCE = new DeleteLicenseAction(); public static final String NAME = "cluster:admin/xpack/license/delete"; @@ -21,9 +20,4 @@ public class DeleteLicenseAction extends Action { +public class GetBasicStatusAction extends Action { public static final GetBasicStatusAction INSTANCE = new GetBasicStatusAction(); public static final String NAME = "cluster:admin/xpack/license/basic_status"; @@ -17,11 +16,6 @@ public class GetBasicStatusAction extends Action { +class GetBasicStatusRequestBuilder extends ActionRequestBuilder { GetBasicStatusRequestBuilder(ElasticsearchClient client, GetBasicStatusAction action) { super(client, action, new GetBasicStatusRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetLicenseAction.java index 47263410796..be8d46e31d0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/GetLicenseAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.license; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class GetLicenseAction extends Action { +public class GetLicenseAction extends Action { public static final GetLicenseAction INSTANCE = new GetLicenseAction(); public static final String NAME = "cluster:monitor/xpack/license/get"; @@ -21,9 +20,4 @@ public class GetLicenseAction extends Action { +public class GetTrialStatusAction extends Action { public static final GetTrialStatusAction INSTANCE = new GetTrialStatusAction(); public static final String NAME = "cluster:admin/xpack/license/trial_status"; @@ -17,11 +16,6 @@ public class GetTrialStatusAction extends Action { +class GetTrialStatusRequestBuilder extends ActionRequestBuilder { GetTrialStatusRequestBuilder(ElasticsearchClient client, GetTrialStatusAction action) { super(client, action, new GetTrialStatusRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java index 56475de123f..d9f7068b218 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicensesMetaData.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.License.OperationMode; +import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; import java.util.EnumSet; @@ -23,7 +24,7 @@ import java.util.EnumSet; /** * Contains metadata about registered licenses */ -public class LicensesMetaData extends AbstractNamedDiffable implements MetaData.Custom, +public class LicensesMetaData extends AbstractNamedDiffable implements XPackPlugin.XPackMetaDataCustom, MergableCustomMetaData { public static final String TYPE = "licenses"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicAction.java index eb55b1be006..747632d9d1d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.license; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class PostStartBasicAction extends Action { +public class PostStartBasicAction extends Action { public static final PostStartBasicAction INSTANCE = new PostStartBasicAction(); public static final String NAME = "cluster:admin/xpack/license/start_basic"; @@ -17,11 +16,6 @@ public class PostStartBasicAction extends Action { +class PostStartBasicRequestBuilder extends ActionRequestBuilder { PostStartBasicRequestBuilder(ElasticsearchClient client, PostStartBasicAction action) { super(client, action, new PostStartBasicRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialAction.java index b0634ef22a9..c7817f73b91 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.license; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class PostStartTrialAction extends Action { +public class PostStartTrialAction extends Action { public static final PostStartTrialAction INSTANCE = new PostStartTrialAction(); public static final String NAME = "cluster:admin/xpack/license/start_trial"; @@ -17,11 +16,6 @@ public class PostStartTrialAction extends Action { +class PostStartTrialRequestBuilder extends ActionRequestBuilder { PostStartTrialRequestBuilder(ElasticsearchClient client, PostStartTrialAction action) { super(client, action, new PostStartTrialRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseAction.java index 4aee591b9c5..b96f13190ed 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PutLicenseAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.license; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class PutLicenseAction extends Action { +public class PutLicenseAction extends Action { public static final PutLicenseAction INSTANCE = new PutLicenseAction(); public static final String NAME = "cluster:admin/xpack/license/put"; @@ -21,9 +20,4 @@ public class PutLicenseAction extends Action> void executeAsyncWithOrigin( - Client client, String origin, Action action, Request request, + RequestBuilder extends ActionRequestBuilder> void executeAsyncWithOrigin( + Client client, String origin, Action action, Request request, ActionListener listener) { final ThreadContext threadContext = client.threadPool().getThreadContext(); final Supplier supplier = threadContext.newRestorableContext(false); @@ -139,8 +139,8 @@ public final class ClientHelper { * The listener to call when the action is complete */ public static > void executeWithHeadersAsync( - Map headers, String origin, Client client, Action action, Request request, + RequestBuilder extends ActionRequestBuilder> void executeWithHeadersAsync( + Map headers, String origin, Client client, Action action, Request request, ActionListener listener) { Map filteredHeaders = headers.entrySet().stream().filter(e -> SECURITY_HEADER_FILTERS.contains(e.getKey())) @@ -177,8 +177,8 @@ public final class ClientHelper { @Override protected > void doExecute( - Action action, Request request, ActionListener listener) { + RequestBuilder extends ActionRequestBuilder> void doExecute( + Action action, Request request, ActionListener listener) { final Supplier supplier = in().threadPool().getThreadContext().newRestorableContext(false); try (ThreadContext.StoredContext ignore = in().threadPool().getThreadContext().stashContext()) { in().threadPool().getThreadContext().putTransient(ACTION_ORIGIN_TRANSIENT_NAME, origin); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java index 0b22cd86fe6..a96de96fd4f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.PageCacheRecycler; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.license.DeleteLicenseAction; @@ -28,6 +27,7 @@ import org.elasticsearch.license.LicensesMetaData; import org.elasticsearch.license.PostStartBasicAction; import org.elasticsearch.license.PostStartTrialAction; import org.elasticsearch.license.PutLicenseAction; +import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; @@ -61,7 +61,6 @@ import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction; import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction; import org.elasticsearch.xpack.core.ml.action.GetFiltersAction; import org.elasticsearch.xpack.core.ml.action.GetInfluencersAction; -import org.elasticsearch.xpack.core.ml.action.MlInfoAction; import org.elasticsearch.xpack.core.ml.action.GetJobsAction; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction; @@ -69,6 +68,7 @@ import org.elasticsearch.xpack.core.ml.action.GetOverallBucketsAction; import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.action.IsolateDatafeedAction; import org.elasticsearch.xpack.core.ml.action.KillProcessAction; +import org.elasticsearch.xpack.core.ml.action.MlInfoAction; import org.elasticsearch.xpack.core.ml.action.OpenJobAction; import org.elasticsearch.xpack.core.ml.action.PersistJobAction; import org.elasticsearch.xpack.core.ml.action.PostCalendarEventsAction; @@ -91,7 +91,6 @@ import org.elasticsearch.xpack.core.ml.action.ValidateJobConfigAction; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState; import org.elasticsearch.xpack.core.ml.job.config.JobTaskStatus; import org.elasticsearch.xpack.core.monitoring.MonitoringFeatureSetUsage; -import org.elasticsearch.persistent.PersistentTaskParams; import org.elasticsearch.xpack.core.rollup.RollupFeatureSetUsage; import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction; @@ -133,6 +132,8 @@ import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl. import org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport; import org.elasticsearch.xpack.core.ssl.SSLService; import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction; +import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction; +import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction; import org.elasticsearch.xpack.core.watcher.WatcherFeatureSetUsage; import org.elasticsearch.xpack.core.watcher.WatcherMetaData; import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchAction; @@ -143,18 +144,25 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchAction import org.elasticsearch.xpack.core.watcher.transport.actions.put.PutWatchAction; import org.elasticsearch.xpack.core.watcher.transport.actions.service.WatcherServiceAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; -import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction; -import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Supplier; public class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPlugin { + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + static Optional X_PACK_FEATURE = Optional.of("x-pack"); + + @Override + protected Optional getFeature() { + return X_PACK_FEATURE; + } + private final Settings settings; public XPackClientPlugin(final Settings settings) { @@ -185,11 +193,10 @@ public class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPl static Settings additionalSettings(final Settings settings, final boolean enabled, final boolean transportClientMode) { if (enabled && transportClientMode) { - final Settings.Builder builder = Settings.builder(); - builder.put(SecuritySettings.addTransportSettings(settings)); - builder.put(SecuritySettings.addUserSettings(settings)); - builder.put(ThreadContext.PREFIX + "." + "has_xpack", true); - return builder.build(); + return Settings.builder() + .put(SecuritySettings.addTransportSettings(settings)) + .put(SecuritySettings.addUserSettings(settings)) + .build(); } else { return Settings.EMPTY; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 9568a36551c..602f4bdbc07 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -59,19 +59,15 @@ import org.elasticsearch.xpack.core.ssl.SSLConfigurationReloader; import org.elasticsearch.xpack.core.ssl.SSLService; import org.elasticsearch.xpack.core.watcher.WatcherMetaData; -import javax.security.auth.DestroyFailedException; - -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.security.AccessController; -import java.security.GeneralSecurityException; import java.security.PrivilegedAction; import java.time.Clock; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -316,4 +312,23 @@ public class XPackPlugin extends XPackClientPlugin implements ScriptPlugin, Exte } return config; } + + public interface XPackClusterStateCustom extends ClusterState.Custom { + + @Override + default Optional getRequiredFeature() { + return XPackClientPlugin.X_PACK_FEATURE; + } + + } + + public interface XPackMetaDataCustom extends MetaData.Custom { + + @Override + default Optional getRequiredFeature() { + return XPackClientPlugin.X_PACK_FEATURE; + } + + } + } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoAction.java index bdca705baff..585153000a2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoAction.java @@ -6,10 +6,9 @@ package org.elasticsearch.xpack.core.action; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.license.XPackInfoResponse; -public class XPackInfoAction extends Action { +public class XPackInfoAction extends Action { public static final String NAME = "cluster:monitor/xpack/info"; public static final XPackInfoAction INSTANCE = new XPackInfoAction(); @@ -18,11 +17,6 @@ public class XPackInfoAction extends Action { +public class XPackInfoRequestBuilder extends ActionRequestBuilder { public XPackInfoRequestBuilder(ElasticsearchClient client) { this(client, XPackInfoAction.INSTANCE); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageAction.java index 252283a1dfc..906aaf3f4da 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.xpack.core.action; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class XPackUsageAction extends Action { +public class XPackUsageAction extends Action { public static final String NAME = "cluster:monitor/xpack/usage"; public static final XPackUsageAction INSTANCE = new XPackUsageAction(); @@ -17,11 +16,6 @@ public class XPackUsageAction extends Action { +public class DeprecationInfoAction extends Action { public static final DeprecationInfoAction INSTANCE = new DeprecationInfoAction(); public static final String NAME = "cluster:admin/xpack/deprecation/info"; @@ -59,11 +58,6 @@ public class DeprecationInfoAction extends Action { +public class GraphExploreAction extends Action { public static final GraphExploreAction INSTANCE = new GraphExploreAction(); public static final String NAME = "indices:data/read/xpack/graph/explore"; @@ -22,9 +21,4 @@ public class GraphExploreAction extends Action { +public class GraphExploreRequestBuilder extends ActionRequestBuilder { public GraphExploreRequestBuilder(ElasticsearchClient client, GraphExploreAction action) { super(client, action, new GraphExploreRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java index 6af323f1510..861f386a909 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.persistent.PersistentTasksCustomMetaData; import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedJobValidator; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState; @@ -53,7 +54,7 @@ import java.util.TreeMap; import java.util.function.Supplier; import java.util.stream.Collectors; -public class MlMetadata implements MetaData.Custom { +public class MlMetadata implements XPackPlugin.XPackMetaDataCustom { private static final ParseField JOBS_FIELD = new ParseField("jobs"); private static final ParseField DATAFEEDS_FIELD = new ParseField("datafeeds"); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java index c66686136e7..3710f5b96f6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java @@ -27,7 +27,7 @@ import org.elasticsearch.xpack.core.ml.job.config.Job; import java.io.IOException; import java.util.Objects; -public class CloseJobAction extends Action { +public class CloseJobAction extends Action { public static final CloseJobAction INSTANCE = new CloseJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/close"; @@ -36,11 +36,6 @@ public class CloseJobAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, CloseJobAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarAction.java index 2a01282d411..4a7872ef66e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarAction.java @@ -19,8 +19,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class DeleteCalendarAction extends Action { +public class DeleteCalendarAction extends Action { public static final DeleteCalendarAction INSTANCE = new DeleteCalendarAction(); public static final String NAME = "cluster:admin/xpack/ml/calendars/delete"; @@ -29,11 +28,6 @@ public class DeleteCalendarAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, DeleteCalendarAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventAction.java index 01d5e3e3721..2fa475ff5e8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventAction.java @@ -20,8 +20,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class DeleteCalendarEventAction extends Action { +public class DeleteCalendarEventAction extends Action { public static final DeleteCalendarEventAction INSTANCE = new DeleteCalendarEventAction(); public static final String NAME = "cluster:admin/xpack/ml/calendars/events/delete"; @@ -30,11 +29,6 @@ public class DeleteCalendarEventAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, DeleteCalendarEventAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedAction.java index 6876294bdf3..c069a49117d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedAction.java @@ -23,8 +23,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class DeleteDatafeedAction extends Action { +public class DeleteDatafeedAction extends Action { public static final DeleteDatafeedAction INSTANCE = new DeleteDatafeedAction(); public static final String NAME = "cluster:admin/xpack/ml/datafeeds/delete"; @@ -33,11 +32,6 @@ public class DeleteDatafeedAction extends Action { +public class DeleteExpiredDataAction extends Action { public static final DeleteExpiredDataAction INSTANCE = new DeleteExpiredDataAction(); public static final String NAME = "cluster:admin/xpack/ml/delete_expired_data"; @@ -30,11 +29,6 @@ public class DeleteExpiredDataAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, DeleteExpiredDataAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteFilterAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteFilterAction.java index 86e343fda22..b214fd24648 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteFilterAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/DeleteFilterAction.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.util.Objects; -public class DeleteFilterAction extends Action { +public class DeleteFilterAction extends Action { public static final DeleteFilterAction INSTANCE = new DeleteFilterAction(); public static final String NAME = "cluster:admin/xpack/ml/filters/delete"; @@ -29,11 +29,6 @@ public class DeleteFilterAction extends Action { +public class DeleteJobAction extends Action { public static final DeleteJobAction INSTANCE = new DeleteJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/delete"; @@ -33,11 +33,6 @@ public class DeleteJobAction extends Action { +public class DeleteModelSnapshotAction extends Action { public static final DeleteModelSnapshotAction INSTANCE = new DeleteModelSnapshotAction(); public static final String NAME = "cluster:admin/xpack/ml/job/model_snapshots/delete"; @@ -29,11 +28,6 @@ public class DeleteModelSnapshotAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, DeleteModelSnapshotAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java index 9259aa0c604..019a52d16b3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java @@ -16,8 +16,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; -public class FinalizeJobExecutionAction extends Action { +public class FinalizeJobExecutionAction extends Action { public static final FinalizeJobExecutionAction INSTANCE = new FinalizeJobExecutionAction(); public static final String NAME = "cluster:internal/xpack/ml/job/finalize_job_execution"; @@ -26,11 +25,6 @@ public class FinalizeJobExecutionAction extends Action { +public class FlushJobAction extends Action { public static final FlushJobAction INSTANCE = new FlushJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/flush"; @@ -35,11 +35,6 @@ public class FlushJobAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, FlushJobAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java index 4868a1e73da..75ba8f19537 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ForecastJobAction.java @@ -24,8 +24,7 @@ import org.elasticsearch.xpack.core.ml.job.results.Forecast; import java.io.IOException; import java.util.Objects; -public class ForecastJobAction extends Action { +public class ForecastJobAction extends Action { public static final ForecastJobAction INSTANCE = new ForecastJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/forecast"; @@ -34,11 +33,6 @@ public class ForecastJobAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, ForecastJobAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetBucketsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetBucketsAction.java index dec819613cb..6abbd2dfbdf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetBucketsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetBucketsAction.java @@ -30,7 +30,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class GetBucketsAction extends Action { +public class GetBucketsAction extends Action { public static final GetBucketsAction INSTANCE = new GetBucketsAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/results/buckets/get"; @@ -39,11 +39,6 @@ public class GetBucketsAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsAction.java index 2fe993b5138..19cf114772d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsAction.java @@ -29,8 +29,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class GetCalendarEventsAction extends Action { +public class GetCalendarEventsAction extends Action { public static final GetCalendarEventsAction INSTANCE = new GetCalendarEventsAction(); public static final String NAME = "cluster:monitor/xpack/ml/calendars/events/get"; @@ -38,11 +37,6 @@ public class GetCalendarEventsAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsAction.java index f11d9ccbf86..60ab7adbbce 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsAction.java @@ -29,7 +29,7 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; -public class GetCalendarsAction extends Action { +public class GetCalendarsAction extends Action { public static final GetCalendarsAction INSTANCE = new GetCalendarsAction(); public static final String NAME = "cluster:monitor/xpack/ml/calendars/get"; @@ -38,11 +38,6 @@ public class GetCalendarsAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesAction.java index 84976c61e45..3bb45901399 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesAction.java @@ -29,8 +29,7 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; -public class GetCategoriesAction extends -Action { +public class GetCategoriesAction extends Action { public static final GetCategoriesAction INSTANCE = new GetCategoriesAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/results/categories/get"; @@ -39,11 +38,6 @@ Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, GetCategoriesAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java index 3f71ac2dc02..5bd6e96e79c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java @@ -25,8 +25,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class GetDatafeedsAction extends Action { +public class GetDatafeedsAction extends Action { public static final GetDatafeedsAction INSTANCE = new GetDatafeedsAction(); public static final String NAME = "cluster:monitor/xpack/ml/datafeeds/get"; @@ -37,11 +36,6 @@ public class GetDatafeedsAction extends Action { +public class GetDatafeedsStatsAction extends Action { public static final GetDatafeedsStatsAction INSTANCE = new GetDatafeedsStatsAction(); public static final String NAME = "cluster:monitor/xpack/ml/datafeeds/stats/get"; @@ -43,11 +42,6 @@ public class GetDatafeedsStatsAction extends Action { +public class GetFiltersAction extends Action { public static final GetFiltersAction INSTANCE = new GetFiltersAction(); public static final String NAME = "cluster:admin/xpack/ml/filters/get"; @@ -36,11 +36,6 @@ public class GetFiltersAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersAction.java index 39721b0c728..803bfda63eb 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersAction.java @@ -29,7 +29,7 @@ import java.io.IOException; import java.util.Objects; public class GetInfluencersAction -extends Action { +extends Action { public static final GetInfluencersAction INSTANCE = new GetInfluencersAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/results/influencers/get"; @@ -38,11 +38,6 @@ extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetJobsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetJobsAction.java index f315783330e..83823457734 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetJobsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetJobsAction.java @@ -25,7 +25,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class GetJobsAction extends Action { +public class GetJobsAction extends Action { public static final GetJobsAction INSTANCE = new GetJobsAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/get"; @@ -34,11 +34,6 @@ public class GetJobsAction extends Action { +public class GetJobsStatsAction extends Action { public static final GetJobsStatsAction INSTANCE = new GetJobsStatsAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/stats/get"; @@ -53,11 +53,6 @@ public class GetJobsStatsAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, GetJobsStatsAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsAction.java index 382b60a07d5..3bd99057760 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsAction.java @@ -29,8 +29,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class GetModelSnapshotsAction -extends Action { +public class GetModelSnapshotsAction extends Action { public static final GetModelSnapshotsAction INSTANCE = new GetModelSnapshotsAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/model_snapshots/get"; @@ -39,11 +38,6 @@ extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, GetModelSnapshotsAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsAction.java index ec1d5484255..81dad665577 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsAction.java @@ -48,8 +48,7 @@ import java.util.function.LongSupplier; * the interval. *

*/ -public class GetOverallBucketsAction - extends Action { +public class GetOverallBucketsAction extends Action { public static final GetOverallBucketsAction INSTANCE = new GetOverallBucketsAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/results/overall_buckets/get"; @@ -58,11 +57,6 @@ public class GetOverallBucketsAction super(NAME); } - @Override - public RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new RequestBuilder(client); - } - @Override public Response newResponse() { return new Response(); @@ -280,7 +274,7 @@ public class GetOverallBucketsAction } } - static class RequestBuilder extends ActionRequestBuilder { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java index 586a40af81a..7d1fb839704 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java @@ -29,7 +29,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class GetRecordsAction extends Action { +public class GetRecordsAction extends Action { public static final GetRecordsAction INSTANCE = new GetRecordsAction(); public static final String NAME = "cluster:monitor/xpack/ml/job/results/records/get"; @@ -38,11 +38,6 @@ public class GetRecordsAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java index 98ca6c29f4b..7bafe5056af 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java @@ -35,8 +35,7 @@ import java.util.Objects; * task ensures the current datafeed task can complete inconsequentially while * the datafeed persistent task may be stopped or reassigned on another node. */ -public class IsolateDatafeedAction - extends Action { +public class IsolateDatafeedAction extends Action { public static final IsolateDatafeedAction INSTANCE = new IsolateDatafeedAction(); public static final String NAME = "cluster:internal/xpack/ml/datafeed/isolate"; @@ -45,11 +44,6 @@ public class IsolateDatafeedAction super(NAME); } - @Override - public RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new RequestBuilder(client, this); - } - @Override public Response newResponse() { return new Response(); @@ -171,7 +165,7 @@ public class IsolateDatafeedAction } } - static class RequestBuilder extends ActionRequestBuilder { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, IsolateDatafeedAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/KillProcessAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/KillProcessAction.java index 48ee4432ff0..5edb988351b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/KillProcessAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/KillProcessAction.java @@ -16,8 +16,7 @@ import org.elasticsearch.common.io.stream.Writeable; import java.io.IOException; import java.util.Objects; -public class KillProcessAction extends Action { +public class KillProcessAction extends Action { public static final KillProcessAction INSTANCE = new KillProcessAction(); public static final String NAME = "cluster:internal/xpack/ml/job/kill/process"; @@ -26,17 +25,12 @@ public class KillProcessAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, KillProcessAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/MlInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/MlInfoAction.java index 53a0758bcf8..38544e57617 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/MlInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/MlInfoAction.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.Map; import java.util.Objects; -public class MlInfoAction extends Action { +public class MlInfoAction extends Action { public static final MlInfoAction INSTANCE = new MlInfoAction(); public static final String NAME = "cluster:monitor/xpack/ml/info/get"; @@ -30,11 +30,6 @@ public class MlInfoAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, MlInfoAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java index ffe82f2abe5..d6e351f7637 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java @@ -31,7 +31,7 @@ import org.elasticsearch.persistent.PersistentTaskParams; import java.io.IOException; import java.util.Objects; -public class OpenJobAction extends Action { +public class OpenJobAction extends Action { public static final OpenJobAction INSTANCE = new OpenJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/open"; @@ -41,11 +41,6 @@ public class OpenJobAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, OpenJobAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PersistJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PersistJobAction.java index 71f65051464..f1d86dd784a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PersistJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PersistJobAction.java @@ -16,7 +16,7 @@ import org.elasticsearch.common.io.stream.Writeable; import java.io.IOException; import java.util.Objects; -public class PersistJobAction extends Action { +public class PersistJobAction extends Action { public static final PersistJobAction INSTANCE = new PersistJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/persist"; @@ -25,11 +25,6 @@ public class PersistJobAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, PersistJobAction action) { super(client, action, new PersistJobAction.Request()); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventsAction.java index 82e9072751e..aa4fc9ee2ea 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventsAction.java @@ -30,8 +30,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -public class PostCalendarEventsAction extends Action { +public class PostCalendarEventsAction extends Action { public static final PostCalendarEventsAction INSTANCE = new PostCalendarEventsAction(); public static final String NAME = "cluster:admin/xpack/ml/calendars/events/post"; @@ -41,11 +40,6 @@ public class PostCalendarEventsAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostDataAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostDataAction.java index 9ba1bf574db..69dd7e69ca1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostDataAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PostDataAction.java @@ -24,7 +24,7 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import java.io.IOException; import java.util.Objects; -public class PostDataAction extends Action { +public class PostDataAction extends Action { public static final PostDataAction INSTANCE = new PostDataAction(); public static final String NAME = "cluster:admin/xpack/ml/job/data/post"; @@ -33,17 +33,12 @@ public class PostDataAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, PostDataAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedAction.java index 15fbe437548..46eb6578e86 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedAction.java @@ -25,8 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Objects; -public class PreviewDatafeedAction extends Action { +public class PreviewDatafeedAction extends Action { public static final PreviewDatafeedAction INSTANCE = new PreviewDatafeedAction(); public static final String NAME = "cluster:admin/xpack/ml/datafeeds/preview"; @@ -35,11 +34,6 @@ public class PreviewDatafeedAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutCalendarAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutCalendarAction.java index 5644d05af04..ace5869dc50 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutCalendarAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutCalendarAction.java @@ -28,7 +28,7 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; -public class PutCalendarAction extends Action { +public class PutCalendarAction extends Action { public static final PutCalendarAction INSTANCE = new PutCalendarAction(); public static final String NAME = "cluster:admin/xpack/ml/calendars/put"; @@ -36,11 +36,6 @@ public class PutCalendarAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedAction.java index bb9b9be16e7..5142abac086 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedAction.java @@ -22,7 +22,7 @@ import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import java.io.IOException; import java.util.Objects; -public class PutDatafeedAction extends Action { +public class PutDatafeedAction extends Action { public static final PutDatafeedAction INSTANCE = new PutDatafeedAction(); public static final String NAME = "cluster:admin/xpack/ml/datafeeds/put"; @@ -31,11 +31,6 @@ public class PutDatafeedAction extends Action { +public class PutFilterAction extends Action { public static final PutFilterAction INSTANCE = new PutFilterAction(); public static final String NAME = "cluster:admin/xpack/ml/filters/put"; @@ -34,11 +34,6 @@ public class PutFilterAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutJobAction.java index 57f4b040010..a556a58d503 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/PutJobAction.java @@ -25,7 +25,7 @@ import java.io.IOException; import java.util.List; import java.util.Objects; -public class PutJobAction extends Action { +public class PutJobAction extends Action { public static final PutJobAction INSTANCE = new PutJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/put"; @@ -34,11 +34,6 @@ public class PutJobAction extends Action { +extends Action { public static final RevertModelSnapshotAction INSTANCE = new RevertModelSnapshotAction(); public static final String NAME = "cluster:admin/xpack/ml/job/model_snapshots/revert"; @@ -39,11 +39,6 @@ extends Action { +public class StartDatafeedAction extends Action { public static final ParseField START_TIME = new ParseField("start"); public static final ParseField END_TIME = new ParseField("end"); @@ -48,11 +47,6 @@ public class StartDatafeedAction super(NAME); } - @Override - public RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new RequestBuilder(client, this); - } - @Override public Response newResponse() { return new Response(); @@ -313,7 +307,7 @@ public class StartDatafeedAction } - static class RequestBuilder extends ActionRequestBuilder { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, StartDatafeedAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java index b59677f2833..4df27e1b984 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java @@ -29,8 +29,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class StopDatafeedAction - extends Action { +public class StopDatafeedAction extends Action { public static final StopDatafeedAction INSTANCE = new StopDatafeedAction(); public static final String NAME = "cluster:admin/xpack/ml/datafeed/stop"; @@ -40,11 +39,6 @@ public class StopDatafeedAction super(NAME); } - @Override - public RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new RequestBuilder(client, this); - } - @Override public Response newResponse() { return new Response(); @@ -235,7 +229,7 @@ public class StopDatafeedAction } } - static class RequestBuilder extends ActionRequestBuilder { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, StopDatafeedAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobAction.java index d1a453c7e16..dfe6499d2c4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobAction.java @@ -18,8 +18,7 @@ import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class UpdateCalendarJobAction extends Action { +public class UpdateCalendarJobAction extends Action { public static final UpdateCalendarJobAction INSTANCE = new UpdateCalendarJobAction(); public static final String NAME = "cluster:admin/xpack/ml/calendars/jobs/update"; @@ -27,11 +26,6 @@ public class UpdateCalendarJobAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedAction.java index 588fb264190..8ed170b8603 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedAction.java @@ -20,8 +20,7 @@ import org.elasticsearch.xpack.core.ml.datafeed.DatafeedUpdate; import java.io.IOException; import java.util.Objects; -public class UpdateDatafeedAction extends Action { +public class UpdateDatafeedAction extends Action { public static final UpdateDatafeedAction INSTANCE = new UpdateDatafeedAction(); public static final String NAME = "cluster:admin/xpack/ml/datafeeds/update"; @@ -30,11 +29,6 @@ public class UpdateDatafeedAction extends Action { +public class UpdateJobAction extends Action { public static final UpdateJobAction INSTANCE = new UpdateJobAction(); public static final String NAME = "cluster:admin/xpack/ml/job/update"; @@ -32,11 +32,6 @@ public class UpdateJobAction extends Action { +public class UpdateModelSnapshotAction extends Action { public static final UpdateModelSnapshotAction INSTANCE = new UpdateModelSnapshotAction(); public static final String NAME = "cluster:admin/xpack/ml/job/model_snapshots/update"; @@ -39,11 +38,6 @@ public class UpdateModelSnapshotAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, UpdateModelSnapshotAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessAction.java index 31ba85232d5..b99a0b74007 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessAction.java @@ -24,8 +24,7 @@ import java.io.IOException; import java.util.List; import java.util.Objects; -public class UpdateProcessAction extends - Action { +public class UpdateProcessAction extends Action { public static final UpdateProcessAction INSTANCE = new UpdateProcessAction(); public static final String NAME = "cluster:internal/xpack/ml/job/update/process"; @@ -34,17 +33,12 @@ public class UpdateProcessAction extends super(NAME); } - @Override - public RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new RequestBuilder(client, this); - } - @Override public Response newResponse() { return new Response(); } - static class RequestBuilder extends ActionRequestBuilder { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client, UpdateProcessAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorAction.java index 13948fc5fdc..9e8b2d69efa 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorAction.java @@ -21,8 +21,7 @@ import org.elasticsearch.xpack.core.ml.job.config.Detector; import java.io.IOException; import java.util.Objects; -public class ValidateDetectorAction -extends Action { +public class ValidateDetectorAction extends Action { public static final ValidateDetectorAction INSTANCE = new ValidateDetectorAction(); public static final String NAME = "cluster:admin/xpack/ml/job/validate/detector"; @@ -31,17 +30,12 @@ extends Action { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, ValidateDetectorAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigAction.java index e0cde4f9358..f8b9eef9ffe 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigAction.java @@ -22,8 +22,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; -public class ValidateJobConfigAction -extends Action { +public class ValidateJobConfigAction extends Action { public static final ValidateJobConfigAction INSTANCE = new ValidateJobConfigAction(); public static final String NAME = "cluster:admin/xpack/ml/job/validate"; @@ -32,17 +31,12 @@ extends Action { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, ValidateJobConfigAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/monitoring/action/MonitoringBulkAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/monitoring/action/MonitoringBulkAction.java index 24dc9be3473..05ea4b8ed2c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/monitoring/action/MonitoringBulkAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/monitoring/action/MonitoringBulkAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.xpack.core.monitoring.action; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class MonitoringBulkAction extends Action { +public class MonitoringBulkAction extends Action { public static final MonitoringBulkAction INSTANCE = new MonitoringBulkAction(); public static final String NAME = "cluster:admin/xpack/monitoring/bulk"; @@ -17,11 +16,6 @@ public class MonitoringBulkAction extends Action { + extends ActionRequestBuilder { public MonitoringBulkRequestBuilder(ElasticsearchClient client) { super(client, MonitoringBulkAction.INSTANCE, new MonitoringBulkRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java index 771f5e98d5c..7093a7215ab 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java @@ -22,8 +22,7 @@ import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Objects; -public class DeleteRollupJobAction extends Action { +public class DeleteRollupJobAction extends Action { public static final DeleteRollupJobAction INSTANCE = new DeleteRollupJobAction(); public static final String NAME = "cluster:admin/xpack/rollup/delete"; @@ -32,11 +31,6 @@ public class DeleteRollupJobAction extends Action { +public class GetRollupCapsAction extends Action { public static final GetRollupCapsAction INSTANCE = new GetRollupCapsAction(); public static final String NAME = "cluster:monitor/xpack/rollup/get/caps"; @@ -40,11 +39,6 @@ public class GetRollupCapsAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, GetRollupCapsAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java index 2e8ed2852e2..53727738670 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java @@ -35,8 +35,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -public class GetRollupJobsAction extends Action { +public class GetRollupJobsAction extends Action { public static final GetRollupJobsAction INSTANCE = new GetRollupJobsAction(); public static final String NAME = "cluster:monitor/xpack/rollup/get"; @@ -49,11 +48,6 @@ public class GetRollupJobsAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, GetRollupJobsAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java index bb64d97f1c8..6d28fb69294 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java @@ -25,8 +25,7 @@ import java.io.IOException; import java.util.Map; import java.util.Objects; -public class PutRollupJobAction extends Action { +public class PutRollupJobAction extends Action { public static final PutRollupJobAction INSTANCE = new PutRollupJobAction(); public static final String NAME = "cluster:admin/xpack/rollup/put"; @@ -35,11 +34,6 @@ public class PutRollupJobAction extends Action { +public class RollupSearchAction extends Action { public static final RollupSearchAction INSTANCE = new RollupSearchAction(); public static final String NAME = "indices:admin/xpack/rollup/search"; @@ -20,17 +20,12 @@ public class RollupSearchAction extends Action { + static class RequestBuilder extends ActionRequestBuilder { RequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new SearchRequest()); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java index 042dbd18d42..1c71653e85f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java @@ -26,8 +26,7 @@ import java.io.IOException; import java.util.Collections; import java.util.Objects; -public class StartRollupJobAction extends Action { +public class StartRollupJobAction extends Action { public static final StartRollupJobAction INSTANCE = new StartRollupJobAction(); public static final String NAME = "cluster:admin/xpack/rollup/start"; @@ -36,11 +35,6 @@ public class StartRollupJobAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, StartRollupJobAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java index cfb7da0bd93..b54130fe1b1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java @@ -25,8 +25,7 @@ import java.io.IOException; import java.util.Collections; import java.util.Objects; -public class StopRollupJobAction extends Action { +public class StopRollupJobAction extends Action { public static final StopRollupJobAction INSTANCE = new StopRollupJobAction(); public static final String NAME = "cluster:admin/xpack/rollup/stop"; @@ -35,11 +34,6 @@ public class StopRollupJobAction extends Action { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, StopRollupJobAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/realm/ClearRealmCacheAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/realm/ClearRealmCacheAction.java index 83e0334bc0b..a1c865a0306 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/realm/ClearRealmCacheAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/realm/ClearRealmCacheAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.xpack.core.security.action.realm; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ClearRealmCacheAction extends Action { +public class ClearRealmCacheAction extends Action { public static final ClearRealmCacheAction INSTANCE = new ClearRealmCacheAction(); public static final String NAME = "cluster:admin/xpack/security/realm/cache/clear"; @@ -17,11 +16,6 @@ public class ClearRealmCacheAction extends Action { +public class ClearRolesCacheAction extends Action { public static final ClearRolesCacheAction INSTANCE = new ClearRolesCacheAction(); public static final String NAME = "cluster:admin/xpack/security/roles/cache/clear"; @@ -20,11 +19,6 @@ public class ClearRolesCacheAction extends Action { +public class DeleteRoleAction extends Action { public static final DeleteRoleAction INSTANCE = new DeleteRoleAction(); public static final String NAME = "cluster:admin/xpack/security/role/delete"; @@ -21,11 +20,6 @@ public class DeleteRoleAction extends Action +public class DeleteRoleRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public DeleteRoleRequestBuilder(ElasticsearchClient client) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/GetRolesAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/GetRolesAction.java index aa770ba160b..3489c2493e7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/GetRolesAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/GetRolesAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.role; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action to retrieve a role from the security index */ -public class GetRolesAction extends Action { +public class GetRolesAction extends Action { public static final GetRolesAction INSTANCE = new GetRolesAction(); public static final String NAME = "cluster:admin/xpack/security/role/get"; @@ -21,11 +20,6 @@ public class GetRolesAction extends Action { +public class GetRolesRequestBuilder extends ActionRequestBuilder { public GetRolesRequestBuilder(ElasticsearchClient client) { this(client, GetRolesAction.INSTANCE); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleAction.java index 8a7461eaeff..a9aa2c8f29a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.role; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for adding a role to the security index */ -public class PutRoleAction extends Action { +public class PutRoleAction extends Action { public static final PutRoleAction INSTANCE = new PutRoleAction(); public static final String NAME = "cluster:admin/xpack/security/role/put"; @@ -21,11 +20,6 @@ public class PutRoleAction extends Action +public class PutRoleRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public PutRoleRequestBuilder(ElasticsearchClient client) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingAction.java index 79e99f38434..db608374374 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingAction.java @@ -12,8 +12,7 @@ import org.elasticsearch.client.ElasticsearchClient; * Action for deleting a role-mapping from the * org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore */ -public class DeleteRoleMappingAction extends Action { +public class DeleteRoleMappingAction extends Action { public static final DeleteRoleMappingAction INSTANCE = new DeleteRoleMappingAction(); public static final String NAME = "cluster:admin/xpack/security/role_mapping/delete"; @@ -22,11 +21,6 @@ public class DeleteRoleMappingAction extends Action +public class DeleteRoleMappingRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public DeleteRoleMappingRequestBuilder(ElasticsearchClient client, diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsAction.java index 49ada117ae6..12797ed4d2b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsAction.java @@ -6,14 +6,13 @@ package org.elasticsearch.xpack.core.security.action.rolemapping; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action to retrieve one or more role-mappings from X-Pack security * see org.elasticsearch.xpack.security.authc.support.mapper.NativeRoleMappingStore */ -public class GetRoleMappingsAction extends Action { +public class GetRoleMappingsAction extends Action { public static final GetRoleMappingsAction INSTANCE = new GetRoleMappingsAction(); public static final String NAME = "cluster:admin/xpack/security/role_mapping/get"; @@ -22,11 +21,6 @@ public class GetRoleMappingsAction extends Action { +public class GetRoleMappingsRequestBuilder extends ActionRequestBuilder { public GetRoleMappingsRequestBuilder(ElasticsearchClient client, GetRoleMappingsAction action) { super(client, action, new GetRoleMappingsRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingAction.java index 4e9b427c63a..34b1e94d753 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingAction.java @@ -11,8 +11,7 @@ import org.elasticsearch.client.ElasticsearchClient; /** * Action for adding a role to the security index */ -public class PutRoleMappingAction extends Action { +public class PutRoleMappingAction extends Action { public static final PutRoleMappingAction INSTANCE = new PutRoleMappingAction(); public static final String NAME = "cluster:admin/xpack/security/role_mapping/put"; @@ -21,11 +20,6 @@ public class PutRoleMappingAction extends Action implements +public class PutRoleMappingRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public PutRoleMappingRequestBuilder(ElasticsearchClient client, PutRoleMappingAction action) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateAction.java index 51691629209..a1b8829b1ed 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateAction.java @@ -11,8 +11,7 @@ import org.elasticsearch.client.ElasticsearchClient; /** * Action for authenticating using SAML assertions */ -public final class SamlAuthenticateAction - extends Action { +public final class SamlAuthenticateAction extends Action { public static final String NAME = "cluster:admin/xpack/security/saml/authenticate"; public static final SamlAuthenticateAction INSTANCE = new SamlAuthenticateAction(); @@ -21,11 +20,6 @@ public final class SamlAuthenticateAction super(NAME); } - @Override - public SamlAuthenticateRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new SamlAuthenticateRequestBuilder(client); - } - @Override public SamlAuthenticateResponse newResponse() { return new SamlAuthenticateResponse(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequestBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequestBuilder.java index 8b8efb504c4..17cff756e26 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequestBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequestBuilder.java @@ -14,7 +14,7 @@ import org.elasticsearch.client.ElasticsearchClient; * Request builder used to populate a {@link SamlAuthenticateRequest} */ public final class SamlAuthenticateRequestBuilder - extends ActionRequestBuilder { + extends ActionRequestBuilder { public SamlAuthenticateRequestBuilder(ElasticsearchClient client) { super(client, SamlAuthenticateAction.INSTANCE, new SamlAuthenticateRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionAction.java index c9bbf3a6671..7efcdc7d16b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionAction.java @@ -11,8 +11,7 @@ import org.elasticsearch.client.ElasticsearchClient; /** * Action to perform IdP-initiated logout for a SAML-SSO user */ -public final class SamlInvalidateSessionAction - extends Action { +public final class SamlInvalidateSessionAction extends Action { public static final String NAME = "cluster:admin/xpack/security/saml/invalidate"; public static final SamlInvalidateSessionAction INSTANCE = new SamlInvalidateSessionAction(); @@ -21,11 +20,6 @@ public final class SamlInvalidateSessionAction super(NAME); } - @Override - public SamlInvalidateSessionRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new SamlInvalidateSessionRequestBuilder(client); - } - @Override public SamlInvalidateSessionResponse newResponse() { return new SamlInvalidateSessionResponse(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequestBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequestBuilder.java index 0d9b26a7b65..10c2f3a539e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequestBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequestBuilder.java @@ -12,7 +12,7 @@ import org.elasticsearch.client.ElasticsearchClient; * Request builder used to populate a {@link SamlInvalidateSessionRequest} */ public final class SamlInvalidateSessionRequestBuilder - extends ActionRequestBuilder { + extends ActionRequestBuilder { public SamlInvalidateSessionRequestBuilder(ElasticsearchClient client) { super(client, SamlInvalidateSessionAction.INSTANCE, new SamlInvalidateSessionRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutAction.java index bc7b0ed257d..8c2cb6f4599 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.saml; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for initiating a logout process for a SAML-SSO user */ -public final class SamlLogoutAction extends Action { +public final class SamlLogoutAction extends Action { public static final String NAME = "cluster:admin/xpack/security/saml/logout"; public static final SamlLogoutAction INSTANCE = new SamlLogoutAction(); @@ -20,11 +19,6 @@ public final class SamlLogoutAction extends Action { +public final class SamlLogoutRequestBuilder extends ActionRequestBuilder { public SamlLogoutRequestBuilder(ElasticsearchClient client) { super(client, SamlLogoutAction.INSTANCE, new SamlLogoutRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationAction.java index bbc4cdbd7fd..9d80df1d960 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationAction.java @@ -11,8 +11,7 @@ import org.elasticsearch.client.ElasticsearchClient; /** * Action for initiating an authentication process using SAML assertions */ -public final class SamlPrepareAuthenticationAction - extends Action { +public final class SamlPrepareAuthenticationAction extends Action { public static final String NAME = "cluster:admin/xpack/security/saml/prepare"; public static final SamlPrepareAuthenticationAction INSTANCE = new SamlPrepareAuthenticationAction(); @@ -21,11 +20,6 @@ public final class SamlPrepareAuthenticationAction super(NAME); } - @Override - public SamlPrepareAuthenticationRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new SamlPrepareAuthenticationRequestBuilder(client); - } - @Override public SamlPrepareAuthenticationResponse newResponse() { return new SamlPrepareAuthenticationResponse(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequestBuilder.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequestBuilder.java index 7474557a76d..a3bf6f595b1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequestBuilder.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequestBuilder.java @@ -12,7 +12,7 @@ import org.elasticsearch.client.ElasticsearchClient; * Request builder used to populate a {@link SamlPrepareAuthenticationRequest} */ public final class SamlPrepareAuthenticationRequestBuilder extends ActionRequestBuilder { + SamlPrepareAuthenticationResponse> { public SamlPrepareAuthenticationRequestBuilder(ElasticsearchClient client) { super(client, SamlPrepareAuthenticationAction.INSTANCE, new SamlPrepareAuthenticationRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenAction.java index 98a312b7fcc..9f2e937151c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.token; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for creating a new token */ -public final class CreateTokenAction extends Action { +public final class CreateTokenAction extends Action { public static final String NAME = "cluster:admin/xpack/security/token/create"; public static final CreateTokenAction INSTANCE = new CreateTokenAction(); @@ -20,11 +19,6 @@ public final class CreateTokenAction extends Action { + extends ActionRequestBuilder { - public CreateTokenRequestBuilder(ElasticsearchClient client, - Action action) { + public CreateTokenRequestBuilder(ElasticsearchClient client, Action action) { super(client, action, new CreateTokenRequest()); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenAction.java index 5f199876d6a..eca864546b2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.token; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for invalidating a given token */ -public final class InvalidateTokenAction extends Action { +public final class InvalidateTokenAction extends Action { public static final String NAME = "cluster:admin/xpack/security/token/invalidate"; public static final InvalidateTokenAction INSTANCE = new InvalidateTokenAction(); @@ -20,11 +19,6 @@ public final class InvalidateTokenAction extends Action { + extends ActionRequestBuilder { public InvalidateTokenRequestBuilder(ElasticsearchClient client) { super(client, InvalidateTokenAction.INSTANCE, new InvalidateTokenRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/RefreshTokenAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/RefreshTokenAction.java index a322f3fa847..c847aa32898 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/RefreshTokenAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/RefreshTokenAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.xpack.core.security.action.token; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public final class RefreshTokenAction extends Action { +public final class RefreshTokenAction extends Action { public static final String NAME = "cluster:admin/xpack/security/token/refresh"; public static final RefreshTokenAction INSTANCE = new RefreshTokenAction(); @@ -17,11 +16,6 @@ public final class RefreshTokenAction extends Action { +public class AuthenticateAction extends Action { public static final String NAME = "cluster:admin/xpack/security/user/authenticate"; public static final AuthenticateAction INSTANCE = new AuthenticateAction(); @@ -17,11 +16,6 @@ public class AuthenticateAction extends Action { + extends ActionRequestBuilder { public AuthenticateRequestBuilder(ElasticsearchClient client) { this(client, AuthenticateAction.INSTANCE); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordAction.java index 44b31e3f3de..23bfff8d801 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.xpack.core.security.action.user; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class ChangePasswordAction extends Action { +public class ChangePasswordAction extends Action { public static final ChangePasswordAction INSTANCE = new ChangePasswordAction(); public static final String NAME = "cluster:admin/xpack/security/user/change_password"; @@ -17,11 +16,6 @@ public class ChangePasswordAction extends Action + extends ActionRequestBuilder implements WriteRequestBuilder { public ChangePasswordRequestBuilder(ElasticsearchClient client) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserAction.java index 54f99f923db..a62381b6ecc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.user; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for deleting a native user. */ -public class DeleteUserAction extends Action { +public class DeleteUserAction extends Action { public static final DeleteUserAction INSTANCE = new DeleteUserAction(); public static final String NAME = "cluster:admin/xpack/security/user/delete"; @@ -20,11 +19,6 @@ public class DeleteUserAction extends Action +public class DeleteUserRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public DeleteUserRequestBuilder(ElasticsearchClient client) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersAction.java index 4b9bf56fb7b..5c9142671f4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.user; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for retrieving a user from the security index */ -public class GetUsersAction extends Action { +public class GetUsersAction extends Action { public static final GetUsersAction INSTANCE = new GetUsersAction(); public static final String NAME = "cluster:admin/xpack/security/user/get"; @@ -20,11 +19,6 @@ public class GetUsersAction extends Action { +public class GetUsersRequestBuilder extends ActionRequestBuilder { public GetUsersRequestBuilder(ElasticsearchClient client) { this(client, GetUsersAction.INSTANCE); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesAction.java index 5df11a349a7..5db27db93ec 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesAction.java @@ -6,14 +6,13 @@ package org.elasticsearch.xpack.core.security.action.user; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; /** * This action is testing whether a user has the specified * {@link RoleDescriptor.IndicesPrivileges privileges} */ -public class HasPrivilegesAction extends Action { +public class HasPrivilegesAction extends Action { public static final HasPrivilegesAction INSTANCE = new HasPrivilegesAction(); public static final String NAME = "cluster:admin/xpack/security/user/has_privileges"; @@ -22,11 +21,6 @@ public class HasPrivilegesAction extends Action { + extends ActionRequestBuilder { public HasPrivilegesRequestBuilder(ElasticsearchClient client) { super(client, HasPrivilegesAction.INSTANCE, new HasPrivilegesRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserAction.java index 377fb57d007..6009f89e69f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.user; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Action for putting (adding/updating) a native user. */ -public class PutUserAction extends Action { +public class PutUserAction extends Action { public static final PutUserAction INSTANCE = new PutUserAction(); public static final String NAME = "cluster:admin/xpack/security/user/put"; @@ -20,11 +19,6 @@ public class PutUserAction extends Action +public class PutUserRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { private final Hasher hasher = Hasher.BCRYPT; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledAction.java index 53bb5463c91..ec010cc17a9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.security.action.user; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * This action is for setting the enabled flag on a native or reserved user */ -public class SetEnabledAction extends Action { +public class SetEnabledAction extends Action { public static final SetEnabledAction INSTANCE = new SetEnabledAction(); public static final String NAME = "cluster:admin/xpack/security/user/set_enabled"; @@ -20,11 +19,6 @@ public class SetEnabledAction extends Action +public class SetEnabledRequestBuilder extends ActionRequestBuilder implements WriteRequestBuilder { public SetEnabledRequestBuilder(ElasticsearchClient client) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java index 6bd6228f2ef..46111b9b16c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/TokenMetaData.java @@ -12,13 +12,14 @@ import org.elasticsearch.cluster.NamedDiff; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; -public final class TokenMetaData extends AbstractNamedDiffable implements ClusterState.Custom { +public final class TokenMetaData extends AbstractNamedDiffable implements XPackPlugin.XPackClusterStateCustom { /** * The type of {@link ClusterState} data. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/action/GetCertificateInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/action/GetCertificateInfoAction.java index 54e7548b803..e4115887f66 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/action/GetCertificateInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/action/GetCertificateInfoAction.java @@ -25,8 +25,7 @@ import java.util.Collection; * Action to obtain information about X.509 (SSL/TLS) certificates that are being used by X-Pack. * The primary use case is for tracking the expiry dates of certificates. */ -public class GetCertificateInfoAction - extends Action { +public class GetCertificateInfoAction extends Action { public static final GetCertificateInfoAction INSTANCE = new GetCertificateInfoAction(); public static final String NAME = "cluster:monitor/xpack/ssl/certificates/get"; @@ -35,11 +34,6 @@ public class GetCertificateInfoAction super(NAME); } - @Override - public GetCertificateInfoAction.RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new GetCertificateInfoAction.RequestBuilder(client, this); - } - @Override public GetCertificateInfoAction.Response newResponse() { return new GetCertificateInfoAction.Response(); @@ -94,7 +88,7 @@ public class GetCertificateInfoAction } } - public static class RequestBuilder extends ActionRequestBuilder { + public static class RequestBuilder extends ActionRequestBuilder { public RequestBuilder(ElasticsearchClient client, GetCertificateInfoAction action) { super(client, action, new Request()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java index f5b5844e5f2..781cfe4d4d2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java @@ -26,8 +26,7 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.xpack.core.upgrade.IndexUpgradeServiceFields.UPGRADE_INDEX_OPTIONS; -public class IndexUpgradeAction extends Action { +public class IndexUpgradeAction extends Action { public static final IndexUpgradeAction INSTANCE = new IndexUpgradeAction(); public static final String NAME = "cluster:admin/xpack/upgrade"; @@ -36,11 +35,6 @@ public class IndexUpgradeAction extends Action { - protected RequestBuilder(ElasticsearchClient client, IndexUpgradeAction action) { - super(client, action, new Request()); + public RequestBuilder(ElasticsearchClient client) { + super(client, INSTANCE, new Request()); } public RequestBuilder setIndex(String index) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java index 74df1caecdd..bfa6de10b1b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java @@ -26,8 +26,7 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; -public class IndexUpgradeInfoAction extends Action { +public class IndexUpgradeInfoAction extends Action { public static final IndexUpgradeInfoAction INSTANCE = new IndexUpgradeInfoAction(); public static final String NAME = "cluster:admin/xpack/upgrade/info"; @@ -36,11 +35,6 @@ public class IndexUpgradeInfoAction extends Action { - protected RequestBuilder(ElasticsearchClient client, IndexUpgradeInfoAction action) { - super(client, action, new Request()); + public RequestBuilder(ElasticsearchClient client) { + super(client, INSTANCE, new Request()); } public RequestBuilder setIndices(String... indices) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java index 3a490f08b79..9f014dee843 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/WatcherMetaData.java @@ -13,12 +13,13 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; import java.util.EnumSet; import java.util.Objects; -public class WatcherMetaData extends AbstractNamedDiffable implements MetaData.Custom { +public class WatcherMetaData extends AbstractNamedDiffable implements XPackPlugin.XPackMetaDataCustom { public static final String TYPE = "watcher"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/ack/AckWatchAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/ack/AckWatchAction.java index d895ae31c50..d6a72590874 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/ack/AckWatchAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/ack/AckWatchAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.ack; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * This action acks a watch in memory, and the index */ -public class AckWatchAction extends Action { +public class AckWatchAction extends Action { public static final AckWatchAction INSTANCE = new AckWatchAction(); public static final String NAME = "cluster:admin/xpack/watcher/watch/ack"; @@ -24,9 +23,4 @@ public class AckWatchAction extends Action { +public class AckWatchRequestBuilder extends ActionRequestBuilder { public AckWatchRequestBuilder(ElasticsearchClient client) { super(client, AckWatchAction.INSTANCE, new AckWatchRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/activate/ActivateWatchAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/activate/ActivateWatchAction.java index 2832b779c40..8f6f10ced90 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/activate/ActivateWatchAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/activate/ActivateWatchAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.activate; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * This action acks a watch in memory, and the index */ -public class ActivateWatchAction extends Action { +public class ActivateWatchAction extends Action { public static final ActivateWatchAction INSTANCE = new ActivateWatchAction(); public static final String NAME = "cluster:admin/xpack/watcher/watch/activate"; @@ -24,9 +23,4 @@ public class ActivateWatchAction extends Action { +public class ActivateWatchRequestBuilder extends ActionRequestBuilder { public ActivateWatchRequestBuilder(ElasticsearchClient client) { super(client, ActivateWatchAction.INSTANCE, new ActivateWatchRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/delete/DeleteWatchAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/delete/DeleteWatchAction.java index ffbe6539f60..e40d6876f1c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/delete/DeleteWatchAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/delete/DeleteWatchAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.delete; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * This action deletes an watch from in memory, the scheduler and the index */ -public class DeleteWatchAction extends Action { +public class DeleteWatchAction extends Action { public static final DeleteWatchAction INSTANCE = new DeleteWatchAction(); public static final String NAME = "cluster:admin/xpack/watcher/watch/delete"; @@ -24,9 +23,4 @@ public class DeleteWatchAction extends Action { +public class DeleteWatchRequestBuilder extends ActionRequestBuilder { public DeleteWatchRequestBuilder(ElasticsearchClient client) { super(client, DeleteWatchAction.INSTANCE, new DeleteWatchRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchAction.java index f8a8b009e44..5baa021d6f1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/execute/ExecuteWatchAction.java @@ -6,13 +6,12 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.execute; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * This action executes a watch, either ignoring the schedule and condition or just the schedule and can execute a subset of the actions, * optionally persisting the history entry */ -public class ExecuteWatchAction extends Action { +public class ExecuteWatchAction extends Action { public static final ExecuteWatchAction INSTANCE = new ExecuteWatchAction(); public static final String NAME = "cluster:admin/xpack/watcher/watch/execute"; @@ -25,10 +24,4 @@ public class ExecuteWatchAction extends Action { +public class ExecuteWatchRequestBuilder extends ActionRequestBuilder { public ExecuteWatchRequestBuilder(ElasticsearchClient client) { super(client, ExecuteWatchAction.INSTANCE, new ExecuteWatchRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchAction.java index a68223c6f6c..c411c0dbeb3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchAction.java @@ -5,12 +5,10 @@ */ package org.elasticsearch.xpack.core.watcher.transport.actions.get; -import org.elasticsearch.client.ElasticsearchClient; - /** * This action gets an watch by name */ -public class GetWatchAction extends org.elasticsearch.action.Action { +public class GetWatchAction extends org.elasticsearch.action.Action { public static final GetWatchAction INSTANCE = new GetWatchAction(); public static final String NAME = "cluster:monitor/xpack/watcher/watch/get"; @@ -23,9 +21,4 @@ public class GetWatchAction extends org.elasticsearch.action.Action { +public class GetWatchRequestBuilder extends ActionRequestBuilder { public GetWatchRequestBuilder(ElasticsearchClient client, String id) { super(client, GetWatchAction.INSTANCE, new GetWatchRequest(id)); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/put/PutWatchAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/put/PutWatchAction.java index 9b0024ee43b..faf2faae182 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/put/PutWatchAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/put/PutWatchAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.put; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * This action puts an watch into the watch index and adds it to the scheduler */ -public class PutWatchAction extends Action { +public class PutWatchAction extends Action { public static final PutWatchAction INSTANCE = new PutWatchAction(); public static final String NAME = "cluster:admin/xpack/watcher/watch/put"; @@ -24,9 +23,4 @@ public class PutWatchAction extends Action { +public class PutWatchRequestBuilder extends ActionRequestBuilder { public PutWatchRequestBuilder(ElasticsearchClient client) { super(client, PutWatchAction.INSTANCE, new PutWatchRequest()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/service/WatcherServiceAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/service/WatcherServiceAction.java index 05cddee273c..a9682b2946d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/service/WatcherServiceAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/service/WatcherServiceAction.java @@ -6,10 +6,9 @@ package org.elasticsearch.xpack.core.watcher.transport.actions.service; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class WatcherServiceAction extends Action { +public class WatcherServiceAction extends Action { public static final WatcherServiceAction INSTANCE = new WatcherServiceAction(); public static final String NAME = "cluster:admin/xpack/watcher/service"; @@ -22,9 +21,4 @@ public class WatcherServiceAction extends Action { +public class WatcherStatsAction extends Action { public static final WatcherStatsAction INSTANCE = new WatcherStatsAction(); public static final String NAME = "cluster:monitor/xpack/watcher/stats/dist"; @@ -24,10 +23,4 @@ public class WatcherStatsAction extends Action SearchScrollAction.INSTANCE.newRequestBuilder(client) + () -> new SearchScrollRequestBuilder(client, SearchScrollAction.INSTANCE) .setScroll(SCROLL_TIMEOUT) .setScrollId(scrollId) .get()); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index 0e674ba000b..24dcb323e3d 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -42,6 +42,7 @@ import org.elasticsearch.rest.RestStatus; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.XPackField; +import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; import org.elasticsearch.xpack.core.rollup.job.RollupJob; @@ -91,6 +92,8 @@ public class TransportPutRollupJobAction extends TransportMasterNodeAction action = + final Action action = "refresh_token".equals(tokenRequest.getGrantType()) ? RefreshTokenAction.INSTANCE : CreateTokenAction.INSTANCE; return channel -> client.execute(action, tokenRequest, // this doesn't use the RestBuilderListener since we need to override the diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java index 09a48a0eb13..15361d997a1 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/saml/TransportSamlInvalidateSessionActionTests.java @@ -126,8 +126,8 @@ public class TransportSamlInvalidateSessionActionTests extends SamlTestCase { @Override protected > - void doExecute(Action action, Request request, ActionListener listener) { + RequestBuilder extends ActionRequestBuilder> + void doExecute(Action action, Request request, ActionListener listener) { if (IndexAction.NAME.equals(action.name())) { assertThat(request, instanceOf(IndexRequest.class)); IndexRequest indexRequest = (IndexRequest) request; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java index 33ba5741e08..1a5adc2e5ef 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java @@ -71,8 +71,8 @@ public class IndexAuditTrailMutedTests extends ESTestCase { @Override protected > void doExecute( - Action action, Request request, ActionListener listener) { + ActionRequestBuilder> void doExecute( + Action action, Request request, ActionListener listener) { clientCalled.set(true); } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStoreTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStoreTests.java index 59244bbc509..ee570dcadda 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStoreTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStoreTests.java @@ -75,9 +75,9 @@ public class NativeUsersStoreTests extends ESTestCase { protected < Request extends ActionRequest, Response extends ActionResponse, - RequestBuilder extends ActionRequestBuilder + RequestBuilder extends ActionRequestBuilder > void doExecute( - Action action, + Action action, Request request, ActionListener listener) { requests.add(new Tuple<>(request, listener)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java index ef60764d26d..8bb9890151f 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java @@ -374,7 +374,7 @@ public class SamlAuthenticatorTests extends SamlTestCase { final String xml = getSimpleResponse(now); // Encrypting with different cert instead of sp cert will mean that the SP cannot decrypt - final String encrypted = encryptAssertions(xml, readKeyPair("RSA_1024")); + final String encrypted = encryptAssertions(xml, readKeyPair("RSA_4096_updated")); assertThat(encrypted, not(equalTo(xml))); final String signed = signDoc(encrypted); @@ -896,7 +896,6 @@ public class SamlAuthenticatorTests extends SamlTestCase { assertThat(attributes.attributes(), iterableWithSize(1)); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/30970") public void testIncorrectSigningKeyIsRejected() throws Exception { final CryptoTransform signer = randomBoolean() ? this::signDoc : this::signAssertions; Instant now = clock.instant(); @@ -938,7 +937,7 @@ public class SamlAuthenticatorTests extends SamlTestCase { assertThat(authenticator.authenticate(token(signer.transform(xml, idpSigningCertificatePair))), notNullValue()); // check is rejected when signed by a different key-pair - final Tuple wrongKey = readRandomKeyPair(randomSigningAlgorithm()); + final Tuple wrongKey = readKeyPair("RSA_4096_updated"); final ElasticsearchSecurityException exception = expectThrows(ElasticsearchSecurityException.class, () -> authenticator.authenticate(token(signer.transform(xml, wrongKey)))); assertThat(exception.getMessage(), containsString("SAML Signature")); @@ -954,10 +953,12 @@ public class SamlAuthenticatorTests extends SamlTestCase { assertThat(authenticator.authenticate(token(signer.transform(xml, idpSigningCertificatePair))), notNullValue()); final Tuple oldKeyPair = idpSigningCertificatePair; - //Ensure we won't read any of the ones we could have picked randomly before + // Ensure we won't read any of the ones we could have picked randomly before idpSigningCertificatePair = readKeyPair("RSA_4096_updated"); assertThat(idpSigningCertificatePair.v2(), not(equalTo(oldKeyPair.v2()))); assertThat(authenticator.authenticate(token(signer.transform(xml, idpSigningCertificatePair))), notNullValue()); + // Restore the keypair to one from the keypair pool of all algorithms and keys + idpSigningCertificatePair = readRandomKeyPair(randomSigningAlgorithm()); } public void testParsingRejectsTamperedContent() throws Exception { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java index bbd98445295..51a6d8732a5 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java @@ -71,7 +71,7 @@ public abstract class SamlTestCase extends ESTestCase { } /** - * Generates key pair for given algorithm and then associates with a certificate. + * Reads a key pair and associated certificate for given algorithm and key length * For testing, for "EC" algorithm 256 key size is used, others use 2048 as default. * @param algorithm * @return X509Certificate a signed certificate, it's PrivateKey {@link Tuple} diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java index b5b67c7e7b2..7754d387f15 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java @@ -66,7 +66,7 @@ public class SecurityIndexManagerTests extends ESTestCase { public static final String INDEX_NAME = ".security"; private static final String TEMPLATE_NAME = "SecurityIndexManagerTests-template"; private SecurityIndexManager manager; - private Map, Map>> actions; + private Map, Map>> actions; @Before public void setUpManager() { @@ -82,8 +82,8 @@ public class SecurityIndexManagerTests extends ESTestCase { @Override protected > - void doExecute(Action action, Request request, + RequestBuilder extends ActionRequestBuilder> + void doExecute(Action action, Request request, ActionListener listener) { final Map> map = actions.getOrDefault(action, new HashMap<>()); map.put(request, listener); diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorAction.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorAction.java index f0b91640f98..2c6daf2c4ae 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorAction.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorAction.java @@ -6,10 +6,8 @@ package org.elasticsearch.xpack.sql.plugin; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class SqlClearCursorAction - extends Action { +public class SqlClearCursorAction extends Action { public static final SqlClearCursorAction INSTANCE = new SqlClearCursorAction(); public static final String NAME = "indices:data/read/sql/close_cursor"; @@ -18,11 +16,6 @@ public class SqlClearCursorAction super(NAME); } - @Override - public SqlClearCursorRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new SqlClearCursorRequestBuilder(client, this); - } - @Override public SqlClearCursorResponse newResponse() { return new SqlClearCursorResponse(); diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorRequestBuilder.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorRequestBuilder.java index 0767f02587c..b7a1f383a2f 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorRequestBuilder.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorRequestBuilder.java @@ -9,7 +9,7 @@ import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; public class SqlClearCursorRequestBuilder extends - ActionRequestBuilder { + ActionRequestBuilder { public SqlClearCursorRequestBuilder(ElasticsearchClient client, SqlClearCursorAction action) { super(client, action, new SqlClearCursorRequest()); diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlQueryAction.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlQueryAction.java index cbcf626adad..82b233968d9 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlQueryAction.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlQueryAction.java @@ -6,9 +6,8 @@ package org.elasticsearch.xpack.sql.plugin; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; -public class SqlQueryAction extends Action { +public class SqlQueryAction extends Action { public static final SqlQueryAction INSTANCE = new SqlQueryAction(); public static final String NAME = "indices:data/read/sql"; @@ -17,11 +16,6 @@ public class SqlQueryAction extends Action { +public class SqlQueryRequestBuilder extends ActionRequestBuilder { public SqlQueryRequestBuilder(ElasticsearchClient client, SqlQueryAction action) { this(client, action, "", Collections.emptyList(), null, Protocol.TIME_ZONE, Protocol.FETCH_SIZE, Protocol.REQUEST_TIMEOUT, diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlTranslateAction.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlTranslateAction.java index 9bfee2d1c34..3d44d26264e 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlTranslateAction.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlTranslateAction.java @@ -6,12 +6,11 @@ package org.elasticsearch.xpack.sql.plugin; import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; /** * Sql action for translating SQL queries into ES requests */ -public class SqlTranslateAction extends Action { +public class SqlTranslateAction extends Action { public static final SqlTranslateAction INSTANCE = new SqlTranslateAction(); public static final String NAME = "indices:data/read/sql/translate"; @@ -20,11 +19,6 @@ public class SqlTranslateAction extends Action { +public class SqlTranslateRequestBuilder extends ActionRequestBuilder { public SqlTranslateRequestBuilder(ElasticsearchClient client, SqlTranslateAction action) { this(client, action, Mode.PLAIN, null, null, Collections.emptyList(), Protocol.TIME_ZONE, Protocol.FETCH_SIZE, Protocol.REQUEST_TIMEOUT, Protocol.PAGE_TIMEOUT); diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java index 22a7889f624..ef90e8ccd47 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.sql.action; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.xpack.sql.plugin.SqlQueryRequestBuilder; import org.elasticsearch.xpack.sql.proto.ColumnInfo; import org.elasticsearch.xpack.sql.plugin.SqlQueryAction; import org.elasticsearch.xpack.sql.plugin.SqlQueryResponse; @@ -31,7 +32,7 @@ public class SqlActionIT extends AbstractSqlIntegTestCase { boolean dataBeforeCount = randomBoolean(); String columns = dataBeforeCount ? "data, count" : "count, data"; - SqlQueryResponse response = client().prepareExecute(SqlQueryAction.INSTANCE) + SqlQueryResponse response = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE) .query("SELECT " + columns + " FROM test ORDER BY count").mode(Mode.JDBC).get(); assertThat(response.size(), equalTo(2L)); assertThat(response.columns(), hasSize(2)); diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java index 7b747ffeb67..643372a21fe 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java @@ -9,8 +9,10 @@ import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.xpack.sql.plugin.SqlClearCursorAction; +import org.elasticsearch.xpack.sql.plugin.SqlClearCursorRequestBuilder; import org.elasticsearch.xpack.sql.plugin.SqlClearCursorResponse; import org.elasticsearch.xpack.sql.plugin.SqlQueryAction; +import org.elasticsearch.xpack.sql.plugin.SqlQueryRequestBuilder; import org.elasticsearch.xpack.sql.plugin.SqlQueryResponse; import org.elasticsearch.xpack.sql.session.Cursor; @@ -37,7 +39,7 @@ public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase { int fetchSize = randomIntBetween(5, 20); logger.info("Fetching {} records at a time", fetchSize); - SqlQueryResponse sqlQueryResponse = client().prepareExecute(SqlQueryAction.INSTANCE) + SqlQueryResponse sqlQueryResponse = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE) .query("SELECT * FROM test").fetchSize(fetchSize).get(); assertEquals(fetchSize, sqlQueryResponse.size()); @@ -45,7 +47,7 @@ public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase { assertThat(sqlQueryResponse.cursor(), notNullValue()); assertThat(sqlQueryResponse.cursor(), not(equalTo(Cursor.EMPTY))); - SqlClearCursorResponse cleanCursorResponse = client().prepareExecute(SqlClearCursorAction.INSTANCE) + SqlClearCursorResponse cleanCursorResponse = new SqlClearCursorRequestBuilder(client(), SqlClearCursorAction.INSTANCE) .cursor(sqlQueryResponse.cursor()).get(); assertTrue(cleanCursorResponse.isSucceeded()); @@ -67,7 +69,7 @@ public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase { int fetchSize = randomIntBetween(5, 20); logger.info("Fetching {} records at a time", fetchSize); - SqlQueryResponse sqlQueryResponse = client().prepareExecute(SqlQueryAction.INSTANCE) + SqlQueryResponse sqlQueryResponse = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE) .query("SELECT * FROM test").fetchSize(fetchSize).get(); assertEquals(fetchSize, sqlQueryResponse.size()); @@ -77,12 +79,12 @@ public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase { long fetched = sqlQueryResponse.size(); do { - sqlQueryResponse = client().prepareExecute(SqlQueryAction.INSTANCE).cursor(sqlQueryResponse.cursor()).get(); + sqlQueryResponse = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).cursor(sqlQueryResponse.cursor()).get(); fetched += sqlQueryResponse.size(); } while (sqlQueryResponse.cursor().equals("") == false); assertEquals(indexSize, fetched); - SqlClearCursorResponse cleanCursorResponse = client().prepareExecute(SqlClearCursorAction.INSTANCE) + SqlClearCursorResponse cleanCursorResponse = new SqlClearCursorRequestBuilder(client(), SqlClearCursorAction.INSTANCE) .cursor(sqlQueryResponse.cursor()).get(); assertFalse(cleanCursorResponse.isSucceeded()); diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java index a9fc420a835..395a2b673f9 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.action; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.sql.plugin.SqlQueryAction; +import org.elasticsearch.xpack.sql.plugin.SqlQueryRequestBuilder; import static org.hamcrest.CoreMatchers.either; import static org.hamcrest.CoreMatchers.startsWith; @@ -32,7 +33,7 @@ public class SqlDisabledIT extends AbstractSqlIntegTestCase { public void testSqlAction() throws Exception { Throwable throwable = expectThrows(Throwable.class, - () -> client().prepareExecute(SqlQueryAction.INSTANCE).query("SHOW tables").get()); + () -> new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).query("SHOW tables").get()); assertThat(throwable.getMessage(), either(startsWith("no proxy found for action")) // disabled on client .or(startsWith("failed to find action")) // disabled on proxy client diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java index 8988f70672a..27597c93fd0 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java @@ -21,8 +21,10 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.xpack.sql.plugin.SqlQueryAction; +import org.elasticsearch.xpack.sql.plugin.SqlQueryRequestBuilder; import org.elasticsearch.xpack.sql.plugin.SqlQueryResponse; import org.elasticsearch.xpack.sql.plugin.SqlTranslateAction; +import org.elasticsearch.xpack.sql.plugin.SqlTranslateRequestBuilder; import org.elasticsearch.xpack.sql.plugin.SqlTranslateResponse; import org.hamcrest.Matchers; import org.junit.Before; @@ -118,11 +120,11 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase { disableSqlLicensing(); ElasticsearchSecurityException e = expectThrows(ElasticsearchSecurityException.class, - () -> client().prepareExecute(SqlQueryAction.INSTANCE).query("SELECT * FROM test").get()); + () -> new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).query("SELECT * FROM test").get()); assertThat(e.getMessage(), equalTo("current license is non-compliant for [sql]")); enableSqlLicensing(); - SqlQueryResponse response = client().prepareExecute(SqlQueryAction.INSTANCE).query("SELECT * FROM test").get(); + SqlQueryResponse response = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).query("SELECT * FROM test").get(); assertThat(response.size(), Matchers.equalTo(2L)); } @@ -132,11 +134,12 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase { disableJdbcLicensing(); ElasticsearchSecurityException e = expectThrows(ElasticsearchSecurityException.class, - () -> client().prepareExecute(SqlQueryAction.INSTANCE).query("SELECT * FROM test").mode("jdbc").get()); + () -> new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).query("SELECT * FROM test").mode("jdbc").get()); assertThat(e.getMessage(), equalTo("current license is non-compliant for [jdbc]")); enableJdbcLicensing(); - SqlQueryResponse response = client().prepareExecute(SqlQueryAction.INSTANCE).query("SELECT * FROM test").mode("jdbc").get(); + SqlQueryResponse response = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE) + .query("SELECT * FROM test").mode("jdbc").get(); assertThat(response.size(), Matchers.equalTo(2L)); } @@ -145,11 +148,12 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase { disableSqlLicensing(); ElasticsearchSecurityException e = expectThrows(ElasticsearchSecurityException.class, - () -> client().prepareExecute(SqlTranslateAction.INSTANCE).query("SELECT * FROM test").get()); + () -> new SqlTranslateRequestBuilder(client(), SqlTranslateAction.INSTANCE).query("SELECT * FROM test").get()); assertThat(e.getMessage(), equalTo("current license is non-compliant for [sql]")); enableSqlLicensing(); - SqlTranslateResponse response = client().prepareExecute(SqlTranslateAction.INSTANCE).query("SELECT * FROM test").get(); + SqlTranslateResponse response = new SqlTranslateRequestBuilder(client(), SqlTranslateAction.INSTANCE) + .query("SELECT * FROM test").get(); SearchSourceBuilder source = response.source(); assertThat(source.docValueFields(), Matchers.contains( new DocValueFieldsContext.FieldAndFormat("count", DocValueFieldsContext.USE_DEFAULT_FORMAT))); diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java index a4c440eb9df..2ef7c084d11 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java @@ -12,6 +12,7 @@ import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.xpack.sql.plugin.SqlTranslateAction; +import org.elasticsearch.xpack.sql.plugin.SqlTranslateRequestBuilder; import org.elasticsearch.xpack.sql.plugin.SqlTranslateResponse; import static java.util.Collections.singletonList; @@ -30,7 +31,7 @@ public class SqlTranslateActionIT extends AbstractSqlIntegTestCase { boolean columnOrder = randomBoolean(); String columns = columnOrder ? "data, count" : "count, data"; - SqlTranslateResponse response = client().prepareExecute(SqlTranslateAction.INSTANCE) + SqlTranslateResponse response = new SqlTranslateRequestBuilder(client(), SqlTranslateAction.INSTANCE) .query("SELECT " + columns + " FROM test ORDER BY count").get(); SearchSourceBuilder source = response.source(); FetchSourceContext fetch = source.fetchSource(); diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java index ef5c3acc3d2..870261d2515 100644 --- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java +++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java @@ -41,7 +41,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase { // Testing only negative case here, the positive test is done in bwcTests assertAcked(client().admin().indices().prepareCreate("test").get()); ensureYellow("test"); - Response response = client().prepareExecute(IndexUpgradeInfoAction.INSTANCE).setIndices("test").get(); + Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get(); assertThat(response.getActions().entrySet(), empty()); } @@ -54,10 +54,10 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase { ensureYellow("test"); disableLicensing(); ElasticsearchSecurityException e = expectThrows(ElasticsearchSecurityException.class, - () -> client().prepareExecute(IndexUpgradeInfoAction.INSTANCE).setIndices("test").get()); + () -> new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get()); assertThat(e.getMessage(), equalTo("current license is non-compliant for [upgrade]")); enableLicensing(); - Response response = client().prepareExecute(IndexUpgradeInfoAction.INSTANCE).setIndices("test").get(); + Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get(); assertThat(response.getActions().entrySet(), empty()); } @@ -73,7 +73,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase { ensureYellow(testIndex); IllegalStateException ex = expectThrows(IllegalStateException.class, - () -> client().prepareExecute(IndexUpgradeAction.INSTANCE).setIndex(testIndex).get()); + () -> new IndexUpgradeAction.RequestBuilder(client()).setIndex(testIndex).get()); assertThat(ex.getMessage(), equalTo("Index [" + testIndex + "] cannot be upgraded")); SearchResponse searchResponse = client().prepareSearch(testIndex).get(); @@ -132,10 +132,10 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase { public void testIndexUpgradeInfoOnEmptyCluster() { // On empty cluster asking for all indices shouldn't fail since no indices means nothing needs to be upgraded - Response response = client().prepareExecute(IndexUpgradeInfoAction.INSTANCE).setIndices("_all").get(); + Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("_all").get(); assertThat(response.getActions().entrySet(), empty()); // but calling on a particular index should fail - assertThrows(client().prepareExecute(IndexUpgradeInfoAction.INSTANCE).setIndices("test"), IndexNotFoundException.class); + assertThrows(new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test"), IndexNotFoundException.class); } } diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java index c3f371a74b7..abc157119b4 100644 --- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java +++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java @@ -171,13 +171,12 @@ public class IndexUpgradeTasksIT extends ESIntegTestCase { ensureYellow("test"); - IndexUpgradeInfoAction.Response infoResponse = client().prepareExecute(IndexUpgradeInfoAction.INSTANCE).setIndices("test").get(); + IndexUpgradeInfoAction.Response infoResponse = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get(); assertThat(infoResponse.getActions().keySet(), contains("test")); assertThat(infoResponse.getActions().get("test"), equalTo(UpgradeActionRequired.UPGRADE)); - ActionFuture upgradeResponse = - client().prepareExecute(IndexUpgradeAction.INSTANCE).setIndex("test").execute(); + ActionFuture upgradeResponse = new IndexUpgradeAction.RequestBuilder(client()).setIndex("test").execute(); assertThat(mockUpgradePlugin.upgradeCalledLatch.await(10, TimeUnit.SECONDS), equalTo(true)); diff --git a/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat b/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat index 37ca14dd094..281b06cf77b 100644 --- a/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat +++ b/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat @@ -10,7 +10,7 @@ setlocal enableextensions set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-watcher-env call "%~dp0elasticsearch-cli.bat" ^ org.elasticsearch.xpack.watcher.trigger.schedule.tool.CronEvalTool ^ - %* ^ + %%* ^ || exit /b 1 endlocal diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index fa169933e45..3461c530b44 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -73,6 +73,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -477,8 +478,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } throw new AssertionError("unexpected state, retrying with next run"); - }); - + }, 30, TimeUnit.SECONDS); } protected void ensureLicenseEnabled() throws Exception { diff --git a/x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ModelPlotsIT.java b/x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ModelPlotsIT.java index 81a44cd1336..db854a6cc64 100644 --- a/x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ModelPlotsIT.java +++ b/x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ModelPlotsIT.java @@ -129,7 +129,11 @@ public class ModelPlotsIT extends MlNativeAutodetectIntegTestCase { startDatafeed(datafeedId, 0, System.currentTimeMillis()); waitUntilJobIsClosed(job.getId()); - assertThat(getBuckets(job.getId()).size(), equalTo(23)); + // As the initial time is random, there's a chance the first record is + // aligned on a bucket start. Thus we check the buckets are in [23, 24] + assertThat(getBuckets(job.getId()).size(), greaterThanOrEqualTo(23)); + assertThat(getBuckets(job.getId()).size(), lessThanOrEqualTo(24)); + Set modelPlotTerms = modelPlotTerms(job.getId(), "by_field_value"); assertThat(modelPlotTerms, containsInAnyOrder("user_2", "user_3")); } diff --git a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml index 9c445f418da..0b224518782 100644 --- a/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml +++ b/x-pack/qa/multi-cluster-search-security/src/test/resources/rest-api-spec/test/multi_cluster/50_missing.yml @@ -56,13 +56,13 @@ teardown: - match: { hits.total: 0 } - do: - catch: "request" + catch: "forbidden" headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: index: "*:foo-bar" - do: - catch: "request" + catch: "forbidden" headers: { Authorization: "Basic am9lOnMza3JpdA==" } search: index: "my_remote_cluster:foo-bar" diff --git a/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java b/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java index d21900ba47a..bcea8338515 100644 --- a/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java +++ b/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java @@ -13,8 +13,11 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.DeleteByQueryAction; +import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder; import org.elasticsearch.index.reindex.ReindexAction; +import org.elasticsearch.index.reindex.ReindexRequestBuilder; import org.elasticsearch.index.reindex.UpdateByQueryAction; +import org.elasticsearch.index.reindex.UpdateByQueryRequestBuilder; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.xpack.core.security.SecurityField; @@ -45,20 +48,20 @@ public class ReindexWithSecurityIT extends SecurityIntegTestCase { public void testDeleteByQuery() { createIndicesWithRandomAliases("test1", "test2", "test3"); - BulkByScrollResponse response = DeleteByQueryAction.INSTANCE.newRequestBuilder(client()) + BulkByScrollResponse response = new DeleteByQueryRequestBuilder(client(), DeleteByQueryAction.INSTANCE) .source("test1", "test2") .filter(QueryBuilders.matchAllQuery()) .get(); assertNotNull(response); - response = DeleteByQueryAction.INSTANCE.newRequestBuilder(client()) + response = new DeleteByQueryRequestBuilder(client(), DeleteByQueryAction.INSTANCE) .source("test*") .filter(QueryBuilders.matchAllQuery()) .get(); assertNotNull(response); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, - () -> DeleteByQueryAction.INSTANCE.newRequestBuilder(client()) + () -> new DeleteByQueryRequestBuilder(client(), DeleteByQueryAction.INSTANCE) .source("test1", "index1") .filter(QueryBuilders.matchAllQuery()) .get()); @@ -68,29 +71,30 @@ public class ReindexWithSecurityIT extends SecurityIntegTestCase { public void testUpdateByQuery() { createIndicesWithRandomAliases("test1", "test2", "test3"); - BulkByScrollResponse response = UpdateByQueryAction.INSTANCE.newRequestBuilder(client()).source("test1", "test2").get(); + BulkByScrollResponse response = new UpdateByQueryRequestBuilder(client(), UpdateByQueryAction.INSTANCE) + .source("test1", "test2").get(); assertNotNull(response); - response = UpdateByQueryAction.INSTANCE.newRequestBuilder(client()).source("test*").get(); + response = new UpdateByQueryRequestBuilder(client(), UpdateByQueryAction.INSTANCE).source("test*").get(); assertNotNull(response); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, - () -> UpdateByQueryAction.INSTANCE.newRequestBuilder(client()).source("test1", "index1").get()); + () -> new UpdateByQueryRequestBuilder(client(), UpdateByQueryAction.INSTANCE).source("test1", "index1").get()); assertEquals("no such index", e.getMessage()); } public void testReindex() { createIndicesWithRandomAliases("test1", "test2", "test3", "dest"); - BulkByScrollResponse response = ReindexAction.INSTANCE.newRequestBuilder(client()).source("test1", "test2") + BulkByScrollResponse response = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("test1", "test2") .destination("dest").get(); assertNotNull(response); - response = ReindexAction.INSTANCE.newRequestBuilder(client()).source("test*").destination("dest").get(); + response = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("test*").destination("dest").get(); assertNotNull(response); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, - () -> ReindexAction.INSTANCE.newRequestBuilder(client()).source("test1", "index1").destination("dest").get()); + () -> new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("test1", "index1").destination("dest").get()); assertEquals("no such index", e.getMessage()); } } diff --git a/x-pack/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java b/x-pack/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java index bdbb75491ca..cb8afc876a4 100644 --- a/x-pack/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java +++ b/x-pack/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/RestSqlSecurityIT.java @@ -9,6 +9,7 @@ import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.Nullable; @@ -177,7 +178,9 @@ public class RestSqlSecurityIT extends SqlSecurityTestCase { request.addParameter("mode", mode); } if (asUser != null) { - request.addHeader("es-security-runas-user", asUser); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("es-security-runas-user", asUser); + request.setOptions(options); } request.setEntity(entity); return toMap(client().performRequest(request)); diff --git a/x-pack/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/rest/RestSqlTestCase.java b/x-pack/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/rest/RestSqlTestCase.java index 80dd09d3c47..7403bee5448 100644 --- a/x-pack/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/rest/RestSqlTestCase.java +++ b/x-pack/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/rest/RestSqlTestCase.java @@ -10,6 +10,7 @@ import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.CheckedSupplier; @@ -319,7 +320,10 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe request.addParameter("mode", mode); // JDBC or PLAIN mode } if (randomBoolean()) { - request.addHeader("Accept", randomFrom("*/*", "application/json")); + // JSON is the default but randomly set it sometime for extra coverage + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("Accept", randomFrom("*/*", "application/json")); + request.setOptions(options); } request.setEntity(sql); Response response = client().performRequest(request); @@ -536,7 +540,9 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe Request request = new Request("POST", "/_xpack/sql" + suffix); request.addParameter("error_trace", "true"); request.setEntity(entity); - request.addHeader("Accept", accept); + RequestOptions.Builder options = request.getOptions().toBuilder(); + options.addHeader("Accept", accept); + request.setOptions(options); Response response = client().performRequest(request); return new Tuple<>( Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)),