Skip to content

Commit 6d01170

Browse files
authored
[HLRC] Added support for CCR Delete Auto Follow Pattern API (#35981)
This change also adds documentation for the Delete Auto Follow Pattern API. Relates to #33824
1 parent 93ed8b7 commit 6d01170

File tree

7 files changed

+204
-12
lines changed

7 files changed

+204
-12
lines changed

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

+51
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.client;
2121

2222
import org.elasticsearch.action.ActionListener;
23+
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
2324
import org.elasticsearch.client.ccr.PauseFollowRequest;
2425
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
2526
import org.elasticsearch.client.ccr.PutFollowRequest;
@@ -77,6 +78,7 @@ public PutFollowResponse putFollow(PutFollowRequest request, RequestOptions opti
7778
*
7879
* @param request the request
7980
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
81+
* @param listener the listener to be notified upon request completion
8082
*/
8183
public void putFollowAsync(PutFollowRequest request,
8284
RequestOptions options,
@@ -120,6 +122,7 @@ public AcknowledgedResponse pauseFollow(PauseFollowRequest request, RequestOptio
120122
*
121123
* @param request the request
122124
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
125+
* @param listener the listener to be notified upon request completion
123126
*/
124127
public void pauseFollowAsync(PauseFollowRequest request,
125128
RequestOptions options,
@@ -162,6 +165,7 @@ public AcknowledgedResponse resumeFollow(ResumeFollowRequest request, RequestOpt
162165
*
163166
* @param request the request
164167
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
168+
* @param listener the listener to be notified upon request completion
165169
*/
166170
public void resumeFollowAsync(ResumeFollowRequest request,
167171
RequestOptions options,
@@ -206,6 +210,7 @@ public AcknowledgedResponse unfollow(UnfollowRequest request, RequestOptions opt
206210
*
207211
* @param request the request
208212
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
213+
* @param listener the listener to be notified upon request completion
209214
*/
210215
public void unfollowAsync(UnfollowRequest request,
211216
RequestOptions options,
@@ -249,6 +254,7 @@ public AcknowledgedResponse putAutoFollowPattern(PutAutoFollowPatternRequest req
249254
*
250255
* @param request the request
251256
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
257+
* @param listener the listener to be notified upon request completion
252258
*/
253259
public void putAutoFollowPatternAsync(PutAutoFollowPatternRequest request,
254260
RequestOptions options,
@@ -262,4 +268,49 @@ public void putAutoFollowPatternAsync(PutAutoFollowPatternRequest request,
262268
Collections.emptySet());
263269
}
264270

271+
/**
272+
* Deletes an auto follow pattern.
273+
*
274+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html">
275+
* the docs</a> for more.
276+
*
277+
* @param request the request
278+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
279+
* @return the response
280+
* @throws IOException in case there is a problem sending the request or parsing back the response
281+
*/
282+
public AcknowledgedResponse deleteAutoFollowPattern(DeleteAutoFollowPatternRequest request,
283+
RequestOptions options) throws IOException {
284+
return restHighLevelClient.performRequestAndParseEntity(
285+
request,
286+
CcrRequestConverters::deleteAutoFollowPattern,
287+
options,
288+
AcknowledgedResponse::fromXContent,
289+
Collections.emptySet()
290+
);
291+
}
292+
293+
/**
294+
* Deletes an auto follow pattern.
295+
*
296+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html">
297+
* the docs</a> for more.
298+
*
299+
* @param request the request
300+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
301+
* @param listener the listener to be notified upon request completion
302+
*/
303+
public void deleteAutoFollowPatternAsync(DeleteAutoFollowPatternRequest request,
304+
RequestOptions options,
305+
ActionListener<AcknowledgedResponse> listener) {
306+
restHighLevelClient.performRequestAsyncAndParseEntity(
307+
request,
308+
CcrRequestConverters::deleteAutoFollowPattern,
309+
options,
310+
AcknowledgedResponse::fromXContent,
311+
listener,
312+
Collections.emptySet()
313+
);
314+
}
315+
265316
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
package org.elasticsearch.client;
2121

22+
import org.apache.http.client.methods.HttpDelete;
2223
import org.apache.http.client.methods.HttpPost;
2324
import org.apache.http.client.methods.HttpPut;
25+
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
2426
import org.elasticsearch.client.ccr.PauseFollowRequest;
2527
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
2628
import org.elasticsearch.client.ccr.PutFollowRequest;
@@ -80,4 +82,12 @@ static Request putAutoFollowPattern(PutAutoFollowPatternRequest putAutoFollowPat
8082
return request;
8183
}
8284

85+
static Request deleteAutoFollowPattern(DeleteAutoFollowPatternRequest deleteAutoFollowPatternRequest) {
86+
String endpoint = new RequestConverters.EndpointBuilder()
87+
.addPathPartAsIs("_ccr", "auto_follow")
88+
.addPathPart(deleteAutoFollowPatternRequest.getName())
89+
.build();
90+
return new Request(HttpDelete.METHOD_NAME, endpoint);
91+
}
92+
8393
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.ccr;
21+
22+
import org.elasticsearch.client.Validatable;
23+
24+
import java.util.Objects;
25+
26+
public final class DeleteAutoFollowPatternRequest implements Validatable {
27+
28+
private final String name;
29+
30+
public DeleteAutoFollowPatternRequest(String name) {
31+
this.name = Objects.requireNonNull(name);
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.action.search.SearchRequest;
3030
import org.elasticsearch.action.search.SearchResponse;
3131
import org.elasticsearch.action.support.WriteRequest;
32+
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
3233
import org.elasticsearch.client.ccr.PauseFollowRequest;
3334
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
3435
import org.elasticsearch.client.ccr.PutFollowRequest;
@@ -148,10 +149,10 @@ public void testAutoFollowing() throws Exception {
148149
});
149150

150151
// Cleanup:
151-
// TODO: replace with hlrc delete auto follow pattern when it is available:
152-
final Request deleteAutoFollowPatternRequest = new Request("DELETE", "/_ccr/auto_follow/pattern1");
153-
Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteAutoFollowPatternRequest));
154-
assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true));
152+
final DeleteAutoFollowPatternRequest deleteAutoFollowPatternRequest = new DeleteAutoFollowPatternRequest("pattern1");
153+
AcknowledgedResponse deleteAutoFollowPatternResponse =
154+
execute(deleteAutoFollowPatternRequest, ccrClient::deleteAutoFollowPattern, ccrClient::deleteAutoFollowPatternAsync);
155+
assertThat(deleteAutoFollowPatternResponse.isAcknowledged(), is(true));
155156

156157
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("copy-logs-20200101");
157158
AcknowledgedResponse pauseFollowResponse = ccrClient.pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);

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

+67-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.client.RequestOptions;
3434
import org.elasticsearch.client.Response;
3535
import org.elasticsearch.client.RestHighLevelClient;
36+
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
3637
import org.elasticsearch.client.ccr.PauseFollowRequest;
3738
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
3839
import org.elasticsearch.client.ccr.PutFollowRequest;
@@ -401,10 +402,9 @@ public void testPutAutoFollowPattern() throws Exception {
401402

402403
// Delete auto follow pattern, so that we can store it again:
403404
{
404-
// TODO: replace with hlrc delete auto follow pattern when it is available:
405-
final Request deleteRequest = new Request("DELETE", "/_ccr/auto_follow/my_pattern");
406-
Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteRequest));
407-
assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true));
405+
final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
406+
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
407+
assertThat(deleteResponse.isAcknowledged(), is(true));
408408
}
409409

410410
// tag::ccr-put-auto-follow-pattern-execute-listener
@@ -435,13 +435,72 @@ public void onFailure(Exception e) {
435435

436436
// Cleanup:
437437
{
438-
// TODO: replace with hlrc delete auto follow pattern when it is available:
439-
final Request deleteRequest = new Request("DELETE", "/_ccr/auto_follow/my_pattern");
440-
Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteRequest));
441-
assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true));
438+
final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
439+
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
440+
assertThat(deleteResponse.isAcknowledged(), is(true));
442441
}
443442
}
444443

444+
public void testDeleteAutoFollowPattern() throws Exception {
445+
RestHighLevelClient client = highLevelClient();
446+
447+
// Put auto follow pattern, so that we can delete it:
448+
{
449+
final PutAutoFollowPatternRequest putRequest =
450+
new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*"));
451+
AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT);
452+
assertThat(putResponse.isAcknowledged(), is(true));
453+
}
454+
455+
// tag::ccr-delete-auto-follow-pattern-request
456+
DeleteAutoFollowPatternRequest request =
457+
new DeleteAutoFollowPatternRequest("my_pattern"); // <1>
458+
// end::ccr-delete-auto-follow-pattern-request
459+
460+
// tag::ccr-delete-auto-follow-pattern-execute
461+
AcknowledgedResponse response = client.ccr()
462+
.deleteAutoFollowPattern(request, RequestOptions.DEFAULT);
463+
// end::ccr-delete-auto-follow-pattern-execute
464+
465+
// tag::ccr-delete-auto-follow-pattern-response
466+
boolean acknowledged = response.isAcknowledged(); // <1>
467+
// end::ccr-delete-auto-follow-pattern-response
468+
469+
// Put auto follow pattern, so that we can delete it again:
470+
{
471+
final PutAutoFollowPatternRequest putRequest =
472+
new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*"));
473+
AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT);
474+
assertThat(putResponse.isAcknowledged(), is(true));
475+
}
476+
477+
// tag::ccr-delete-auto-follow-pattern-execute-listener
478+
ActionListener<AcknowledgedResponse> listener =
479+
new ActionListener<AcknowledgedResponse>() {
480+
@Override
481+
public void onResponse(AcknowledgedResponse response) { // <1>
482+
boolean acknowledged = response.isAcknowledged();
483+
}
484+
485+
@Override
486+
public void onFailure(Exception e) {
487+
// <2>
488+
}
489+
};
490+
// end::ccr-delete-auto-follow-pattern-execute-listener
491+
492+
// Replace the empty listener by a blocking listener in test
493+
final CountDownLatch latch = new CountDownLatch(1);
494+
listener = new LatchedActionListener<>(listener, latch);
495+
496+
// tag::ccr-delete-auto-follow-pattern-execute-async
497+
client.ccr().deleteAutoFollowPatternAsync(request,
498+
RequestOptions.DEFAULT, listener); // <1>
499+
// end::ccr-delete-auto-follow-pattern-execute-async
500+
501+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
502+
}
503+
445504
static Map<String, Object> toMap(Response response) throws IOException {
446505
return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
447506
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--
2+
:api: ccr-delete-auto-follow-pattern
3+
:request: DeleteAutoFollowPatternRequest
4+
:response: AcknowledgedResponse
5+
--
6+
7+
[id="{upid}-{api}"]
8+
=== Delete Auto Follow Pattern API
9+
10+
[id="{upid}-{api}-request"]
11+
==== Request
12+
13+
The Delete Auto Follow Pattern API allows you to delete an auto follow pattern.
14+
15+
["source","java",subs="attributes,callouts,macros"]
16+
--------------------------------------------------
17+
include-tagged::{doc-tests-file}[{api}-request]
18+
--------------------------------------------------
19+
<1> The name of the auto follow pattern to delete.
20+
21+
[id="{upid}-{api}-response"]
22+
==== Response
23+
24+
The returned +{response}+ indicates if the delete auto follow pattern request was received.
25+
26+
["source","java",subs="attributes,callouts,macros"]
27+
--------------------------------------------------
28+
include-tagged::{doc-tests-file}[{api}-response]
29+
--------------------------------------------------
30+
<1> Whether or not the delete auto follow pattern request was acknowledged.
31+
32+
include::../execution.asciidoc[]

docs/java-rest/high-level/supported-apis.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,14 @@ The Java High Level REST Client supports the following CCR APIs:
469469
* <<{upid}-ccr-resume-follow>>
470470
* <<{upid}-ccr-unfollow>>
471471
* <<{upid}-ccr-put-auto-follow-pattern>>
472+
* <<{upid}-ccr-delete-auto-follow-pattern>>
472473

473474
include::ccr/put_follow.asciidoc[]
474475
include::ccr/pause_follow.asciidoc[]
475476
include::ccr/resume_follow.asciidoc[]
476477
include::ccr/unfollow.asciidoc[]
477478
include::ccr/put_auto_follow_pattern.asciidoc[]
479+
include::ccr/delete_auto_follow_pattern.asciidoc[]
478480

479481
== Index Lifecycle Management APIs
480482

0 commit comments

Comments
 (0)