[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
This commit is contained in:
parent
93ed8b7d61
commit
6d01170ca1
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PauseFollowRequest;
|
||||
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PutFollowRequest;
|
||||
|
@ -77,6 +78,7 @@ public final class CcrClient {
|
|||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void putFollowAsync(PutFollowRequest request,
|
||||
RequestOptions options,
|
||||
|
@ -120,6 +122,7 @@ public final class CcrClient {
|
|||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void pauseFollowAsync(PauseFollowRequest request,
|
||||
RequestOptions options,
|
||||
|
@ -162,6 +165,7 @@ public final class CcrClient {
|
|||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void resumeFollowAsync(ResumeFollowRequest request,
|
||||
RequestOptions options,
|
||||
|
@ -206,6 +210,7 @@ public final class CcrClient {
|
|||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void unfollowAsync(UnfollowRequest request,
|
||||
RequestOptions options,
|
||||
|
@ -249,6 +254,7 @@ public final class CcrClient {
|
|||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void putAutoFollowPatternAsync(PutAutoFollowPatternRequest request,
|
||||
RequestOptions options,
|
||||
|
@ -262,4 +268,49 @@ public final class CcrClient {
|
|||
Collections.emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an auto follow pattern.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public AcknowledgedResponse deleteAutoFollowPattern(DeleteAutoFollowPatternRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(
|
||||
request,
|
||||
CcrRequestConverters::deleteAutoFollowPattern,
|
||||
options,
|
||||
AcknowledgedResponse::fromXContent,
|
||||
Collections.emptySet()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an auto follow pattern.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void deleteAutoFollowPatternAsync(DeleteAutoFollowPatternRequest request,
|
||||
RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request,
|
||||
CcrRequestConverters::deleteAutoFollowPattern,
|
||||
options,
|
||||
AcknowledgedResponse::fromXContent,
|
||||
listener,
|
||||
Collections.emptySet()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PauseFollowRequest;
|
||||
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PutFollowRequest;
|
||||
|
@ -80,4 +82,12 @@ final class CcrRequestConverters {
|
|||
return request;
|
||||
}
|
||||
|
||||
static Request deleteAutoFollowPattern(DeleteAutoFollowPatternRequest deleteAutoFollowPatternRequest) {
|
||||
String endpoint = new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_ccr", "auto_follow")
|
||||
.addPathPart(deleteAutoFollowPatternRequest.getName())
|
||||
.build();
|
||||
return new Request(HttpDelete.METHOD_NAME, endpoint);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.ccr;
|
||||
|
||||
import org.elasticsearch.client.Validatable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class DeleteAutoFollowPatternRequest implements Validatable {
|
||||
|
||||
private final String name;
|
||||
|
||||
public DeleteAutoFollowPatternRequest(String name) {
|
||||
this.name = Objects.requireNonNull(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.action.index.IndexRequest;
|
|||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PauseFollowRequest;
|
||||
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PutFollowRequest;
|
||||
|
@ -148,10 +149,10 @@ public class CCRIT extends ESRestHighLevelClientTestCase {
|
|||
});
|
||||
|
||||
// Cleanup:
|
||||
// TODO: replace with hlrc delete auto follow pattern when it is available:
|
||||
final Request deleteAutoFollowPatternRequest = new Request("DELETE", "/_ccr/auto_follow/pattern1");
|
||||
Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteAutoFollowPatternRequest));
|
||||
assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true));
|
||||
final DeleteAutoFollowPatternRequest deleteAutoFollowPatternRequest = new DeleteAutoFollowPatternRequest("pattern1");
|
||||
AcknowledgedResponse deleteAutoFollowPatternResponse =
|
||||
execute(deleteAutoFollowPatternRequest, ccrClient::deleteAutoFollowPattern, ccrClient::deleteAutoFollowPatternAsync);
|
||||
assertThat(deleteAutoFollowPatternResponse.isAcknowledged(), is(true));
|
||||
|
||||
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("copy-logs-20200101");
|
||||
AcknowledgedResponse pauseFollowResponse = ccrClient.pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.client.Request;
|
|||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PauseFollowRequest;
|
||||
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
|
||||
import org.elasticsearch.client.ccr.PutFollowRequest;
|
||||
|
@ -401,10 +402,9 @@ public class CCRDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
// Delete auto follow pattern, so that we can store it again:
|
||||
{
|
||||
// TODO: replace with hlrc delete auto follow pattern when it is available:
|
||||
final Request deleteRequest = new Request("DELETE", "/_ccr/auto_follow/my_pattern");
|
||||
Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteRequest));
|
||||
assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true));
|
||||
final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
|
||||
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
|
||||
assertThat(deleteResponse.isAcknowledged(), is(true));
|
||||
}
|
||||
|
||||
// tag::ccr-put-auto-follow-pattern-execute-listener
|
||||
|
@ -435,13 +435,72 @@ public class CCRDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
// Cleanup:
|
||||
{
|
||||
// TODO: replace with hlrc delete auto follow pattern when it is available:
|
||||
final Request deleteRequest = new Request("DELETE", "/_ccr/auto_follow/my_pattern");
|
||||
Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteRequest));
|
||||
assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true));
|
||||
final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
|
||||
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
|
||||
assertThat(deleteResponse.isAcknowledged(), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteAutoFollowPattern() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
// Put auto follow pattern, so that we can delete it:
|
||||
{
|
||||
final PutAutoFollowPatternRequest putRequest =
|
||||
new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*"));
|
||||
AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT);
|
||||
assertThat(putResponse.isAcknowledged(), is(true));
|
||||
}
|
||||
|
||||
// tag::ccr-delete-auto-follow-pattern-request
|
||||
DeleteAutoFollowPatternRequest request =
|
||||
new DeleteAutoFollowPatternRequest("my_pattern"); // <1>
|
||||
// end::ccr-delete-auto-follow-pattern-request
|
||||
|
||||
// tag::ccr-delete-auto-follow-pattern-execute
|
||||
AcknowledgedResponse response = client.ccr()
|
||||
.deleteAutoFollowPattern(request, RequestOptions.DEFAULT);
|
||||
// end::ccr-delete-auto-follow-pattern-execute
|
||||
|
||||
// tag::ccr-delete-auto-follow-pattern-response
|
||||
boolean acknowledged = response.isAcknowledged(); // <1>
|
||||
// end::ccr-delete-auto-follow-pattern-response
|
||||
|
||||
// Put auto follow pattern, so that we can delete it again:
|
||||
{
|
||||
final PutAutoFollowPatternRequest putRequest =
|
||||
new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*"));
|
||||
AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT);
|
||||
assertThat(putResponse.isAcknowledged(), is(true));
|
||||
}
|
||||
|
||||
// tag::ccr-delete-auto-follow-pattern-execute-listener
|
||||
ActionListener<AcknowledgedResponse> listener =
|
||||
new ActionListener<AcknowledgedResponse>() {
|
||||
@Override
|
||||
public void onResponse(AcknowledgedResponse response) { // <1>
|
||||
boolean acknowledged = response.isAcknowledged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::ccr-delete-auto-follow-pattern-execute-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::ccr-delete-auto-follow-pattern-execute-async
|
||||
client.ccr().deleteAutoFollowPatternAsync(request,
|
||||
RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::ccr-delete-auto-follow-pattern-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
static Map<String, Object> toMap(Response response) throws IOException {
|
||||
return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
--
|
||||
:api: ccr-delete-auto-follow-pattern
|
||||
:request: DeleteAutoFollowPatternRequest
|
||||
:response: AcknowledgedResponse
|
||||
--
|
||||
|
||||
[id="{upid}-{api}"]
|
||||
=== Delete Auto Follow Pattern API
|
||||
|
||||
[id="{upid}-{api}-request"]
|
||||
==== Request
|
||||
|
||||
The Delete Auto Follow Pattern API allows you to delete an auto follow pattern.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests-file}[{api}-request]
|
||||
--------------------------------------------------
|
||||
<1> The name of the auto follow pattern to delete.
|
||||
|
||||
[id="{upid}-{api}-response"]
|
||||
==== Response
|
||||
|
||||
The returned +{response}+ indicates if the delete auto follow pattern request was received.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests-file}[{api}-response]
|
||||
--------------------------------------------------
|
||||
<1> Whether or not the delete auto follow pattern request was acknowledged.
|
||||
|
||||
include::../execution.asciidoc[]
|
|
@ -469,12 +469,14 @@ The Java High Level REST Client supports the following CCR APIs:
|
|||
* <<{upid}-ccr-resume-follow>>
|
||||
* <<{upid}-ccr-unfollow>>
|
||||
* <<{upid}-ccr-put-auto-follow-pattern>>
|
||||
* <<{upid}-ccr-delete-auto-follow-pattern>>
|
||||
|
||||
include::ccr/put_follow.asciidoc[]
|
||||
include::ccr/pause_follow.asciidoc[]
|
||||
include::ccr/resume_follow.asciidoc[]
|
||||
include::ccr/unfollow.asciidoc[]
|
||||
include::ccr/put_auto_follow_pattern.asciidoc[]
|
||||
include::ccr/delete_auto_follow_pattern.asciidoc[]
|
||||
|
||||
== Index Lifecycle Management APIs
|
||||
|
||||
|
|
Loading…
Reference in New Issue