Skip to content

Commit 2891783

Browse files
authored
Add Pause/Resume Auto-Follower APIs to High Level REST Client (#47989)
This commit adds support for Pause/Resume Auto-Follower APIs to the HLRC, with the documentation. Relates #47510
1 parent efc033c commit 2891783

File tree

9 files changed

+407
-0
lines changed

9 files changed

+407
-0
lines changed

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

+88
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
3131
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
3232
import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse;
33+
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
3334
import org.elasticsearch.client.ccr.PauseFollowRequest;
3435
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
3536
import org.elasticsearch.client.ccr.PutFollowRequest;
3637
import org.elasticsearch.client.ccr.PutFollowResponse;
38+
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
3739
import org.elasticsearch.client.ccr.ResumeFollowRequest;
3840
import org.elasticsearch.client.ccr.UnfollowRequest;
3941
import org.elasticsearch.client.core.AcknowledgedResponse;
@@ -410,6 +412,92 @@ public Cancellable getAutoFollowPatternAsync(GetAutoFollowPatternRequest request
410412
);
411413
}
412414

415+
/**
416+
* Pauses an auto follow pattern.
417+
*
418+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-auto-follow-pattern.html">
419+
* the docs</a> for more.
420+
*
421+
* @param request the request
422+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
423+
* @return the response
424+
* @throws IOException in case there is a problem sending the request or parsing back the response
425+
*/
426+
public AcknowledgedResponse pauseAutoFollowPattern(PauseAutoFollowPatternRequest request, RequestOptions options) throws IOException {
427+
return restHighLevelClient.performRequestAndParseEntity(
428+
request,
429+
CcrRequestConverters::pauseAutoFollowPattern,
430+
options,
431+
AcknowledgedResponse::fromXContent,
432+
Collections.emptySet()
433+
);
434+
}
435+
436+
/**
437+
* Asynchronously pauses an auto follow pattern.
438+
*
439+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-auto-follow-pattern.html">
440+
* the docs</a> for more.
441+
* @param request the request
442+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
443+
* @param listener the listener to be notified upon request completion
444+
* @return cancellable that may be used to cancel the request
445+
*/
446+
public Cancellable pauseAutoFollowPatternAsync(PauseAutoFollowPatternRequest request,
447+
RequestOptions options,
448+
ActionListener<AcknowledgedResponse> listener) {
449+
return restHighLevelClient.performRequestAsyncAndParseEntity(
450+
request,
451+
CcrRequestConverters::pauseAutoFollowPattern,
452+
options,
453+
AcknowledgedResponse::fromXContent,
454+
listener,
455+
Collections.emptySet());
456+
}
457+
458+
/**
459+
* Resumes an auto follow pattern.
460+
*
461+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-auto-follow-pattern.html">
462+
* the docs</a> for more.
463+
*
464+
* @param request the request
465+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
466+
* @return the response
467+
* @throws IOException in case there is a problem sending the request or parsing back the response
468+
*/
469+
public AcknowledgedResponse resumeAutoFollowPattern(ResumeAutoFollowPatternRequest request, RequestOptions options) throws IOException {
470+
return restHighLevelClient.performRequestAndParseEntity(
471+
request,
472+
CcrRequestConverters::resumeAutoFollowPattern,
473+
options,
474+
AcknowledgedResponse::fromXContent,
475+
Collections.emptySet()
476+
);
477+
}
478+
479+
/**
480+
* Asynchronously resumes an auto follow pattern.
481+
*
482+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-auto-follow-pattern.html">
483+
* the docs</a> for more.
484+
* @param request the request
485+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
486+
* @param listener the listener to be notified upon request completion
487+
* @return cancellable that may be used to cancel the request
488+
*/
489+
public Cancellable resumeAutoFollowPatternAsync(ResumeAutoFollowPatternRequest request,
490+
RequestOptions options,
491+
ActionListener<AcknowledgedResponse> listener) {
492+
return restHighLevelClient.performRequestAsyncAndParseEntity(
493+
request,
494+
CcrRequestConverters::resumeAutoFollowPattern,
495+
options,
496+
AcknowledgedResponse::fromXContent,
497+
listener,
498+
Collections.emptySet());
499+
}
500+
413501
/**
414502
* Gets all CCR stats.
415503
*

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

+20
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
import org.elasticsearch.client.ccr.FollowStatsRequest;
3030
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
3131
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
32+
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
3233
import org.elasticsearch.client.ccr.PauseFollowRequest;
3334
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
3435
import org.elasticsearch.client.ccr.PutFollowRequest;
36+
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
3537
import org.elasticsearch.client.ccr.ResumeFollowRequest;
3638
import org.elasticsearch.client.ccr.UnfollowRequest;
3739

@@ -118,6 +120,24 @@ static Request getAutoFollowPattern(GetAutoFollowPatternRequest getAutoFollowPat
118120
return new Request(HttpGet.METHOD_NAME, endpoint);
119121
}
120122

123+
static Request pauseAutoFollowPattern(PauseAutoFollowPatternRequest pauseAutoFollowPatternRequest) throws IOException {
124+
String endpoint = new RequestConverters.EndpointBuilder()
125+
.addPathPartAsIs("_ccr", "auto_follow")
126+
.addPathPart(pauseAutoFollowPatternRequest.getName())
127+
.addPathPartAsIs("pause")
128+
.build();
129+
return new Request(HttpPost.METHOD_NAME, endpoint);
130+
}
131+
132+
static Request resumeAutoFollowPattern(ResumeAutoFollowPatternRequest resumeAutoFollowPatternRequest) throws IOException {
133+
String endpoint = new RequestConverters.EndpointBuilder()
134+
.addPathPartAsIs("_ccr", "auto_follow")
135+
.addPathPart(resumeAutoFollowPatternRequest.getName())
136+
.addPathPartAsIs("resume")
137+
.build();
138+
return new Request(HttpPost.METHOD_NAME, endpoint);
139+
}
140+
121141
static Request getCcrStats(CcrStatsRequest ccrStatsRequest) {
122142
String endpoint = new RequestConverters.EndpointBuilder()
123143
.addPathPartAsIs("_ccr", "stats")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
/**
27+
* Request class for pause auto follow pattern api.
28+
*/
29+
public final class PauseAutoFollowPatternRequest implements Validatable {
30+
31+
private final String name;
32+
33+
/**
34+
* Pause auto follow pattern with the specified name
35+
*
36+
* @param name The name of the auto follow pattern to pause
37+
*/
38+
public PauseAutoFollowPatternRequest(String name) {
39+
this.name = Objects.requireNonNull(name);
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
/**
27+
* Request class for resume auto follow pattern api.
28+
*/
29+
public final class ResumeAutoFollowPatternRequest implements Validatable {
30+
31+
private final String name;
32+
33+
/**
34+
* Resume auto follow pattern with the specified name
35+
*
36+
* @param name The name of the auto follow pattern to resume
37+
*/
38+
public ResumeAutoFollowPatternRequest(String name) {
39+
this.name = Objects.requireNonNull(name);
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
}

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

+22
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import org.elasticsearch.client.ccr.FollowStatsRequest;
3232
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
3333
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
34+
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
3435
import org.elasticsearch.client.ccr.PauseFollowRequest;
3536
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
3637
import org.elasticsearch.client.ccr.PutFollowRequest;
38+
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
3739
import org.elasticsearch.client.ccr.ResumeFollowRequest;
3840
import org.elasticsearch.client.ccr.UnfollowRequest;
3941
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -143,6 +145,26 @@ public void testGetAutofollowPattern() throws Exception {
143145
assertThat(result.getEntity(), nullValue());
144146
}
145147

148+
public void testPauseAutofollowPattern() throws Exception {
149+
PauseAutoFollowPatternRequest pauseAutoFollowPatternRequest = new PauseAutoFollowPatternRequest(randomAlphaOfLength(4));
150+
151+
Request result = CcrRequestConverters.pauseAutoFollowPattern(pauseAutoFollowPatternRequest);
152+
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
153+
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + pauseAutoFollowPatternRequest.getName() + "/pause"));
154+
assertThat(result.getParameters().size(), equalTo(0));
155+
assertThat(result.getEntity(), nullValue());
156+
}
157+
158+
public void testResumeAutofollowPattern() throws Exception {
159+
ResumeAutoFollowPatternRequest resumeAutoFollowPatternRequest = new ResumeAutoFollowPatternRequest(randomAlphaOfLength(4));
160+
161+
Request result = CcrRequestConverters.resumeAutoFollowPattern(resumeAutoFollowPatternRequest);
162+
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
163+
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + resumeAutoFollowPatternRequest.getName() + "/resume"));
164+
assertThat(result.getParameters().size(), equalTo(0));
165+
assertThat(result.getEntity(), nullValue());
166+
}
167+
146168
public void testGetCcrStats() throws Exception {
147169
CcrStatsRequest ccrStatsRequest = new CcrStatsRequest();
148170
Request result = CcrRequestConverters.getCcrStats(ccrStatsRequest);

0 commit comments

Comments
 (0)