Skip to content

Commit 1f4e775

Browse files
sohaibiftikharjavanna
authored andcommitted
REST high-level client: add delete ingest pipeline API (#30865)
Relates to #27205
1 parent 7d7d2f4 commit 1f4e775

File tree

12 files changed

+286
-136
lines changed

12 files changed

+286
-136
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/ClusterClient.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import org.elasticsearch.action.ActionListener;
2424
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
2525
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
26+
import org.elasticsearch.action.ingest.PutPipelineRequest;
2627
import org.elasticsearch.action.ingest.GetPipelineRequest;
2728
import org.elasticsearch.action.ingest.GetPipelineResponse;
28-
import org.elasticsearch.action.ingest.PutPipelineRequest;
29-
import org.elasticsearch.action.ingest.PutPipelineResponse;
29+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
30+
import org.elasticsearch.action.ingest.WritePipelineResponse;
3031

3132
import java.io.IOException;
3233

@@ -74,9 +75,9 @@ public void putSettingsAsync(ClusterUpdateSettingsRequest clusterUpdateSettingsR
7475
* See
7576
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
7677
*/
77-
public PutPipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException {
78+
public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException {
7879
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline,
79-
PutPipelineResponse::fromXContent, emptySet(), headers);
80+
WritePipelineResponse::fromXContent, emptySet(), headers);
8081
}
8182

8283
/**
@@ -85,9 +86,9 @@ public PutPipelineResponse putPipeline(PutPipelineRequest request, Header... hea
8586
* See
8687
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
8788
*/
88-
public void putPipelineAsync(PutPipelineRequest request, ActionListener<PutPipelineResponse> listener, Header... headers) {
89+
public void putPipelineAsync(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
8990
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline,
90-
PutPipelineResponse::fromXContent, listener, emptySet(), headers);
91+
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
9192
}
9293

9394
/**
@@ -111,4 +112,28 @@ public void getPipelineAsync(GetPipelineRequest request, ActionListener<GetPipel
111112
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::getPipeline,
112113
GetPipelineResponse::fromXContent, listener, emptySet(), headers);
113114
}
115+
116+
/**
117+
* Delete an existing pipeline
118+
* <p>
119+
* See
120+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
121+
* Delete Pipeline API on elastic.co</a>
122+
*/
123+
public WritePipelineResponse deletePipeline(DeletePipelineRequest request, Header... headers) throws IOException {
124+
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::deletePipeline,
125+
WritePipelineResponse::fromXContent, emptySet(), headers);
126+
}
127+
128+
/**
129+
* Asynchronously delete an existing pipeline
130+
* <p>
131+
* See
132+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
133+
* Delete Pipeline API on elastic.co</a>
134+
*/
135+
public void deletePipelineAsync(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
136+
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline,
137+
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
138+
}
114139
}

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.elasticsearch.action.get.GetRequest;
6161
import org.elasticsearch.action.get.MultiGetRequest;
6262
import org.elasticsearch.action.index.IndexRequest;
63+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
6364
import org.elasticsearch.action.ingest.PutPipelineRequest;
6465
import org.elasticsearch.action.ingest.GetPipelineRequest;
6566
import org.elasticsearch.action.search.ClearScrollRequest;
@@ -659,6 +660,20 @@ static Request putPipeline(PutPipelineRequest putPipelineRequest) throws IOExcep
659660
return request;
660661
}
661662

663+
static Request deletePipeline(DeletePipelineRequest deletePipelineRequest) {
664+
String endpoint = new EndpointBuilder()
665+
.addPathPartAsIs("_ingest/pipeline")
666+
.addPathPart(deletePipelineRequest.getId())
667+
.build();
668+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
669+
670+
Params parameters = new Params(request);
671+
parameters.withTimeout(deletePipelineRequest.timeout());
672+
parameters.withMasterTimeout(deletePipelineRequest.masterNodeTimeout());
673+
674+
return request;
675+
}
676+
662677
static Request listTasks(ListTasksRequest listTaskRequest) {
663678
if (listTaskRequest.getTaskId() != null && listTaskRequest.getTaskId().isSet()) {
664679
throw new IllegalArgumentException("TaskId cannot be used for list tasks request");

client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import org.elasticsearch.action.ingest.GetPipelineRequest;
2626
import org.elasticsearch.action.ingest.GetPipelineResponse;
2727
import org.elasticsearch.action.ingest.PutPipelineRequest;
28-
import org.elasticsearch.action.ingest.PutPipelineResponse;
28+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
29+
import org.elasticsearch.action.ingest.WritePipelineResponse;
2930
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
3031
import org.elasticsearch.common.bytes.BytesReference;
3132
import org.elasticsearch.common.settings.Settings;
@@ -121,7 +122,7 @@ public void testPutPipeline() throws IOException {
121122
BytesReference.bytes(pipelineBuilder),
122123
pipelineBuilder.contentType());
123124

124-
PutPipelineResponse putPipelineResponse =
125+
WritePipelineResponse putPipelineResponse =
125126
execute(request, highLevelClient().cluster()::putPipeline, highLevelClient().cluster()::putPipelineAsync);
126127
assertTrue(putPipelineResponse.isAcknowledged());
127128
}
@@ -148,4 +149,17 @@ public void testGetPipeline() throws IOException {
148149
new PipelineConfiguration(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType());
149150
assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap());
150151
}
152+
153+
public void testDeletePipeline() throws IOException {
154+
String id = "some_pipeline_id";
155+
{
156+
createPipeline(id);
157+
}
158+
159+
DeletePipelineRequest request = new DeletePipelineRequest(id);
160+
161+
WritePipelineResponse response =
162+
execute(request, highLevelClient().cluster()::deletePipeline, highLevelClient().cluster()::deletePipelineAsync);
163+
assertTrue(response.isAcknowledged());
164+
}
151165
}

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.elasticsearch.action.get.GetRequest;
6464
import org.elasticsearch.action.get.MultiGetRequest;
6565
import org.elasticsearch.action.index.IndexRequest;
66+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
6667
import org.elasticsearch.action.ingest.GetPipelineRequest;
6768
import org.elasticsearch.action.ingest.PutPipelineRequest;
6869
import org.elasticsearch.action.search.ClearScrollRequest;
@@ -1497,6 +1498,21 @@ public void testGetPipeline() {
14971498
assertEquals(expectedParams, expectedRequest.getParameters());
14981499
}
14991500

1501+
public void testDeletePipeline() {
1502+
String pipelineId = "some_pipeline_id";
1503+
Map<String, String> expectedParams = new HashMap<>();
1504+
DeletePipelineRequest request = new DeletePipelineRequest(pipelineId);
1505+
setRandomMasterTimeout(request, expectedParams);
1506+
setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
1507+
Request expectedRequest = RequestConverters.deletePipeline(request);
1508+
StringJoiner endpoint = new StringJoiner("/", "/", "");
1509+
endpoint.add("_ingest/pipeline");
1510+
endpoint.add(pipelineId);
1511+
assertEquals(endpoint.toString(), expectedRequest.getEndpoint());
1512+
assertEquals(HttpDelete.METHOD_NAME, expectedRequest.getMethod());
1513+
assertEquals(expectedParams, expectedRequest.getParameters());
1514+
}
1515+
15001516
public void testRollover() throws IOException {
15011517
RolloverRequest rolloverRequest = new RolloverRequest(randomAlphaOfLengthBetween(3, 10),
15021518
randomBoolean() ? null : randomAlphaOfLengthBetween(3, 10));

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ClusterClientDocumentationIT.java

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.elasticsearch.action.ingest.GetPipelineRequest;
2727
import org.elasticsearch.action.ingest.GetPipelineResponse;
2828
import org.elasticsearch.action.ingest.PutPipelineRequest;
29-
import org.elasticsearch.action.ingest.PutPipelineResponse;
29+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
30+
import org.elasticsearch.action.ingest.WritePipelineResponse;
3031
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
3132
import org.elasticsearch.client.RestHighLevelClient;
3233
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
@@ -212,7 +213,7 @@ public void testPutPipeline() throws IOException {
212213
// end::put-pipeline-request-masterTimeout
213214

214215
// tag::put-pipeline-execute
215-
PutPipelineResponse response = client.cluster().putPipeline(request); // <1>
216+
WritePipelineResponse response = client.cluster().putPipeline(request); // <1>
216217
// end::put-pipeline-execute
217218

218219
// tag::put-pipeline-response
@@ -236,10 +237,10 @@ public void testPutPipelineAsync() throws Exception {
236237
);
237238

238239
// tag::put-pipeline-execute-listener
239-
ActionListener<PutPipelineResponse> listener =
240-
new ActionListener<PutPipelineResponse>() {
240+
ActionListener<WritePipelineResponse> listener =
241+
new ActionListener<WritePipelineResponse>() {
241242
@Override
242-
public void onResponse(PutPipelineResponse response) {
243+
public void onResponse(WritePipelineResponse response) {
243244
// <1>
244245
}
245246

@@ -331,4 +332,74 @@ public void onFailure(Exception e) {
331332
assertTrue(latch.await(30L, TimeUnit.SECONDS));
332333
}
333334
}
335+
336+
public void testDeletePipeline() throws IOException {
337+
RestHighLevelClient client = highLevelClient();
338+
339+
{
340+
createPipeline("my-pipeline-id");
341+
}
342+
343+
{
344+
// tag::delete-pipeline-request
345+
DeletePipelineRequest request = new DeletePipelineRequest("my-pipeline-id"); // <1>
346+
// end::delete-pipeline-request
347+
348+
// tag::delete-pipeline-request-timeout
349+
request.timeout(TimeValue.timeValueMinutes(2)); // <1>
350+
request.timeout("2m"); // <2>
351+
// end::delete-pipeline-request-timeout
352+
353+
// tag::delete-pipeline-request-masterTimeout
354+
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1>
355+
request.masterNodeTimeout("1m"); // <2>
356+
// end::delete-pipeline-request-masterTimeout
357+
358+
// tag::delete-pipeline-execute
359+
WritePipelineResponse response = client.cluster().deletePipeline(request); // <1>
360+
// end::delete-pipeline-execute
361+
362+
// tag::delete-pipeline-response
363+
boolean acknowledged = response.isAcknowledged(); // <1>
364+
// end::delete-pipeline-response
365+
assertTrue(acknowledged);
366+
}
367+
}
368+
369+
public void testDeletePipelineAsync() throws Exception {
370+
RestHighLevelClient client = highLevelClient();
371+
372+
{
373+
createPipeline("my-pipeline-id");
374+
}
375+
376+
{
377+
DeletePipelineRequest request = new DeletePipelineRequest("my-pipeline-id");
378+
379+
// tag::delete-pipeline-execute-listener
380+
ActionListener<WritePipelineResponse> listener =
381+
new ActionListener<WritePipelineResponse>() {
382+
@Override
383+
public void onResponse(WritePipelineResponse response) {
384+
// <1>
385+
}
386+
387+
@Override
388+
public void onFailure(Exception e) {
389+
// <2>
390+
}
391+
};
392+
// end::delete-pipeline-execute-listener
393+
394+
// Replace the empty listener by a blocking listener in test
395+
final CountDownLatch latch = new CountDownLatch(1);
396+
listener = new LatchedActionListener<>(listener, latch);
397+
398+
// tag::delete-pipeline-execute-async
399+
client.cluster().deletePipelineAsync(request, listener); // <1>
400+
// end::delete-pipeline-execute-async
401+
402+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
403+
}
404+
}
334405
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[[java-rest-high-cluster-delete-pipeline]]
2+
=== Delete Pipeline API
3+
4+
[[java-rest-high-cluster-delete-pipeline-request]]
5+
==== Delete Pipeline Request
6+
7+
A `DeletePipelineRequest` requires a pipeline `id` to delete.
8+
9+
["source","java",subs="attributes,callouts,macros"]
10+
--------------------------------------------------
11+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request]
12+
--------------------------------------------------
13+
<1> The pipeline id to delete
14+
15+
==== Optional arguments
16+
The following arguments can optionally be provided:
17+
18+
["source","java",subs="attributes,callouts,macros"]
19+
--------------------------------------------------
20+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request-timeout]
21+
--------------------------------------------------
22+
<1> Timeout to wait for the all the nodes to acknowledge the pipeline deletion as a `TimeValue`
23+
<2> Timeout to wait for the all the nodes to acknowledge the pipeline deletion as a `String`
24+
25+
["source","java",subs="attributes,callouts,macros"]
26+
--------------------------------------------------
27+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-request-masterTimeout]
28+
--------------------------------------------------
29+
<1> Timeout to connect to the master node as a `TimeValue`
30+
<2> Timeout to connect to the master node as a `String`
31+
32+
[[java-rest-high-cluster-delete-pipeline-sync]]
33+
==== Synchronous Execution
34+
35+
["source","java",subs="attributes,callouts,macros"]
36+
--------------------------------------------------
37+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute]
38+
--------------------------------------------------
39+
<1> Execute the request and get back the response in a `WritePipelineResponse` object.
40+
41+
[[java-rest-high-cluster-delete-pipeline-async]]
42+
==== Asynchronous Execution
43+
44+
The asynchronous execution of a delete pipeline request requires both the `DeletePipelineRequest`
45+
instance and an `ActionListener` instance to be passed to the asynchronous
46+
method:
47+
48+
["source","java",subs="attributes,callouts,macros"]
49+
--------------------------------------------------
50+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute-async]
51+
--------------------------------------------------
52+
<1> The `DeletePipelineRequest` to execute and the `ActionListener` to use when
53+
the execution completes
54+
55+
The asynchronous method does not block and returns immediately. Once it is
56+
completed the `ActionListener` is called back using the `onResponse` method
57+
if the execution successfully completed or using the `onFailure` method if
58+
it failed.
59+
60+
A typical listener for `WritePipelineResponse` looks like:
61+
62+
["source","java",subs="attributes,callouts,macros"]
63+
--------------------------------------------------
64+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-execute-listener]
65+
--------------------------------------------------
66+
<1> Called when the execution is successfully completed. The response is
67+
provided as an argument
68+
<2> Called in case of failure. The raised exception is provided as an argument
69+
70+
[[java-rest-high-cluster-delete-pipeline-response]]
71+
==== Delete Pipeline Response
72+
73+
The returned `WritePipelineResponse` allows to retrieve information about the executed
74+
operation as follows:
75+
76+
["source","java",subs="attributes,callouts,macros"]
77+
--------------------------------------------------
78+
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[delete-pipeline-response]
79+
--------------------------------------------------
80+
<1> Indicates whether all of the nodes have acknowledged the request

docs/java-rest/high-level/cluster/put_pipeline.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ The following arguments can optionally be provided:
2222
--------------------------------------------------
2323
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-request-timeout]
2424
--------------------------------------------------
25-
<1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue`
26-
<2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String`
25+
<1> Timeout to wait for the all the nodes to acknowledge the pipeline creation as a `TimeValue`
26+
<2> Timeout to wait for the all the nodes to acknowledge the pipeline creation as a `String`
2727

2828
["source","java",subs="attributes,callouts,macros"]
2929
--------------------------------------------------
@@ -39,7 +39,7 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-reque
3939
--------------------------------------------------
4040
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-execute]
4141
--------------------------------------------------
42-
<1> Execute the request and get back the response in a PutPipelineResponse object.
42+
<1> Execute the request and get back the response in a WritePipelineResponse object.
4343

4444
[[java-rest-high-cluster-put-pipeline-async]]
4545
==== Asynchronous Execution
@@ -60,7 +60,7 @@ completed the `ActionListener` is called back using the `onResponse` method
6060
if the execution successfully completed or using the `onFailure` method if
6161
it failed.
6262

63-
A typical listener for `PutPipelineResponse` looks like:
63+
A typical listener for `WritePipelineResponse` looks like:
6464

6565
["source","java",subs="attributes,callouts,macros"]
6666
--------------------------------------------------
@@ -73,7 +73,7 @@ provided as an argument
7373
[[java-rest-high-cluster-put-pipeline-response]]
7474
==== Put Pipeline Response
7575

76-
The returned `PutPipelineResponse` allows to retrieve information about the executed
76+
The returned `WritePipelineResponse` allows to retrieve information about the executed
7777
operation as follows:
7878

7979
["source","java",subs="attributes,callouts,macros"]

0 commit comments

Comments
 (0)