From 3809450bf3aaa48317b6e717525550b818315847 Mon Sep 17 00:00:00 2001 From: Sohaib Iftikhar Date: Mon, 4 Jun 2018 10:34:55 +0200 Subject: [PATCH] Move pipeline APIs to ingest namespace (#31027) --- .../elasticsearch/client/ClusterClient.java | 73 ----- .../elasticsearch/client/IngestClient.java | 114 +++++++ .../client/RestHighLevelClient.java | 10 + .../elasticsearch/client/ClusterClientIT.java | 57 ---- .../elasticsearch/client/IngestClientIT.java | 83 ++++++ .../ClusterClientDocumentationIT.java | 216 -------------- .../IngestClientDocumentationIT.java | 279 ++++++++++++++++++ .../delete_pipeline.asciidoc | 24 +- .../{cluster => ingest}/get_pipeline.asciidoc | 22 +- .../{cluster => ingest}/put_pipeline.asciidoc | 24 +- .../high-level/supported-apis.asciidoc | 17 +- 11 files changed, 532 insertions(+), 387 deletions(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/IngestClient.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/IngestClientIT.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java rename docs/java-rest/high-level/{cluster => ingest}/delete_pipeline.asciidoc (75%) rename docs/java-rest/high-level/{cluster => ingest}/get_pipeline.asciidoc (76%) rename docs/java-rest/high-level/{cluster => ingest}/put_pipeline.asciidoc (77%) 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 4254b132b57..f3c84db79d6 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 @@ -23,11 +23,6 @@ import org.apache.http.Header; 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.GetPipelineRequest; -import org.elasticsearch.action.ingest.GetPipelineResponse; -import org.elasticsearch.action.ingest.DeletePipelineRequest; -import org.elasticsearch.action.ingest.WritePipelineResponse; import java.io.IOException; @@ -68,72 +63,4 @@ public final class ClusterClient { restHighLevelClient.performRequestAsyncAndParseEntity(clusterUpdateSettingsRequest, RequestConverters::clusterPutSettings, ClusterUpdateSettingsResponse::fromXContent, listener, emptySet(), headers); } - - /** - * Add a pipeline or update an existing pipeline in the cluster - *

- * See - * Put Pipeline API on elastic.co - */ - public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline, - WritePipelineResponse::fromXContent, emptySet(), headers); - } - - /** - * Asynchronously add a pipeline or update an existing pipeline in the cluster - *

- * See - * Put Pipeline API on elastic.co - */ - public void putPipelineAsync(PutPipelineRequest request, ActionListener listener, Header... headers) { - restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline, - 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/IngestClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IngestClient.java new file mode 100644 index 00000000000..72b1813f939 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IngestClient.java @@ -0,0 +1,114 @@ +/* + * 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.action.ActionListener; +import org.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineResponse; +import org.elasticsearch.action.ingest.PutPipelineRequest; +import org.elasticsearch.action.ingest.WritePipelineResponse; + +import java.io.IOException; + +import static java.util.Collections.emptySet; + +/** + * A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Ingest API. + *

+ * See Ingest API on elastic.co + */ +public final class IngestClient { + + private final RestHighLevelClient restHighLevelClient; + + IngestClient(RestHighLevelClient restHighLevelClient) { + this.restHighLevelClient = restHighLevelClient; + } + + /** + * Add a pipeline or update an existing pipeline + *

+ * See + * Put Pipeline API on elastic.co + */ + public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException { + return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline, + WritePipelineResponse::fromXContent, emptySet(), headers); + } + + /** + * Asynchronously add a pipeline or update an existing pipeline + *

+ * See + * Put Pipeline API on elastic.co + */ + public void putPipelineAsync(PutPipelineRequest request, ActionListener listener, Header... headers) { + restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline, + 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/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index fc74a43dd80..a9587b73c19 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 @@ -191,6 +191,7 @@ public class RestHighLevelClient implements Closeable { private final IndicesClient indicesClient = new IndicesClient(this); private final ClusterClient clusterClient = new ClusterClient(this); + private final IngestClient ingestClient = new IngestClient(this); private final SnapshotClient snapshotClient = new SnapshotClient(this); private final TasksClient tasksClient = new TasksClient(this); @@ -256,6 +257,15 @@ public class RestHighLevelClient implements Closeable { return clusterClient; } + /** + * Provides a {@link IngestClient} which can be used to access the Ingest API. + * + * See Ingest API on elastic.co + */ + public final IngestClient ingest() { + return ingestClient; + } + /** * Provides a {@link SnapshotClient} which can be used to access the Snapshot API. * 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 42db51e81b7..9314bb2e36c 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,20 +22,12 @@ 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.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; import org.elasticsearch.common.unit.ByteSizeUnit; -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.PipelineConfiguration; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -113,53 +105,4 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase { assertThat(exception.getMessage(), equalTo( "Elasticsearch exception [type=illegal_argument_exception, reason=transient setting [" + setting + "], not recognized]")); } - - public void testPutPipeline() throws IOException { - String id = "some_pipeline_id"; - XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); - PutPipelineRequest request = new PutPipelineRequest( - id, - BytesReference.bytes(pipelineBuilder), - pipelineBuilder.contentType()); - - 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/IngestClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IngestClientIT.java new file mode 100644 index 00000000000..ecc0d0052d4 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IngestClientIT.java @@ -0,0 +1,83 @@ +/* + * 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.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineResponse; +import org.elasticsearch.action.ingest.PutPipelineRequest; +import org.elasticsearch.action.ingest.WritePipelineResponse; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.ingest.PipelineConfiguration; + +import java.io.IOException; + +public class IngestClientIT extends ESRestHighLevelClientTestCase { + + public void testPutPipeline() throws IOException { + String id = "some_pipeline_id"; + XContentBuilder pipelineBuilder = buildRandomXContentPipeline(); + PutPipelineRequest request = new PutPipelineRequest( + id, + BytesReference.bytes(pipelineBuilder), + pipelineBuilder.contentType()); + + WritePipelineResponse putPipelineResponse = + execute(request, highLevelClient().ingest()::putPipeline, highLevelClient().ingest()::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().ingest()::getPipeline, highLevelClient().ingest()::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().ingest()::deletePipeline, highLevelClient().ingest()::deletePipelineAsync); + assertTrue(response.isAcknowledged()); + } +} 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 0da577f17e8..304c5010a47 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 @@ -186,220 +186,4 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase assertTrue(latch.await(30L, TimeUnit.SECONDS)); } } - - public void testPutPipeline() throws IOException { - RestHighLevelClient client = highLevelClient(); - - { - // tag::put-pipeline-request - String source = - "{\"description\":\"my set of processors\"," + - "\"processors\":[{\"set\":{\"field\":\"foo\",\"value\":\"bar\"}}]}"; - PutPipelineRequest request = new PutPipelineRequest( - "my-pipeline-id", // <1> - new BytesArray(source.getBytes(StandardCharsets.UTF_8)), // <2> - XContentType.JSON // <3> - ); - // end::put-pipeline-request - - // tag::put-pipeline-request-timeout - request.timeout(TimeValue.timeValueMinutes(2)); // <1> - request.timeout("2m"); // <2> - // end::put-pipeline-request-timeout - - // tag::put-pipeline-request-masterTimeout - request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> - request.masterNodeTimeout("1m"); // <2> - // end::put-pipeline-request-masterTimeout - - // tag::put-pipeline-execute - WritePipelineResponse response = client.cluster().putPipeline(request); // <1> - // end::put-pipeline-execute - - // tag::put-pipeline-response - boolean acknowledged = response.isAcknowledged(); // <1> - // end::put-pipeline-response - assertTrue(acknowledged); - } - } - - public void testPutPipelineAsync() throws Exception { - RestHighLevelClient client = highLevelClient(); - - { - String source = - "{\"description\":\"my set of processors\"," + - "\"processors\":[{\"set\":{\"field\":\"foo\",\"value\":\"bar\"}}]}"; - PutPipelineRequest request = new PutPipelineRequest( - "my-pipeline-id", - new BytesArray(source.getBytes(StandardCharsets.UTF_8)), - XContentType.JSON - ); - - // tag::put-pipeline-execute-listener - ActionListener listener = - new ActionListener() { - @Override - public void onResponse(WritePipelineResponse response) { - // <1> - } - - @Override - public void onFailure(Exception e) { - // <2> - } - }; - // end::put-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::put-pipeline-execute-async - client.cluster().putPipelineAsync(request, listener); // <1> - // end::put-pipeline-execute-async - - 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-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java new file mode 100644 index 00000000000..7971e49da44 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IngestClientDocumentationIT.java @@ -0,0 +1,279 @@ +/* + * 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.documentation; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.LatchedActionListener; +import org.elasticsearch.action.ingest.DeletePipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineRequest; +import org.elasticsearch.action.ingest.GetPipelineResponse; +import org.elasticsearch.action.ingest.PutPipelineRequest; +import org.elasticsearch.action.ingest.WritePipelineResponse; +import org.elasticsearch.client.ESRestHighLevelClientTestCase; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.ingest.PipelineConfiguration; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * This class is used to generate the Java Ingest API documentation. + * You need to wrap your code between two tags like: + * // tag::example + * // end::example + * + * Where example is your tag name. + * + * Then in the documentation, you can extract what is between tag and end tags with + * ["source","java",subs="attributes,callouts,macros"] + * -------------------------------------------------- + * include-tagged::{doc-tests}/IngestClientDocumentationIT.java[example] + * -------------------------------------------------- + * + * The column width of the code block is 84. If the code contains a line longer + * than 84, the line will be cut and a horizontal scroll bar will be displayed. + * (the code indentation of the tag is not included in the width) + */ +public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase { + + public void testPutPipeline() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + // tag::put-pipeline-request + String source = + "{\"description\":\"my set of processors\"," + + "\"processors\":[{\"set\":{\"field\":\"foo\",\"value\":\"bar\"}}]}"; + PutPipelineRequest request = new PutPipelineRequest( + "my-pipeline-id", // <1> + new BytesArray(source.getBytes(StandardCharsets.UTF_8)), // <2> + XContentType.JSON // <3> + ); + // end::put-pipeline-request + + // tag::put-pipeline-request-timeout + request.timeout(TimeValue.timeValueMinutes(2)); // <1> + request.timeout("2m"); // <2> + // end::put-pipeline-request-timeout + + // tag::put-pipeline-request-masterTimeout + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> + request.masterNodeTimeout("1m"); // <2> + // end::put-pipeline-request-masterTimeout + + // tag::put-pipeline-execute + WritePipelineResponse response = client.ingest().putPipeline(request); // <1> + // end::put-pipeline-execute + + // tag::put-pipeline-response + boolean acknowledged = response.isAcknowledged(); // <1> + // end::put-pipeline-response + assertTrue(acknowledged); + } + } + + public void testPutPipelineAsync() throws Exception { + RestHighLevelClient client = highLevelClient(); + + { + String source = + "{\"description\":\"my set of processors\"," + + "\"processors\":[{\"set\":{\"field\":\"foo\",\"value\":\"bar\"}}]}"; + PutPipelineRequest request = new PutPipelineRequest( + "my-pipeline-id", + new BytesArray(source.getBytes(StandardCharsets.UTF_8)), + XContentType.JSON + ); + + // tag::put-pipeline-execute-listener + ActionListener listener = + new ActionListener() { + @Override + public void onResponse(WritePipelineResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::put-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::put-pipeline-execute-async + client.ingest().putPipelineAsync(request, listener); // <1> + // end::put-pipeline-execute-async + + 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.ingest().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.ingest().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.ingest().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.ingest().deletePipelineAsync(request, listener); // <1> + // end::delete-pipeline-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + } + +} diff --git a/docs/java-rest/high-level/cluster/delete_pipeline.asciidoc b/docs/java-rest/high-level/ingest/delete_pipeline.asciidoc similarity index 75% rename from docs/java-rest/high-level/cluster/delete_pipeline.asciidoc rename to docs/java-rest/high-level/ingest/delete_pipeline.asciidoc index f809f831f78..3801f8a3b52 100644 --- a/docs/java-rest/high-level/cluster/delete_pipeline.asciidoc +++ b/docs/java-rest/high-level/ingest/delete_pipeline.asciidoc @@ -1,14 +1,14 @@ -[[java-rest-high-cluster-delete-pipeline]] +[[java-rest-high-ingest-delete-pipeline]] === Delete Pipeline API -[[java-rest-high-cluster-delete-pipeline-request]] +[[java-rest-high-ingest-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] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-request] -------------------------------------------------- <1> The pipeline id to delete @@ -17,28 +17,28 @@ The following arguments can optionally be provided: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request-timeout] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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]] +[[java-rest-high-ingest-delete-pipeline-sync]] ==== Synchronous Execution ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-execute] -------------------------------------------------- <1> Execute the request and get back the response in a `WritePipelineResponse` object. -[[java-rest-high-cluster-delete-pipeline-async]] +[[java-rest-high-ingest-delete-pipeline-async]] ==== Asynchronous Execution The asynchronous execution of a delete pipeline request requires both the `DeletePipelineRequest` @@ -47,7 +47,7 @@ method: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute-async] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[delete-pipeline-execute-async] -------------------------------------------------- <1> The `DeletePipelineRequest` to execute and the `ActionListener` to use when the execution completes @@ -61,13 +61,13 @@ A typical listener for `WritePipelineResponse` looks like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute-listener] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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]] +[[java-rest-high-ingest-delete-pipeline-response]] ==== Delete Pipeline Response The returned `WritePipelineResponse` allows to retrieve information about the executed @@ -75,6 +75,6 @@ The returned `WritePipelineResponse` allows to retrieve information about the ex ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-response] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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/ingest/get_pipeline.asciidoc similarity index 76% rename from docs/java-rest/high-level/cluster/get_pipeline.asciidoc rename to docs/java-rest/high-level/ingest/get_pipeline.asciidoc index d6a9472a715..54ba545d709 100644 --- a/docs/java-rest/high-level/cluster/get_pipeline.asciidoc +++ b/docs/java-rest/high-level/ingest/get_pipeline.asciidoc @@ -1,14 +1,14 @@ -[[java-rest-high-cluster-get-pipeline]] +[[java-rest-high-ingest-get-pipeline]] === Get Pipeline API -[[java-rest-high-cluster-get-pipeline-request]] +[[java-rest-high-ingest-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] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-request] -------------------------------------------------- <1> The pipeline id to fetch @@ -17,21 +17,21 @@ The following arguments can optionally be provided: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-request-masterTimeout] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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]] +[[java-rest-high-ingest-get-pipeline-sync]] ==== Synchronous Execution ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-execute] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-execute] -------------------------------------------------- <1> Execute the request and get back the response in a GetPipelineResponse object. -[[java-rest-high-cluster-get-pipeline-async]] +[[java-rest-high-ingest-get-pipeline-async]] ==== Asynchronous Execution The asynchronous execution of a get pipeline request requires both the `GetPipelineRequest` @@ -40,7 +40,7 @@ method: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-execute-async] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[get-pipeline-execute-async] -------------------------------------------------- <1> The `GetPipelineRequest` to execute and the `ActionListener` to use when the execution completes @@ -54,13 +54,13 @@ A typical listener for `GetPipelineResponse` looks like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-execute-listener] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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]] +[[java-rest-high-ingest-get-pipeline-response]] ==== Get Pipeline Response The returned `GetPipelineResponse` allows to retrieve information about the executed @@ -68,7 +68,7 @@ The returned `GetPipelineResponse` allows to retrieve information about the exec ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[get-pipeline-response] +include-tagged::{doc-tests}/IngestClientDocumentationIT.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. diff --git a/docs/java-rest/high-level/cluster/put_pipeline.asciidoc b/docs/java-rest/high-level/ingest/put_pipeline.asciidoc similarity index 77% rename from docs/java-rest/high-level/cluster/put_pipeline.asciidoc rename to docs/java-rest/high-level/ingest/put_pipeline.asciidoc index 942b75b74cd..12a4eb15bce 100644 --- a/docs/java-rest/high-level/cluster/put_pipeline.asciidoc +++ b/docs/java-rest/high-level/ingest/put_pipeline.asciidoc @@ -1,7 +1,7 @@ -[[java-rest-high-cluster-put-pipeline]] +[[java-rest-high-ingest-put-pipeline]] === Put Pipeline API -[[java-rest-high-cluster-put-pipeline-request]] +[[java-rest-high-ingest-put-pipeline-request]] ==== Put Pipeline Request A `PutPipelineRequest` requires an `id` argument, a source and a `XContentType`. The source consists @@ -9,7 +9,7 @@ of a description and a list of `Processor` objects. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-request] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-request] -------------------------------------------------- <1> The pipeline id <2> The source for the pipeline as a `ByteArray`. @@ -20,28 +20,28 @@ The following arguments can optionally be provided: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-request-timeout] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-request-timeout] -------------------------------------------------- <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"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-request-masterTimeout] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-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-put-pipeline-sync]] +[[java-rest-high-ingest-put-pipeline-sync]] ==== Synchronous Execution ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-execute] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-execute] -------------------------------------------------- <1> Execute the request and get back the response in a WritePipelineResponse object. -[[java-rest-high-cluster-put-pipeline-async]] +[[java-rest-high-ingest-put-pipeline-async]] ==== Asynchronous Execution The asynchronous execution of a put pipeline request requires both the `PutPipelineRequest` @@ -50,7 +50,7 @@ method: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-execute-async] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-execute-async] -------------------------------------------------- <1> The `PutPipelineRequest` to execute and the `ActionListener` to use when the execution completes @@ -64,13 +64,13 @@ A typical listener for `WritePipelineResponse` looks like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-execute-listener] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-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-put-pipeline-response]] +[[java-rest-high-ingest-put-pipeline-response]] ==== Put Pipeline Response The returned `WritePipelineResponse` allows to retrieve information about the executed @@ -78,6 +78,6 @@ The returned `WritePipelineResponse` allows to retrieve information about the ex ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-response] +include-tagged::{doc-tests}/IngestClientDocumentationIT.java[put-pipeline-response] -------------------------------------------------- <1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 34873a248b7..f15baeb6b73 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -106,14 +106,19 @@ include::indices/put_template.asciidoc[] 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[] + +== Ingest APIs +The Java High Level REST Client supports the following Ingest APIs: + +* <> +* <> +* <> + +include::ingest/put_pipeline.asciidoc[] +include::ingest/get_pipeline.asciidoc[] +include::ingest/delete_pipeline.asciidoc[] == Snapshot APIs