[PURIFY] remove all trace of x-pack ccr (#11)

This committ removes all trace of Elastic licensed CCR.

Signed-off-by: Peter Nied <petern@amazon.com>
This commit is contained in:
Nick Knize 2021-01-30 00:20:00 -06:00 committed by Peter Nied
parent 479dd4b42a
commit 0dd4f9f281
40 changed files with 2 additions and 5484 deletions

View File

@ -1,631 +0,0 @@
/*
* 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.ActionListener;
import org.elasticsearch.client.ccr.CcrStatsRequest;
import org.elasticsearch.client.ccr.CcrStatsResponse;
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.FollowInfoRequest;
import org.elasticsearch.client.ccr.FollowInfoResponse;
import org.elasticsearch.client.ccr.FollowStatsRequest;
import org.elasticsearch.client.ccr.FollowStatsResponse;
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse;
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseFollowRequest;
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PutFollowRequest;
import org.elasticsearch.client.ccr.PutFollowResponse;
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.ResumeFollowRequest;
import org.elasticsearch.client.ccr.UnfollowRequest;
import org.elasticsearch.client.core.AcknowledgedResponse;
import org.elasticsearch.client.core.BroadcastResponse;
import java.io.IOException;
import java.util.Collections;
/**
* A wrapper for the {@link RestHighLevelClient} that provides methods for
* accessing the Elastic ccr related methods
* <p>
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-apis.html">
* X-Pack Rollup APIs on elastic.co</a> for more information.
*/
public final class CcrClient {
private final RestHighLevelClient restHighLevelClient;
CcrClient(RestHighLevelClient restHighLevelClient) {
this.restHighLevelClient = restHighLevelClient;
}
/**
* Executes the put follow api, which creates a follower index and then the follower index starts following
* the leader index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.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 PutFollowResponse putFollow(PutFollowRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::putFollow,
options,
PutFollowResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously executes the put follow api, which creates a follower index and then the follower index starts
* following the leader index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.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
* @return cancellable that may be used to cancel the request
*/
public Cancellable putFollowAsync(PutFollowRequest request,
RequestOptions options,
ActionListener<PutFollowResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::putFollow,
options,
PutFollowResponse::fromXContent,
listener,
Collections.emptySet()
);
}
/**
* Instructs a follower index to pause the following of a leader index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.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 pauseFollow(PauseFollowRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::pauseFollow,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously instruct a follower index to pause the following of a leader index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.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
* @return cancellable that may be used to cancel the request
*/
public Cancellable pauseFollowAsync(PauseFollowRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::pauseFollow,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}
/**
* Instructs a follower index to resume the following of a leader index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-follow.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 resumeFollow(ResumeFollowRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::resumeFollow,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously instruct a follower index to resume the following of a leader index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-follow.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
* @return cancellable that may be used to cancel the request
*/
public Cancellable resumeFollowAsync(ResumeFollowRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::resumeFollow,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}
/**
* Instructs a follower index to unfollow and become a regular index.
* Note that index following needs to be paused and the follower index needs to be closed.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-unfollow.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 unfollow(UnfollowRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::unfollow,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously instructs a follower index to unfollow and become a regular index.
* Note that index following needs to be paused and the follower index needs to be closed.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-unfollow.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
* @return cancellable that may be used to cancel the request
*/
public Cancellable unfollowAsync(UnfollowRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::unfollow,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet()
);
}
/**
* Instructs an index acting as a leader index to forget the specified follower index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-forget-follower.html">the docs</a> for more details
* on the intended usage of this API.
*
* @param request the request
* @param options the request options (e.g., headers), use {@link RequestOptions#DEFAULT} if the defaults are acceptable.
* @return the response
* @throws IOException if an I/O exception occurs while executing this request
*/
public BroadcastResponse forgetFollower(final ForgetFollowerRequest request, final RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::forgetFollower,
options,
BroadcastResponse::fromXContent,
Collections.emptySet());
}
/**
* Asynchronously instructs an index acting as a leader index to forget the specified follower index.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-forget-follower.html">the docs</a> for more details
* on the intended usage of this API.
* @param request the request
* @param options the request options (e.g., headers), use {@link RequestOptions#DEFAULT} if the defaults are acceptable.
* @return cancellable that may be used to cancel the request
*/
public Cancellable forgetFollowerAsync(
final ForgetFollowerRequest request,
final RequestOptions options,
final ActionListener<BroadcastResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::forgetFollower,
options,
BroadcastResponse::fromXContent,
listener,
Collections.emptySet());
}
/**
* Stores an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-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 putAutoFollowPattern(PutAutoFollowPatternRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::putAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously stores an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-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
* @return cancellable that may be used to cancel the request
*/
public Cancellable putAutoFollowPatternAsync(PutAutoFollowPatternRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::putAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
listener,
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()
);
}
/**
* Asynchronously 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
* @return cancellable that may be used to cancel the request
*/
public Cancellable deleteAutoFollowPatternAsync(DeleteAutoFollowPatternRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::deleteAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet()
);
}
/**
* Gets an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-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 GetAutoFollowPatternResponse getAutoFollowPattern(GetAutoFollowPatternRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::getAutoFollowPattern,
options,
GetAutoFollowPatternResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously gets an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-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
* @return cancellable that may be used to cancel the request
*/
public Cancellable getAutoFollowPatternAsync(GetAutoFollowPatternRequest request,
RequestOptions options,
ActionListener<GetAutoFollowPatternResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::getAutoFollowPattern,
options,
GetAutoFollowPatternResponse::fromXContent,
listener,
Collections.emptySet()
);
}
/**
* Pauses an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-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 pauseAutoFollowPattern(PauseAutoFollowPatternRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::pauseAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously pauses an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-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
* @return cancellable that may be used to cancel the request
*/
public Cancellable pauseAutoFollowPatternAsync(PauseAutoFollowPatternRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::pauseAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}
/**
* Resumes an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-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 resumeAutoFollowPattern(ResumeAutoFollowPatternRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::resumeAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously resumes an auto follow pattern.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-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
* @return cancellable that may be used to cancel the request
*/
public Cancellable resumeAutoFollowPatternAsync(ResumeAutoFollowPatternRequest request,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::resumeAutoFollowPattern,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}
/**
* Gets all CCR stats.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.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 CcrStatsResponse getCcrStats(CcrStatsRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::getCcrStats,
options,
CcrStatsResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously gets all CCR stats.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.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 cancellable that may be used to cancel the request
*/
public Cancellable getCcrStatsAsync(CcrStatsRequest request,
RequestOptions options,
ActionListener<CcrStatsResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::getCcrStats,
options,
CcrStatsResponse::fromXContent,
listener,
Collections.emptySet()
);
}
/**
* Gets follow stats for specific indices.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.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 FollowStatsResponse getFollowStats(FollowStatsRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::getFollowStats,
options,
FollowStatsResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously gets follow stats for specific indices.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.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 cancellable that may be used to cancel the request
*/
public Cancellable getFollowStatsAsync(FollowStatsRequest request,
RequestOptions options,
ActionListener<FollowStatsResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::getFollowStats,
options,
FollowStatsResponse::fromXContent,
listener,
Collections.emptySet()
);
}
/**
* Gets follow info for specific indices.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.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 FollowInfoResponse getFollowInfo(FollowInfoRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
CcrRequestConverters::getFollowInfo,
options,
FollowInfoResponse::fromXContent,
Collections.emptySet()
);
}
/**
* Asynchronously gets follow info for specific indices.
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.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 cancellable that may be used to cancel the request
*/
public Cancellable getFollowInfoAsync(FollowInfoRequest request,
RequestOptions options,
ActionListener<FollowInfoResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
request,
CcrRequestConverters::getFollowInfo,
options,
FollowInfoResponse::fromXContent,
listener,
Collections.emptySet()
);
}
}

View File

@ -1,164 +0,0 @@
/*
* 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.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.client.ccr.CcrStatsRequest;
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.FollowInfoRequest;
import org.elasticsearch.client.ccr.FollowStatsRequest;
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseFollowRequest;
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PutFollowRequest;
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.ResumeFollowRequest;
import org.elasticsearch.client.ccr.UnfollowRequest;
import java.io.IOException;
import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE;
import static org.elasticsearch.client.RequestConverters.createEntity;
final class CcrRequestConverters {
static Request putFollow(PutFollowRequest putFollowRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(putFollowRequest.getFollowerIndex())
.addPathPartAsIs("_ccr", "follow")
.build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withWaitForActiveShards(putFollowRequest.waitForActiveShards());
request.setEntity(createEntity(putFollowRequest, REQUEST_BODY_CONTENT_TYPE));
request.addParameters(parameters.asMap());
return request;
}
static Request pauseFollow(PauseFollowRequest pauseFollowRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(pauseFollowRequest.getFollowerIndex())
.addPathPartAsIs("_ccr", "pause_follow")
.build();
return new Request(HttpPost.METHOD_NAME, endpoint);
}
static Request resumeFollow(ResumeFollowRequest resumeFollowRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(resumeFollowRequest.getFollowerIndex())
.addPathPartAsIs("_ccr", "resume_follow")
.build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
request.setEntity(createEntity(resumeFollowRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
static Request unfollow(UnfollowRequest unfollowRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(unfollowRequest.getFollowerIndex())
.addPathPartAsIs("_ccr", "unfollow")
.build();
return new Request(HttpPost.METHOD_NAME, endpoint);
}
static Request forgetFollower(final ForgetFollowerRequest forgetFollowerRequest) throws IOException {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(forgetFollowerRequest.leaderIndex())
.addPathPartAsIs("_ccr")
.addPathPartAsIs("forget_follower")
.build();
final Request request = new Request(HttpPost.METHOD_NAME, endpoint);
request.setEntity(createEntity(forgetFollowerRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
static Request putAutoFollowPattern(PutAutoFollowPatternRequest putAutoFollowPatternRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_ccr", "auto_follow")
.addPathPart(putAutoFollowPatternRequest.getName())
.build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
request.setEntity(createEntity(putAutoFollowPatternRequest, REQUEST_BODY_CONTENT_TYPE));
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);
}
static Request getAutoFollowPattern(GetAutoFollowPatternRequest getAutoFollowPatternRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_ccr", "auto_follow")
.addPathPart(getAutoFollowPatternRequest.getName())
.build();
return new Request(HttpGet.METHOD_NAME, endpoint);
}
static Request pauseAutoFollowPattern(PauseAutoFollowPatternRequest pauseAutoFollowPatternRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_ccr", "auto_follow")
.addPathPart(pauseAutoFollowPatternRequest.getName())
.addPathPartAsIs("pause")
.build();
return new Request(HttpPost.METHOD_NAME, endpoint);
}
static Request resumeAutoFollowPattern(ResumeAutoFollowPatternRequest resumeAutoFollowPatternRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_ccr", "auto_follow")
.addPathPart(resumeAutoFollowPatternRequest.getName())
.addPathPartAsIs("resume")
.build();
return new Request(HttpPost.METHOD_NAME, endpoint);
}
static Request getCcrStats(CcrStatsRequest ccrStatsRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_ccr", "stats")
.build();
return new Request(HttpGet.METHOD_NAME, endpoint);
}
static Request getFollowStats(FollowStatsRequest followStatsRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(followStatsRequest.getFollowerIndex())
.addPathPartAsIs("_ccr", "stats")
.build();
return new Request(HttpGet.METHOD_NAME, endpoint);
}
static Request getFollowInfo(FollowInfoRequest followInfoRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(followInfoRequest.getFollowerIndex())
.addPathPartAsIs("_ccr", "info")
.build();
return new Request(HttpGet.METHOD_NAME, endpoint);
}
}

View File

@ -269,7 +269,6 @@ public class RestHighLevelClient implements Closeable {
private final SecurityClient securityClient = new SecurityClient(this);
private final IndexLifecycleClient ilmClient = new IndexLifecycleClient(this);
private final RollupClient rollupClient = new RollupClient(this);
private final CcrClient ccrClient = new CcrClient(this);
private final TransformClient transformClient = new TransformClient(this);
/**
@ -364,20 +363,6 @@ public class RestHighLevelClient implements Closeable {
return rollupClient;
}
/**
* Provides methods for accessing the Elastic Licensed CCR APIs that
* are shipped with the Elastic Stack distribution of Elasticsearch. All of
* these APIs will 404 if run against the OSS distribution of Elasticsearch.
* <p>
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-api.html">
* CCR APIs on elastic.co</a> for more information.
*
* @return the client wrapper for making CCR API calls
*/
public final CcrClient ccr() {
return ccrClient;
}
/**
* Provides a {@link TasksClient} which can be used to access the Tasks API.
*

View File

@ -1,157 +0,0 @@
/*
* 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.ElasticsearchException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
public final class AutoFollowStats {
static final ParseField NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED = new ParseField("number_of_successful_follow_indices");
static final ParseField NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED = new ParseField("number_of_failed_follow_indices");
static final ParseField NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS =
new ParseField("number_of_failed_remote_cluster_state_requests");
static final ParseField RECENT_AUTO_FOLLOW_ERRORS = new ParseField("recent_auto_follow_errors");
static final ParseField LEADER_INDEX = new ParseField("leader_index");
static final ParseField TIMESTAMP = new ParseField("timestamp");
static final ParseField AUTO_FOLLOW_EXCEPTION = new ParseField("auto_follow_exception");
static final ParseField AUTO_FOLLOWED_CLUSTERS = new ParseField("auto_followed_clusters");
static final ParseField CLUSTER_NAME = new ParseField("cluster_name");
static final ParseField TIME_SINCE_LAST_CHECK_MILLIS = new ParseField("time_since_last_check_millis");
static final ParseField LAST_SEEN_METADATA_VERSION = new ParseField("last_seen_metadata_version");
@SuppressWarnings("unchecked")
static final ConstructingObjectParser<AutoFollowStats, Void> STATS_PARSER = new ConstructingObjectParser<>(
"auto_follow_stats",
true,
args -> new AutoFollowStats(
(Long) args[0],
(Long) args[1],
(Long) args[2],
new TreeMap<>(
((List<Map.Entry<String, Tuple<Long, ElasticsearchException>>>) args[3])
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))),
new TreeMap<>(
((List<Map.Entry<String, AutoFollowedCluster>>) args[4])
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
));
static final ConstructingObjectParser<Map.Entry<String, Tuple<Long, ElasticsearchException>>, Void> AUTO_FOLLOW_EXCEPTIONS_PARSER =
new ConstructingObjectParser<>(
"auto_follow_stats_errors",
true,
args -> new AbstractMap.SimpleEntry<>((String) args[0], Tuple.tuple((Long) args[1], (ElasticsearchException) args[2])));
private static final ConstructingObjectParser<Map.Entry<String, AutoFollowedCluster>, Void> AUTO_FOLLOWED_CLUSTERS_PARSER =
new ConstructingObjectParser<>(
"auto_followed_clusters",
true,
args -> new AbstractMap.SimpleEntry<>((String) args[0], new AutoFollowedCluster((Long) args[1], (Long) args[2])));
static {
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX);
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), TIMESTAMP);
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareObject(
ConstructingObjectParser.constructorArg(),
(p, c) -> ElasticsearchException.fromXContent(p),
AUTO_FOLLOW_EXCEPTION);
AUTO_FOLLOWED_CLUSTERS_PARSER.declareString(ConstructingObjectParser.constructorArg(), CLUSTER_NAME);
AUTO_FOLLOWED_CLUSTERS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), TIME_SINCE_LAST_CHECK_MILLIS);
AUTO_FOLLOWED_CLUSTERS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), LAST_SEEN_METADATA_VERSION);
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED);
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS);
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED);
STATS_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AUTO_FOLLOW_EXCEPTIONS_PARSER,
RECENT_AUTO_FOLLOW_ERRORS);
STATS_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AUTO_FOLLOWED_CLUSTERS_PARSER,
AUTO_FOLLOWED_CLUSTERS);
}
private final long numberOfFailedFollowIndices;
private final long numberOfFailedRemoteClusterStateRequests;
private final long numberOfSuccessfulFollowIndices;
private final NavigableMap<String, Tuple<Long, ElasticsearchException>> recentAutoFollowErrors;
private final NavigableMap<String, AutoFollowedCluster> autoFollowedClusters;
AutoFollowStats(long numberOfFailedFollowIndices,
long numberOfFailedRemoteClusterStateRequests,
long numberOfSuccessfulFollowIndices,
NavigableMap<String, Tuple<Long, ElasticsearchException>> recentAutoFollowErrors,
NavigableMap<String, AutoFollowedCluster> autoFollowedClusters) {
this.numberOfFailedFollowIndices = numberOfFailedFollowIndices;
this.numberOfFailedRemoteClusterStateRequests = numberOfFailedRemoteClusterStateRequests;
this.numberOfSuccessfulFollowIndices = numberOfSuccessfulFollowIndices;
this.recentAutoFollowErrors = recentAutoFollowErrors;
this.autoFollowedClusters = autoFollowedClusters;
}
public long getNumberOfFailedFollowIndices() {
return numberOfFailedFollowIndices;
}
public long getNumberOfFailedRemoteClusterStateRequests() {
return numberOfFailedRemoteClusterStateRequests;
}
public long getNumberOfSuccessfulFollowIndices() {
return numberOfSuccessfulFollowIndices;
}
public NavigableMap<String, Tuple<Long, ElasticsearchException>> getRecentAutoFollowErrors() {
return recentAutoFollowErrors;
}
public NavigableMap<String, AutoFollowedCluster> getAutoFollowedClusters() {
return autoFollowedClusters;
}
public static class AutoFollowedCluster {
private final long timeSinceLastCheckMillis;
private final long lastSeenMetadataVersion;
public AutoFollowedCluster(long timeSinceLastCheckMillis, long lastSeenMetadataVersion) {
this.timeSinceLastCheckMillis = timeSinceLastCheckMillis;
this.lastSeenMetadataVersion = lastSeenMetadataVersion;
}
public long getTimeSinceLastCheckMillis() {
return timeSinceLastCheckMillis;
}
public long getLastSeenMetadataVersion() {
return lastSeenMetadataVersion;
}
}
}

View File

@ -1,25 +0,0 @@
/*
* 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;
public final class CcrStatsRequest implements Validatable {
}

View File

@ -1,64 +0,0 @@
/*
* 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.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
public final class CcrStatsResponse {
static final ParseField AUTO_FOLLOW_STATS_FIELD = new ParseField("auto_follow_stats");
static final ParseField FOLLOW_STATS_FIELD = new ParseField("follow_stats");
private static final ConstructingObjectParser<CcrStatsResponse, Void> PARSER = new ConstructingObjectParser<>(
"indices",
true,
args -> {
AutoFollowStats autoFollowStats = (AutoFollowStats) args[0];
IndicesFollowStats indicesFollowStats = (IndicesFollowStats) args[1];
return new CcrStatsResponse(autoFollowStats, indicesFollowStats);
});
static {
PARSER.declareObject(ConstructingObjectParser.constructorArg(), AutoFollowStats.STATS_PARSER, AUTO_FOLLOW_STATS_FIELD);
PARSER.declareObject(ConstructingObjectParser.constructorArg(), IndicesFollowStats.PARSER, FOLLOW_STATS_FIELD);
}
public static CcrStatsResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
private final AutoFollowStats autoFollowStats;
private final IndicesFollowStats indicesFollowStats;
public CcrStatsResponse(AutoFollowStats autoFollowStats, IndicesFollowStats indicesFollowStats) {
this.autoFollowStats = autoFollowStats;
this.indicesFollowStats = indicesFollowStats;
}
public AutoFollowStats getAutoFollowStats() {
return autoFollowStats;
}
public IndicesFollowStats getIndicesFollowStats() {
return indicesFollowStats;
}
}

View File

@ -1,37 +0,0 @@
/*
* 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;
}
}

View File

@ -1,262 +0,0 @@
/*
* 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.common.ParseField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Objects;
public class FollowConfig {
static final ParseField SETTINGS = new ParseField("settings");
static final ParseField MAX_READ_REQUEST_OPERATION_COUNT = new ParseField("max_read_request_operation_count");
static final ParseField MAX_READ_REQUEST_SIZE = new ParseField("max_read_request_size");
static final ParseField MAX_OUTSTANDING_READ_REQUESTS = new ParseField("max_outstanding_read_requests");
static final ParseField MAX_WRITE_REQUEST_OPERATION_COUNT = new ParseField("max_write_request_operation_count");
static final ParseField MAX_WRITE_REQUEST_SIZE = new ParseField("max_write_request_size");
static final ParseField MAX_OUTSTANDING_WRITE_REQUESTS = new ParseField("max_outstanding_write_requests");
static final ParseField MAX_WRITE_BUFFER_COUNT = new ParseField("max_write_buffer_count");
static final ParseField MAX_WRITE_BUFFER_SIZE = new ParseField("max_write_buffer_size");
static final ParseField MAX_RETRY_DELAY_FIELD = new ParseField("max_retry_delay");
static final ParseField READ_POLL_TIMEOUT = new ParseField("read_poll_timeout");
private static final ObjectParser<FollowConfig, Void> PARSER = new ObjectParser<>(
"follow_config",
true,
FollowConfig::new);
static {
PARSER.declareObject(FollowConfig::setSettings, (p, c) -> Settings.fromXContent(p), SETTINGS);
PARSER.declareInt(FollowConfig::setMaxReadRequestOperationCount, MAX_READ_REQUEST_OPERATION_COUNT);
PARSER.declareInt(FollowConfig::setMaxOutstandingReadRequests, MAX_OUTSTANDING_READ_REQUESTS);
PARSER.declareField(
FollowConfig::setMaxReadRequestSize,
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_READ_REQUEST_SIZE.getPreferredName()),
MAX_READ_REQUEST_SIZE,
ObjectParser.ValueType.STRING);
PARSER.declareInt(FollowConfig::setMaxWriteRequestOperationCount, MAX_WRITE_REQUEST_OPERATION_COUNT);
PARSER.declareField(
FollowConfig::setMaxWriteRequestSize,
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_REQUEST_SIZE.getPreferredName()),
MAX_WRITE_REQUEST_SIZE,
ObjectParser.ValueType.STRING);
PARSER.declareInt(FollowConfig::setMaxOutstandingWriteRequests, MAX_OUTSTANDING_WRITE_REQUESTS);
PARSER.declareInt(FollowConfig::setMaxWriteBufferCount, MAX_WRITE_BUFFER_COUNT);
PARSER.declareField(
FollowConfig::setMaxWriteBufferSize,
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_WRITE_BUFFER_SIZE.getPreferredName()),
MAX_WRITE_BUFFER_SIZE,
ObjectParser.ValueType.STRING);
PARSER.declareField(FollowConfig::setMaxRetryDelay,
(p, c) -> TimeValue.parseTimeValue(p.text(), MAX_RETRY_DELAY_FIELD.getPreferredName()),
MAX_RETRY_DELAY_FIELD, ObjectParser.ValueType.STRING);
PARSER.declareField(FollowConfig::setReadPollTimeout,
(p, c) -> TimeValue.parseTimeValue(p.text(), READ_POLL_TIMEOUT.getPreferredName()),
READ_POLL_TIMEOUT, ObjectParser.ValueType.STRING);
}
static FollowConfig fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
private Settings settings = Settings.EMPTY;
private Integer maxReadRequestOperationCount;
private Integer maxOutstandingReadRequests;
private ByteSizeValue maxReadRequestSize;
private Integer maxWriteRequestOperationCount;
private ByteSizeValue maxWriteRequestSize;
private Integer maxOutstandingWriteRequests;
private Integer maxWriteBufferCount;
private ByteSizeValue maxWriteBufferSize;
private TimeValue maxRetryDelay;
private TimeValue readPollTimeout;
FollowConfig() {
}
public Settings getSettings() {
return settings;
}
public void setSettings(final Settings settings) {
this.settings = Objects.requireNonNull(settings);
}
public Integer getMaxReadRequestOperationCount() {
return maxReadRequestOperationCount;
}
public void setMaxReadRequestOperationCount(Integer maxReadRequestOperationCount) {
this.maxReadRequestOperationCount = maxReadRequestOperationCount;
}
public Integer getMaxOutstandingReadRequests() {
return maxOutstandingReadRequests;
}
public void setMaxOutstandingReadRequests(Integer maxOutstandingReadRequests) {
this.maxOutstandingReadRequests = maxOutstandingReadRequests;
}
public ByteSizeValue getMaxReadRequestSize() {
return maxReadRequestSize;
}
public void setMaxReadRequestSize(ByteSizeValue maxReadRequestSize) {
this.maxReadRequestSize = maxReadRequestSize;
}
public Integer getMaxWriteRequestOperationCount() {
return maxWriteRequestOperationCount;
}
public void setMaxWriteRequestOperationCount(Integer maxWriteRequestOperationCount) {
this.maxWriteRequestOperationCount = maxWriteRequestOperationCount;
}
public ByteSizeValue getMaxWriteRequestSize() {
return maxWriteRequestSize;
}
public void setMaxWriteRequestSize(ByteSizeValue maxWriteRequestSize) {
this.maxWriteRequestSize = maxWriteRequestSize;
}
public Integer getMaxOutstandingWriteRequests() {
return maxOutstandingWriteRequests;
}
public void setMaxOutstandingWriteRequests(Integer maxOutstandingWriteRequests) {
this.maxOutstandingWriteRequests = maxOutstandingWriteRequests;
}
public Integer getMaxWriteBufferCount() {
return maxWriteBufferCount;
}
public void setMaxWriteBufferCount(Integer maxWriteBufferCount) {
this.maxWriteBufferCount = maxWriteBufferCount;
}
public ByteSizeValue getMaxWriteBufferSize() {
return maxWriteBufferSize;
}
public void setMaxWriteBufferSize(ByteSizeValue maxWriteBufferSize) {
this.maxWriteBufferSize = maxWriteBufferSize;
}
public TimeValue getMaxRetryDelay() {
return maxRetryDelay;
}
public void setMaxRetryDelay(TimeValue maxRetryDelay) {
this.maxRetryDelay = maxRetryDelay;
}
public TimeValue getReadPollTimeout() {
return readPollTimeout;
}
public void setReadPollTimeout(TimeValue readPollTimeout) {
this.readPollTimeout = readPollTimeout;
}
void toXContentFragment(XContentBuilder builder, ToXContent.Params params) throws IOException {
if (settings.isEmpty() == false) {
builder.startObject(SETTINGS.getPreferredName());
{
settings.toXContent(builder, params);
}
builder.endObject();
}
if (maxReadRequestOperationCount != null) {
builder.field(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName(), maxReadRequestOperationCount);
}
if (maxReadRequestSize != null) {
builder.field(MAX_READ_REQUEST_SIZE.getPreferredName(), maxReadRequestSize.getStringRep());
}
if (maxWriteRequestOperationCount != null) {
builder.field(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName(), maxWriteRequestOperationCount);
}
if (maxWriteRequestSize != null) {
builder.field(MAX_WRITE_REQUEST_SIZE.getPreferredName(), maxWriteRequestSize.getStringRep());
}
if (maxWriteBufferCount != null) {
builder.field(MAX_WRITE_BUFFER_COUNT.getPreferredName(), maxWriteBufferCount);
}
if (maxWriteBufferSize != null) {
builder.field(MAX_WRITE_BUFFER_SIZE.getPreferredName(), maxWriteBufferSize.getStringRep());
}
if (maxOutstandingReadRequests != null) {
builder.field(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName(), maxOutstandingReadRequests);
}
if (maxOutstandingWriteRequests != null) {
builder.field(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName(), maxOutstandingWriteRequests);
}
if (maxRetryDelay != null) {
builder.field(MAX_RETRY_DELAY_FIELD.getPreferredName(), maxRetryDelay.getStringRep());
}
if (readPollTimeout != null) {
builder.field(READ_POLL_TIMEOUT.getPreferredName(), readPollTimeout.getStringRep());
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FollowConfig that = (FollowConfig) o;
return Objects.equals(maxReadRequestOperationCount, that.maxReadRequestOperationCount) &&
Objects.equals(maxOutstandingReadRequests, that.maxOutstandingReadRequests) &&
Objects.equals(maxReadRequestSize, that.maxReadRequestSize) &&
Objects.equals(maxWriteRequestOperationCount, that.maxWriteRequestOperationCount) &&
Objects.equals(maxWriteRequestSize, that.maxWriteRequestSize) &&
Objects.equals(maxOutstandingWriteRequests, that.maxOutstandingWriteRequests) &&
Objects.equals(maxWriteBufferCount, that.maxWriteBufferCount) &&
Objects.equals(maxWriteBufferSize, that.maxWriteBufferSize) &&
Objects.equals(maxRetryDelay, that.maxRetryDelay) &&
Objects.equals(readPollTimeout, that.readPollTimeout);
}
@Override
public int hashCode() {
return Objects.hash(
maxReadRequestOperationCount,
maxOutstandingReadRequests,
maxReadRequestSize,
maxWriteRequestOperationCount,
maxWriteRequestSize,
maxOutstandingWriteRequests,
maxWriteBufferCount,
maxWriteBufferSize,
maxRetryDelay,
readPollTimeout
);
}
}

View File

@ -1,37 +0,0 @@
/*
* 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 FollowInfoRequest implements Validatable {
private final String followerIndex;
public FollowInfoRequest(String followerIndex) {
this.followerIndex = Objects.requireNonNull(followerIndex);
}
public String getFollowerIndex() {
return followerIndex;
}
}

View File

@ -1,178 +0,0 @@
/*
* 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.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
import java.util.List;
import java.util.Objects;
public final class FollowInfoResponse {
static final ParseField FOLLOWER_INDICES_FIELD = new ParseField("follower_indices");
private static final ConstructingObjectParser<FollowInfoResponse, Void> PARSER = new ConstructingObjectParser<>(
"indices",
true,
args -> {
@SuppressWarnings("unchecked")
List<FollowerInfo> infos = (List<FollowerInfo>) args[0];
return new FollowInfoResponse(infos);
});
static {
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), FollowerInfo.PARSER, FOLLOWER_INDICES_FIELD);
}
public static FollowInfoResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
private final List<FollowerInfo> infos;
FollowInfoResponse(List<FollowerInfo> infos) {
this.infos = infos;
}
public List<FollowerInfo> getInfos() {
return infos;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FollowInfoResponse that = (FollowInfoResponse) o;
return infos.equals(that.infos);
}
@Override
public int hashCode() {
return Objects.hash(infos);
}
public static final class FollowerInfo {
static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index");
static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster");
static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index");
static final ParseField STATUS_FIELD = new ParseField("status");
static final ParseField PARAMETERS_FIELD = new ParseField("parameters");
private static final ConstructingObjectParser<FollowerInfo, Void> PARSER = new ConstructingObjectParser<>(
"follower_info",
true,
args -> {
return new FollowerInfo((String) args[0], (String) args[1], (String) args[2],
Status.fromString((String) args[3]), (FollowConfig) args[4]);
});
static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), FOLLOWER_INDEX_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), REMOTE_CLUSTER_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), STATUS_FIELD);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> FollowConfig.fromXContent(p), PARAMETERS_FIELD);
}
private final String followerIndex;
private final String remoteCluster;
private final String leaderIndex;
private final Status status;
private final FollowConfig parameters;
FollowerInfo(String followerIndex, String remoteCluster, String leaderIndex, Status status,
FollowConfig parameters) {
this.followerIndex = followerIndex;
this.remoteCluster = remoteCluster;
this.leaderIndex = leaderIndex;
this.status = status;
this.parameters = parameters;
}
public String getFollowerIndex() {
return followerIndex;
}
public String getRemoteCluster() {
return remoteCluster;
}
public String getLeaderIndex() {
return leaderIndex;
}
public Status getStatus() {
return status;
}
public FollowConfig getParameters() {
return parameters;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FollowerInfo that = (FollowerInfo) o;
return Objects.equals(followerIndex, that.followerIndex) &&
Objects.equals(remoteCluster, that.remoteCluster) &&
Objects.equals(leaderIndex, that.leaderIndex) &&
status == that.status &&
Objects.equals(parameters, that.parameters);
}
@Override
public int hashCode() {
return Objects.hash(followerIndex, remoteCluster, leaderIndex, status, parameters);
}
}
public enum Status {
ACTIVE("active"),
PAUSED("paused");
private final String name;
Status(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static Status fromString(String value) {
switch (value) {
case "active":
return Status.ACTIVE;
case "paused":
return Status.PAUSED;
default:
throw new IllegalArgumentException("unexpected status value [" + value + "]");
}
}
}
}

View File

@ -1,37 +0,0 @@
/*
* 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 FollowStatsRequest implements Validatable {
private final String followerIndex;
public FollowStatsRequest(String followerIndex) {
this.followerIndex = Objects.requireNonNull(followerIndex);
}
public String getFollowerIndex() {
return followerIndex;
}
}

View File

@ -1,39 +0,0 @@
/*
* 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.common.xcontent.XContentParser;
public final class FollowStatsResponse {
public static FollowStatsResponse fromXContent(XContentParser parser) {
return new FollowStatsResponse(IndicesFollowStats.PARSER.apply(parser, null));
}
private final IndicesFollowStats indicesFollowStats;
public FollowStatsResponse(IndicesFollowStats indicesFollowStats) {
this.indicesFollowStats = indicesFollowStats;
}
public IndicesFollowStats getIndicesFollowStats() {
return indicesFollowStats;
}
}

View File

@ -1,89 +0,0 @@
/*
* 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 org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Objects;
/**
* Represents a forget follower request. Note that this an expert API intended to be used only when unfollowing a follower index fails to
* remove the follower retention leases. Please be sure that you understand the purpose this API before using.
*/
public final class ForgetFollowerRequest implements ToXContentObject, Validatable {
private final String followerCluster;
private final String followerIndex;
private final String followerIndexUUID;
private final String leaderRemoteCluster;
private final String leaderIndex;
/**
* The name of the leader index.
*
* @return the name of the leader index
*/
public String leaderIndex() {
return leaderIndex;
}
/**
* Construct a forget follower request.
*
* @param followerCluster the name of the cluster containing the follower index to forget
* @param followerIndex the name of follower index
* @param followerIndexUUID the UUID of the follower index
* @param leaderRemoteCluster the alias of the remote cluster containing the leader index from the perspective of the follower index
* @param leaderIndex the name of the leader index
*/
public ForgetFollowerRequest(
final String followerCluster,
final String followerIndex,
final String followerIndexUUID,
final String leaderRemoteCluster,
final String leaderIndex) {
this.followerCluster = Objects.requireNonNull(followerCluster);
this.followerIndex = Objects.requireNonNull(followerIndex);
this.followerIndexUUID = Objects.requireNonNull(followerIndexUUID);
this.leaderRemoteCluster = Objects.requireNonNull(leaderRemoteCluster);
this.leaderIndex = Objects.requireNonNull(leaderIndex);
}
@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
builder.startObject();
{
builder.field("follower_cluster", followerCluster);
builder.field("follower_index", followerIndex);
builder.field("follower_index_uuid", followerIndexUUID);
builder.field("leader_remote_cluster", leaderRemoteCluster);
}
builder.endObject();
return builder;
}
}

View File

@ -1,52 +0,0 @@
/*
* 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;
/**
* Request class for get auto follow pattern api.
*/
public final class GetAutoFollowPatternRequest implements Validatable {
private final String name;
/**
* Get all auto follow patterns
*/
public GetAutoFollowPatternRequest() {
this.name = null;
}
/**
* Get auto follow pattern with the specified name
*
* @param name The name of the auto follow pattern to get
*/
public GetAutoFollowPatternRequest(String name) {
this.name = Objects.requireNonNull(name);
}
public String getName() {
return name;
}
}

View File

@ -1,179 +0,0 @@
/*
* 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.common.ParseField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects;
import java.util.TreeMap;
import java.util.stream.Collectors;
public final class GetAutoFollowPatternResponse {
static final ParseField PATTERNS_FIELD = new ParseField("patterns");
static final ParseField NAME_FIELD = new ParseField("name");
static final ParseField PATTERN_FIELD = new ParseField("pattern");
private static final ConstructingObjectParser<Map.Entry<String, Pattern>, Void> ENTRY_PARSER = new ConstructingObjectParser<>(
"get_auto_follow_pattern_response", true, args -> new AbstractMap.SimpleEntry<>((String) args[0], (Pattern) args[1]));
static {
ENTRY_PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME_FIELD);
ENTRY_PARSER.declareObject(ConstructingObjectParser.constructorArg(), Pattern.PARSER, PATTERN_FIELD);
}
private static final ConstructingObjectParser<GetAutoFollowPatternResponse, Void> PARSER = new ConstructingObjectParser<>(
"get_auto_follow_pattern_response", true, args -> {
@SuppressWarnings("unchecked")
List<Map.Entry<String, Pattern>> entries = (List<Map.Entry<String, Pattern>>) args[0];
return new GetAutoFollowPatternResponse(new TreeMap<>(entries.stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))));
});
static {
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), ENTRY_PARSER, PATTERNS_FIELD);
}
public static GetAutoFollowPatternResponse fromXContent(final XContentParser parser) {
return PARSER.apply(parser, null);
}
private final NavigableMap<String, Pattern> patterns;
GetAutoFollowPatternResponse(NavigableMap<String, Pattern> patterns) {
this.patterns = Collections.unmodifiableNavigableMap(patterns);
}
public NavigableMap<String, Pattern> getPatterns() {
return patterns;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GetAutoFollowPatternResponse that = (GetAutoFollowPatternResponse) o;
return Objects.equals(patterns, that.patterns);
}
@Override
public int hashCode() {
return Objects.hash(patterns);
}
public static class Pattern extends FollowConfig {
@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Pattern, Void> PARSER = new ConstructingObjectParser<>(
"pattern", true, args -> new Pattern((String) args[0], (List<String>) args[1], (String) args[2]));
static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), PutFollowRequest.REMOTE_CLUSTER_FIELD);
PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), PutAutoFollowPatternRequest.LEADER_PATTERNS_FIELD);
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), PutAutoFollowPatternRequest.FOLLOW_PATTERN_FIELD);
PARSER.declareObject(Pattern::setSettings, (p, c) -> Settings.fromXContent(p), PutAutoFollowPatternRequest.SETTINGS);
PARSER.declareInt(Pattern::setMaxReadRequestOperationCount, FollowConfig.MAX_READ_REQUEST_OPERATION_COUNT);
PARSER.declareField(
Pattern::setMaxReadRequestSize,
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), FollowConfig.MAX_READ_REQUEST_SIZE.getPreferredName()),
PutFollowRequest.MAX_READ_REQUEST_SIZE,
ObjectParser.ValueType.STRING);
PARSER.declareInt(Pattern::setMaxOutstandingReadRequests, FollowConfig.MAX_OUTSTANDING_READ_REQUESTS);
PARSER.declareInt(Pattern::setMaxWriteRequestOperationCount, FollowConfig.MAX_WRITE_REQUEST_OPERATION_COUNT);
PARSER.declareField(
Pattern::setMaxWriteRequestSize,
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), FollowConfig.MAX_WRITE_REQUEST_SIZE.getPreferredName()),
PutFollowRequest.MAX_WRITE_REQUEST_SIZE,
ObjectParser.ValueType.STRING);
PARSER.declareInt(Pattern::setMaxOutstandingWriteRequests, FollowConfig.MAX_OUTSTANDING_WRITE_REQUESTS);
PARSER.declareInt(Pattern::setMaxWriteBufferCount, FollowConfig.MAX_WRITE_BUFFER_COUNT);
PARSER.declareField(
Pattern::setMaxWriteBufferSize,
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), FollowConfig.MAX_WRITE_BUFFER_SIZE.getPreferredName()),
PutFollowRequest.MAX_WRITE_BUFFER_SIZE,
ObjectParser.ValueType.STRING);
PARSER.declareField(
Pattern::setMaxRetryDelay,
(p, c) -> TimeValue.parseTimeValue(p.text(), FollowConfig.MAX_RETRY_DELAY_FIELD.getPreferredName()),
PutFollowRequest.MAX_RETRY_DELAY_FIELD,
ObjectParser.ValueType.STRING);
PARSER.declareField(
Pattern::setReadPollTimeout,
(p, c) -> TimeValue.parseTimeValue(p.text(), FollowConfig.READ_POLL_TIMEOUT.getPreferredName()),
PutFollowRequest.READ_POLL_TIMEOUT,
ObjectParser.ValueType.STRING);
}
private final String remoteCluster;
private final List<String> leaderIndexPatterns;
private final String followIndexNamePattern;
Pattern(String remoteCluster, List<String> leaderIndexPatterns, String followIndexNamePattern) {
this.remoteCluster = remoteCluster;
this.leaderIndexPatterns = leaderIndexPatterns;
this.followIndexNamePattern = followIndexNamePattern;
}
public String getRemoteCluster() {
return remoteCluster;
}
public List<String> getLeaderIndexPatterns() {
return leaderIndexPatterns;
}
public String getFollowIndexNamePattern() {
return followIndexNamePattern;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Pattern pattern = (Pattern) o;
return Objects.equals(remoteCluster, pattern.remoteCluster) &&
Objects.equals(leaderIndexPatterns, pattern.leaderIndexPatterns) &&
Objects.equals(followIndexNamePattern, pattern.followIndexNamePattern);
}
@Override
public int hashCode() {
return Objects.hash(
super.hashCode(),
remoteCluster,
leaderIndexPatterns,
followIndexNamePattern
);
}
}
}

View File

@ -1,418 +0,0 @@
/*
* 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.ElasticsearchException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
public final class IndicesFollowStats {
static final ParseField INDICES_FIELD = new ParseField("indices");
static final ParseField INDEX_FIELD = new ParseField("index");
static final ParseField SHARDS_FIELD = new ParseField("shards");
private static final ConstructingObjectParser<Tuple<String, List<ShardFollowStats>>, Void> ENTRY_PARSER =
new ConstructingObjectParser<>(
"entry",
true,
args -> {
String index = (String) args[0];
@SuppressWarnings("unchecked")
List<ShardFollowStats> shardFollowStats = (List<ShardFollowStats>) args[1];
return new Tuple<>(index, shardFollowStats);
}
);
static {
ENTRY_PARSER.declareString(ConstructingObjectParser.constructorArg(), INDEX_FIELD);
ENTRY_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), ShardFollowStats.PARSER, SHARDS_FIELD);
}
static final ConstructingObjectParser<IndicesFollowStats, Void> PARSER = new ConstructingObjectParser<>(
"indices",
true,
args -> {
@SuppressWarnings("unchecked")
List<Tuple<String, List<ShardFollowStats>>> entries = (List<Tuple<String, List<ShardFollowStats>>>) args[0];
Map<String, List<ShardFollowStats>> shardFollowStats = entries.stream().collect(Collectors.toMap(Tuple::v1, Tuple::v2));
return new IndicesFollowStats(new TreeMap<>(shardFollowStats));
});
static {
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), ENTRY_PARSER, INDICES_FIELD);
}
private final NavigableMap<String, List<ShardFollowStats>> shardFollowStats;
IndicesFollowStats(NavigableMap<String, List<ShardFollowStats>> shardFollowStats) {
this.shardFollowStats = Collections.unmodifiableNavigableMap(shardFollowStats);
}
public List<ShardFollowStats> getShardFollowStats(String index) {
return shardFollowStats.get(index);
}
public Map<String, List<ShardFollowStats>> getShardFollowStats() {
return shardFollowStats;
}
public static final class ShardFollowStats {
static final ParseField LEADER_CLUSTER = new ParseField("remote_cluster");
static final ParseField LEADER_INDEX = new ParseField("leader_index");
static final ParseField FOLLOWER_INDEX = new ParseField("follower_index");
static final ParseField SHARD_ID = new ParseField("shard_id");
static final ParseField LEADER_GLOBAL_CHECKPOINT_FIELD = new ParseField("leader_global_checkpoint");
static final ParseField LEADER_MAX_SEQ_NO_FIELD = new ParseField("leader_max_seq_no");
static final ParseField FOLLOWER_GLOBAL_CHECKPOINT_FIELD = new ParseField("follower_global_checkpoint");
static final ParseField FOLLOWER_MAX_SEQ_NO_FIELD = new ParseField("follower_max_seq_no");
static final ParseField LAST_REQUESTED_SEQ_NO_FIELD = new ParseField("last_requested_seq_no");
static final ParseField OUTSTANDING_READ_REQUESTS = new ParseField("outstanding_read_requests");
static final ParseField OUTSTANDING_WRITE_REQUESTS = new ParseField("outstanding_write_requests");
static final ParseField WRITE_BUFFER_OPERATION_COUNT_FIELD = new ParseField("write_buffer_operation_count");
static final ParseField WRITE_BUFFER_SIZE_IN_BYTES_FIELD = new ParseField("write_buffer_size_in_bytes");
static final ParseField FOLLOWER_MAPPING_VERSION_FIELD = new ParseField("follower_mapping_version");
static final ParseField FOLLOWER_SETTINGS_VERSION_FIELD = new ParseField("follower_settings_version");
static final ParseField FOLLOWER_ALIASES_VERSION_FIELD = new ParseField("follower_aliases_version");
static final ParseField TOTAL_READ_TIME_MILLIS_FIELD = new ParseField("total_read_time_millis");
static final ParseField TOTAL_READ_REMOTE_EXEC_TIME_MILLIS_FIELD = new ParseField("total_read_remote_exec_time_millis");
static final ParseField SUCCESSFUL_READ_REQUESTS_FIELD = new ParseField("successful_read_requests");
static final ParseField FAILED_READ_REQUESTS_FIELD = new ParseField("failed_read_requests");
static final ParseField OPERATIONS_READ_FIELD = new ParseField("operations_read");
static final ParseField BYTES_READ = new ParseField("bytes_read");
static final ParseField TOTAL_WRITE_TIME_MILLIS_FIELD = new ParseField("total_write_time_millis");
static final ParseField SUCCESSFUL_WRITE_REQUESTS_FIELD = new ParseField("successful_write_requests");
static final ParseField FAILED_WRITE_REQUEST_FIELD = new ParseField("failed_write_requests");
static final ParseField OPERATIONS_WRITTEN = new ParseField("operations_written");
static final ParseField READ_EXCEPTIONS = new ParseField("read_exceptions");
static final ParseField TIME_SINCE_LAST_READ_MILLIS_FIELD = new ParseField("time_since_last_read_millis");
static final ParseField FATAL_EXCEPTION = new ParseField("fatal_exception");
@SuppressWarnings("unchecked")
static final ConstructingObjectParser<ShardFollowStats, Void> PARSER =
new ConstructingObjectParser<>(
"shard-follow-stats",
true,
args -> new ShardFollowStats(
(String) args[0],
(String) args[1],
(String) args[2],
(int) args[3],
(long) args[4],
(long) args[5],
(long) args[6],
(long) args[7],
(long) args[8],
(int) args[9],
(int) args[10],
(int) args[11],
(long) args[12],
(long) args[13],
(long) args[14],
(long) args[15],
(long) args[16],
(long) args[17],
(long) args[18],
(long) args[19],
(long) args[20],
(long) args[21],
(long) args[22],
(long) args[23],
(long) args[24],
(long) args[25],
(long) args[26],
new TreeMap<>(
((List<Map.Entry<Long, Tuple<Integer, ElasticsearchException>>>) args[27])
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))),
(ElasticsearchException) args[28]));
static final ConstructingObjectParser<Map.Entry<Long, Tuple<Integer, ElasticsearchException>>, Void> READ_EXCEPTIONS_ENTRY_PARSER =
new ConstructingObjectParser<>(
"shard-follow-stats-read-exceptions-entry",
true,
args -> new AbstractMap.SimpleEntry<>((long) args[0], Tuple.tuple((Integer) args[1], (ElasticsearchException)args[2])));
static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_CLUSTER);
PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX);
PARSER.declareString(ConstructingObjectParser.constructorArg(), FOLLOWER_INDEX);
PARSER.declareInt(ConstructingObjectParser.constructorArg(), SHARD_ID);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), LEADER_GLOBAL_CHECKPOINT_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), LEADER_MAX_SEQ_NO_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FOLLOWER_GLOBAL_CHECKPOINT_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FOLLOWER_MAX_SEQ_NO_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), LAST_REQUESTED_SEQ_NO_FIELD);
PARSER.declareInt(ConstructingObjectParser.constructorArg(), OUTSTANDING_READ_REQUESTS);
PARSER.declareInt(ConstructingObjectParser.constructorArg(), OUTSTANDING_WRITE_REQUESTS);
PARSER.declareInt(ConstructingObjectParser.constructorArg(), WRITE_BUFFER_OPERATION_COUNT_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), WRITE_BUFFER_SIZE_IN_BYTES_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FOLLOWER_MAPPING_VERSION_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FOLLOWER_SETTINGS_VERSION_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FOLLOWER_ALIASES_VERSION_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), TOTAL_READ_TIME_MILLIS_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), TOTAL_READ_REMOTE_EXEC_TIME_MILLIS_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), SUCCESSFUL_READ_REQUESTS_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FAILED_READ_REQUESTS_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), OPERATIONS_READ_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), BYTES_READ);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), TOTAL_WRITE_TIME_MILLIS_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), SUCCESSFUL_WRITE_REQUESTS_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), FAILED_WRITE_REQUEST_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), OPERATIONS_WRITTEN);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), TIME_SINCE_LAST_READ_MILLIS_FIELD);
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), READ_EXCEPTIONS_ENTRY_PARSER, READ_EXCEPTIONS);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> ElasticsearchException.fromXContent(p),
FATAL_EXCEPTION);
}
static final ParseField READ_EXCEPTIONS_ENTRY_FROM_SEQ_NO = new ParseField("from_seq_no");
static final ParseField READ_EXCEPTIONS_RETRIES = new ParseField("retries");
static final ParseField READ_EXCEPTIONS_ENTRY_EXCEPTION = new ParseField("exception");
static {
READ_EXCEPTIONS_ENTRY_PARSER.declareLong(ConstructingObjectParser.constructorArg(), READ_EXCEPTIONS_ENTRY_FROM_SEQ_NO);
READ_EXCEPTIONS_ENTRY_PARSER.declareInt(ConstructingObjectParser.constructorArg(), READ_EXCEPTIONS_RETRIES);
READ_EXCEPTIONS_ENTRY_PARSER.declareObject(
ConstructingObjectParser.constructorArg(),
(p, c) -> ElasticsearchException.fromXContent(p),
READ_EXCEPTIONS_ENTRY_EXCEPTION);
}
private final String remoteCluster;
private final String leaderIndex;
private final String followerIndex;
private final int shardId;
private final long leaderGlobalCheckpoint;
private final long leaderMaxSeqNo;
private final long followerGlobalCheckpoint;
private final long followerMaxSeqNo;
private final long lastRequestedSeqNo;
private final int outstandingReadRequests;
private final int outstandingWriteRequests;
private final int writeBufferOperationCount;
private final long writeBufferSizeInBytes;
private final long followerMappingVersion;
private final long followerSettingsVersion;
private final long followerAliasesVersion;
private final long totalReadTimeMillis;
private final long totalReadRemoteExecTimeMillis;
private final long successfulReadRequests;
private final long failedReadRequests;
private final long operationsReads;
private final long bytesRead;
private final long totalWriteTimeMillis;
private final long successfulWriteRequests;
private final long failedWriteRequests;
private final long operationWritten;
private final long timeSinceLastReadMillis;
private final NavigableMap<Long, Tuple<Integer, ElasticsearchException>> readExceptions;
private final ElasticsearchException fatalException;
ShardFollowStats(String remoteCluster,
String leaderIndex,
String followerIndex,
int shardId,
long leaderGlobalCheckpoint,
long leaderMaxSeqNo,
long followerGlobalCheckpoint,
long followerMaxSeqNo,
long lastRequestedSeqNo,
int outstandingReadRequests,
int outstandingWriteRequests,
int writeBufferOperationCount,
long writeBufferSizeInBytes,
long followerMappingVersion,
long followerSettingsVersion,
long followerAliasesVersion,
long totalReadTimeMillis,
long totalReadRemoteExecTimeMillis,
long successfulReadRequests,
long failedReadRequests,
long operationsReads,
long bytesRead,
long totalWriteTimeMillis,
long successfulWriteRequests,
long failedWriteRequests,
long operationWritten,
long timeSinceLastReadMillis,
NavigableMap<Long, Tuple<Integer, ElasticsearchException>> readExceptions,
ElasticsearchException fatalException) {
this.remoteCluster = remoteCluster;
this.leaderIndex = leaderIndex;
this.followerIndex = followerIndex;
this.shardId = shardId;
this.leaderGlobalCheckpoint = leaderGlobalCheckpoint;
this.leaderMaxSeqNo = leaderMaxSeqNo;
this.followerGlobalCheckpoint = followerGlobalCheckpoint;
this.followerMaxSeqNo = followerMaxSeqNo;
this.lastRequestedSeqNo = lastRequestedSeqNo;
this.outstandingReadRequests = outstandingReadRequests;
this.outstandingWriteRequests = outstandingWriteRequests;
this.writeBufferOperationCount = writeBufferOperationCount;
this.writeBufferSizeInBytes = writeBufferSizeInBytes;
this.followerMappingVersion = followerMappingVersion;
this.followerSettingsVersion = followerSettingsVersion;
this.followerAliasesVersion = followerAliasesVersion;
this.totalReadTimeMillis = totalReadTimeMillis;
this.totalReadRemoteExecTimeMillis = totalReadRemoteExecTimeMillis;
this.successfulReadRequests = successfulReadRequests;
this.failedReadRequests = failedReadRequests;
this.operationsReads = operationsReads;
this.bytesRead = bytesRead;
this.totalWriteTimeMillis = totalWriteTimeMillis;
this.successfulWriteRequests = successfulWriteRequests;
this.failedWriteRequests = failedWriteRequests;
this.operationWritten = operationWritten;
this.timeSinceLastReadMillis = timeSinceLastReadMillis;
this.readExceptions = readExceptions;
this.fatalException = fatalException;
}
public String getRemoteCluster() {
return remoteCluster;
}
public String getLeaderIndex() {
return leaderIndex;
}
public String getFollowerIndex() {
return followerIndex;
}
public int getShardId() {
return shardId;
}
public long getLeaderGlobalCheckpoint() {
return leaderGlobalCheckpoint;
}
public long getLeaderMaxSeqNo() {
return leaderMaxSeqNo;
}
public long getFollowerGlobalCheckpoint() {
return followerGlobalCheckpoint;
}
public long getFollowerMaxSeqNo() {
return followerMaxSeqNo;
}
public long getLastRequestedSeqNo() {
return lastRequestedSeqNo;
}
public int getOutstandingReadRequests() {
return outstandingReadRequests;
}
public int getOutstandingWriteRequests() {
return outstandingWriteRequests;
}
public int getWriteBufferOperationCount() {
return writeBufferOperationCount;
}
public long getWriteBufferSizeInBytes() {
return writeBufferSizeInBytes;
}
public long getFollowerMappingVersion() {
return followerMappingVersion;
}
public long getFollowerSettingsVersion() {
return followerSettingsVersion;
}
public long getFollowerAliasesVersion() {
return followerAliasesVersion;
}
public long getTotalReadTimeMillis() {
return totalReadTimeMillis;
}
public long getTotalReadRemoteExecTimeMillis() {
return totalReadRemoteExecTimeMillis;
}
public long getSuccessfulReadRequests() {
return successfulReadRequests;
}
public long getFailedReadRequests() {
return failedReadRequests;
}
public long getOperationsReads() {
return operationsReads;
}
public long getBytesRead() {
return bytesRead;
}
public long getTotalWriteTimeMillis() {
return totalWriteTimeMillis;
}
public long getSuccessfulWriteRequests() {
return successfulWriteRequests;
}
public long getFailedWriteRequests() {
return failedWriteRequests;
}
public long getOperationWritten() {
return operationWritten;
}
public long getTimeSinceLastReadMillis() {
return timeSinceLastReadMillis;
}
public NavigableMap<Long, Tuple<Integer, ElasticsearchException>> getReadExceptions() {
return readExceptions;
}
public ElasticsearchException getFatalException() {
return fatalException;
}
}
}

View File

@ -1,45 +0,0 @@
/*
* 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;
/**
* Request class for pause auto follow pattern api.
*/
public final class PauseAutoFollowPatternRequest implements Validatable {
private final String name;
/**
* Pause auto follow pattern with the specified name
*
* @param name The name of the auto follow pattern to pause
*/
public PauseAutoFollowPatternRequest(String name) {
this.name = Objects.requireNonNull(name);
}
public String getName() {
return name;
}
}

View File

@ -1,37 +0,0 @@
/*
* 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 PauseFollowRequest implements Validatable {
private final String followerIndex;
public PauseFollowRequest(String followerIndex) {
this.followerIndex = Objects.requireNonNull(followerIndex);
}
public String getFollowerIndex() {
return followerIndex;
}
}

View File

@ -1,102 +0,0 @@
/*
* 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 org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
public final class PutAutoFollowPatternRequest extends FollowConfig implements Validatable, ToXContentObject {
static final ParseField LEADER_PATTERNS_FIELD = new ParseField("leader_index_patterns");
static final ParseField FOLLOW_PATTERN_FIELD = new ParseField("follow_index_pattern");
private final String name;
private final String remoteCluster;
private final List<String> leaderIndexPatterns;
private String followIndexNamePattern;
public PutAutoFollowPatternRequest(String name, String remoteCluster, List<String> leaderIndexPatterns) {
this.name = Objects.requireNonNull(name);
this.remoteCluster = Objects.requireNonNull(remoteCluster);
this.leaderIndexPatterns = Objects.requireNonNull(leaderIndexPatterns);
}
public String getName() {
return name;
}
public String getRemoteCluster() {
return remoteCluster;
}
public List<String> getLeaderIndexPatterns() {
return leaderIndexPatterns;
}
public String getFollowIndexNamePattern() {
return followIndexNamePattern;
}
public void setFollowIndexNamePattern(String followIndexNamePattern) {
this.followIndexNamePattern = followIndexNamePattern;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(PutFollowRequest.REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster);
builder.field(LEADER_PATTERNS_FIELD.getPreferredName(), leaderIndexPatterns);
if (followIndexNamePattern != null) {
builder.field(FOLLOW_PATTERN_FIELD.getPreferredName(), followIndexNamePattern);
}
toXContentFragment(builder, params);
builder.endObject();
return builder;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PutAutoFollowPatternRequest that = (PutAutoFollowPatternRequest) o;
return Objects.equals(name, that.name) &&
Objects.equals(remoteCluster, that.remoteCluster) &&
Objects.equals(leaderIndexPatterns, that.leaderIndexPatterns) &&
Objects.equals(followIndexNamePattern, that.followIndexNamePattern);
}
@Override
public int hashCode() {
return Objects.hash(
super.hashCode(),
name,
remoteCluster,
leaderIndexPatterns,
followIndexNamePattern
);
}
}

View File

@ -1,99 +0,0 @@
/*
* 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.action.support.ActiveShardCount;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Objects;
public final class PutFollowRequest extends FollowConfig implements Validatable, ToXContentObject {
static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster");
static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index");
private final String remoteCluster;
private final String leaderIndex;
private final String followerIndex;
private final ActiveShardCount waitForActiveShards;
public PutFollowRequest(String remoteCluster, String leaderIndex, String followerIndex) {
this(remoteCluster, leaderIndex, followerIndex, ActiveShardCount.NONE);
}
public PutFollowRequest(String remoteCluster, String leaderIndex, String followerIndex, ActiveShardCount waitForActiveShards) {
this.remoteCluster = Objects.requireNonNull(remoteCluster, "remoteCluster");
this.leaderIndex = Objects.requireNonNull(leaderIndex, "leaderIndex");
this.followerIndex = Objects.requireNonNull(followerIndex, "followerIndex");
this.waitForActiveShards = waitForActiveShards;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(REMOTE_CLUSTER_FIELD.getPreferredName(), remoteCluster);
builder.field(LEADER_INDEX_FIELD.getPreferredName(), leaderIndex);
toXContentFragment(builder, params);
builder.endObject();
return builder;
}
public String getRemoteCluster() {
return remoteCluster;
}
public String getLeaderIndex() {
return leaderIndex;
}
public String getFollowerIndex() {
return followerIndex;
}
public ActiveShardCount waitForActiveShards() {
return waitForActiveShards;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PutFollowRequest that = (PutFollowRequest) o;
return Objects.equals(waitForActiveShards, that.waitForActiveShards) &&
Objects.equals(remoteCluster, that.remoteCluster) &&
Objects.equals(leaderIndex, that.leaderIndex) &&
Objects.equals(followerIndex, that.followerIndex);
}
@Override
public int hashCode() {
return Objects.hash(
super.hashCode(),
remoteCluster,
leaderIndex,
followerIndex,
waitForActiveShards);
}
}

View File

@ -1,84 +0,0 @@
/*
* 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.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Objects;
public final class PutFollowResponse {
static final ParseField FOLLOW_INDEX_CREATED = new ParseField("follow_index_created");
static final ParseField FOLLOW_INDEX_SHARDS_ACKED = new ParseField("follow_index_shards_acked");
static final ParseField INDEX_FOLLOWING_STARTED = new ParseField("index_following_started");
private static final ConstructingObjectParser<PutFollowResponse, Void> PARSER = new ConstructingObjectParser<>(
"put_follow_response", true, args -> new PutFollowResponse((boolean) args[0], (boolean) args[1], (boolean) args[2]));
static {
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), FOLLOW_INDEX_CREATED);
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), FOLLOW_INDEX_SHARDS_ACKED);
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), INDEX_FOLLOWING_STARTED);
}
public static PutFollowResponse fromXContent(final XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
private final boolean followIndexCreated;
private final boolean followIndexShardsAcked;
private final boolean indexFollowingStarted;
public PutFollowResponse(boolean followIndexCreated, boolean followIndexShardsAcked, boolean indexFollowingStarted) {
this.followIndexCreated = followIndexCreated;
this.followIndexShardsAcked = followIndexShardsAcked;
this.indexFollowingStarted = indexFollowingStarted;
}
public boolean isFollowIndexCreated() {
return followIndexCreated;
}
public boolean isFollowIndexShardsAcked() {
return followIndexShardsAcked;
}
public boolean isIndexFollowingStarted() {
return indexFollowingStarted;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PutFollowResponse that = (PutFollowResponse) o;
return followIndexCreated == that.followIndexCreated &&
followIndexShardsAcked == that.followIndexShardsAcked &&
indexFollowingStarted == that.indexFollowingStarted;
}
@Override
public int hashCode() {
return Objects.hash(followIndexCreated, followIndexShardsAcked, indexFollowingStarted);
}
}

View File

@ -1,45 +0,0 @@
/*
* 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;
/**
* Request class for resume auto follow pattern api.
*/
public final class ResumeAutoFollowPatternRequest implements Validatable {
private final String name;
/**
* Resume auto follow pattern with the specified name
*
* @param name The name of the auto follow pattern to resume
*/
public ResumeAutoFollowPatternRequest(String name) {
this.name = Objects.requireNonNull(name);
}
public String getName() {
return name;
}
}

View File

@ -1,62 +0,0 @@
/*
* 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 org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Objects;
public final class ResumeFollowRequest extends FollowConfig implements Validatable, ToXContentObject {
private final String followerIndex;
public ResumeFollowRequest(String followerIndex) {
this.followerIndex = Objects.requireNonNull(followerIndex, "followerIndex");
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
toXContentFragment(builder, params);
builder.endObject();
return builder;
}
public String getFollowerIndex() {
return followerIndex;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ResumeFollowRequest that = (ResumeFollowRequest) o;
return Objects.equals(followerIndex, that.followerIndex);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), followerIndex);
}
}

View File

@ -1,37 +0,0 @@
/*
* 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 UnfollowRequest implements Validatable {
private final String followerIndex;
public UnfollowRequest(String followerIndex) {
this.followerIndex = Objects.requireNonNull(followerIndex);
}
public String getFollowerIndex() {
return followerIndex;
}
}

View File

@ -319,14 +319,12 @@ public final class Role {
public static final String MANAGE_TOKEN = "manage_token";
public static final String MANAGE_PIPELINE = "manage_pipeline";
public static final String MANAGE_AUTOSCALING = "manage_autoscaling";
public static final String MANAGE_CCR = "manage_ccr";
public static final String READ_CCR = "read_ccr";
public static final String MANAGE_ILM = "manage_ilm";
public static final String READ_ILM = "read_ilm";
public static final String[] ALL_ARRAY = new String[] { NONE, ALL, MONITOR, MONITOR_TRANSFORM_DEPRECATED, MONITOR_TRANSFORM,
MONITOR_ML, MONITOR_WATCHER, MONITOR_ROLLUP, MANAGE, MANAGE_TRANSFORM_DEPRECATED, MANAGE_TRANSFORM,
MANAGE_ML, MANAGE_WATCHER, MANAGE_ROLLUP, MANAGE_INDEX_TEMPLATES, MANAGE_INGEST_PIPELINES, TRANSPORT_CLIENT,
MANAGE_SECURITY, MANAGE_SAML, MANAGE_OIDC, MANAGE_TOKEN, MANAGE_PIPELINE, MANAGE_AUTOSCALING, MANAGE_CCR, READ_CCR,
MANAGE_SECURITY, MANAGE_SAML, MANAGE_OIDC, MANAGE_TOKEN, MANAGE_PIPELINE, MANAGE_AUTOSCALING,
MANAGE_ILM, READ_ILM };
}
@ -347,13 +345,12 @@ public final class Role {
public static final String DELETE_INDEX = "delete_index";
public static final String CREATE_INDEX = "create_index";
public static final String VIEW_INDEX_METADATA = "view_index_metadata";
public static final String MANAGE_FOLLOW_INDEX = "manage_follow_index";
public static final String MANAGE_ILM = "manage_ilm";
public static final String CREATE_DOC = "create_doc";
public static final String MAINTENANCE = "maintenance";
public static final String AUTO_CONFIGURE = "auto_configure";
public static final String[] ALL_ARRAY = new String[] { NONE, ALL, READ, READ_CROSS, CREATE, INDEX, DELETE, WRITE, MONITOR, MANAGE,
DELETE_INDEX, CREATE_INDEX, VIEW_INDEX_METADATA, MANAGE_FOLLOW_INDEX, MANAGE_ILM, CREATE_DOC, MAINTENANCE,
DELETE_INDEX, CREATE_INDEX, VIEW_INDEX_METADATA, MANAGE_ILM, CREATE_DOC, MAINTENANCE,
AUTO_CONFIGURE};
}

View File

@ -1,307 +0,0 @@
/*
* 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.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.ccr.CcrStatsRequest;
import org.elasticsearch.client.ccr.CcrStatsResponse;
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.FollowInfoRequest;
import org.elasticsearch.client.ccr.FollowInfoResponse;
import org.elasticsearch.client.ccr.FollowStatsRequest;
import org.elasticsearch.client.ccr.FollowStatsResponse;
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse;
import org.elasticsearch.client.ccr.IndicesFollowStats;
import org.elasticsearch.client.ccr.IndicesFollowStats.ShardFollowStats;
import org.elasticsearch.client.ccr.PauseFollowRequest;
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PutFollowRequest;
import org.elasticsearch.client.ccr.PutFollowResponse;
import org.elasticsearch.client.ccr.ResumeFollowRequest;
import org.elasticsearch.client.ccr.UnfollowRequest;
import org.elasticsearch.client.core.AcknowledgedResponse;
import org.elasticsearch.client.core.BroadcastResponse;
import org.elasticsearch.client.indices.CloseIndexRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.seqno.ReplicationTracker;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.junit.Before;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
public class CCRIT extends ESRestHighLevelClientTestCase {
@Before
public void setupRemoteClusterConfig() throws Exception {
setupRemoteClusterConfig("local_cluster");
}
public void testIndexFollowing() throws Exception {
CcrClient ccrClient = highLevelClient().ccr();
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
PutFollowRequest putFollowRequest = new PutFollowRequest("local_cluster", "leader", "follower", ActiveShardCount.ONE);
putFollowRequest.setSettings(Settings.builder().put("index.number_of_replicas", 0L).build());
PutFollowResponse putFollowResponse = execute(putFollowRequest, ccrClient::putFollow, ccrClient::putFollowAsync);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
IndexRequest indexRequest = new IndexRequest("leader", "_doc")
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source("{}", XContentType.JSON);
highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
SearchRequest leaderSearchRequest = new SearchRequest("leader");
SearchResponse leaderSearchResponse = highLevelClient().search(leaderSearchRequest, RequestOptions.DEFAULT);
assertThat(leaderSearchResponse.getHits().getTotalHits().value, equalTo(1L));
try {
assertBusy(() -> {
FollowInfoRequest followInfoRequest = new FollowInfoRequest("follower");
FollowInfoResponse followInfoResponse =
execute(followInfoRequest, ccrClient::getFollowInfo, ccrClient::getFollowInfoAsync);
assertThat(followInfoResponse.getInfos().size(), equalTo(1));
assertThat(followInfoResponse.getInfos().get(0).getFollowerIndex(), equalTo("follower"));
assertThat(followInfoResponse.getInfos().get(0).getLeaderIndex(), equalTo("leader"));
assertThat(followInfoResponse.getInfos().get(0).getRemoteCluster(), equalTo("local_cluster"));
assertThat(followInfoResponse.getInfos().get(0).getStatus(), equalTo(FollowInfoResponse.Status.ACTIVE));
FollowStatsRequest followStatsRequest = new FollowStatsRequest("follower");
FollowStatsResponse followStatsResponse =
execute(followStatsRequest, ccrClient::getFollowStats, ccrClient::getFollowStatsAsync);
List<ShardFollowStats> shardFollowStats = followStatsResponse.getIndicesFollowStats().getShardFollowStats("follower");
long followerGlobalCheckpoint = shardFollowStats.stream()
.mapToLong(ShardFollowStats::getFollowerGlobalCheckpoint)
.max()
.getAsLong();
assertThat(followerGlobalCheckpoint, equalTo(0L));
SearchRequest followerSearchRequest = new SearchRequest("follower");
SearchResponse followerSearchResponse = highLevelClient().search(followerSearchRequest, RequestOptions.DEFAULT);
assertThat(followerSearchResponse.getHits().getTotalHits().value, equalTo(1L));
GetSettingsRequest followerSettingsRequest = new GetSettingsRequest().indices("follower");
GetSettingsResponse followerSettingsResponse =
highLevelClient().indices().getSettings(followerSettingsRequest, RequestOptions.DEFAULT);
assertThat(
IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(followerSettingsResponse.getIndexToSettings().get("follower")),
equalTo(0));
});
} catch (Exception e) {
IndicesFollowStats followStats = ccrClient.getCcrStats(new CcrStatsRequest(), RequestOptions.DEFAULT).getIndicesFollowStats();
for (Map.Entry<String, List<ShardFollowStats>> entry : followStats.getShardFollowStats().entrySet()) {
for (ShardFollowStats shardFollowStats : entry.getValue()) {
if (shardFollowStats.getFatalException() != null) {
logger.warn(new ParameterizedMessage("fatal shard follow exception {}", shardFollowStats.getShardId()),
shardFollowStats.getFatalException());
}
}
}
}
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = execute(pauseFollowRequest, ccrClient::pauseFollow, ccrClient::pauseFollowAsync);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest("follower");
AcknowledgedResponse resumeFollowResponse = execute(resumeFollowRequest, ccrClient::resumeFollow, ccrClient::resumeFollowAsync);
assertThat(resumeFollowResponse.isAcknowledged(), is(true));
assertBusy(() -> {
FollowStatsRequest followStatsRequest = new FollowStatsRequest("follower");
FollowStatsResponse followStatsResponse =
execute(followStatsRequest, ccrClient::getFollowStats, ccrClient::getFollowStatsAsync);
List<ShardFollowStats> shardFollowStats = followStatsResponse.getIndicesFollowStats().getShardFollowStats("follower");
long followerGlobalCheckpoint = shardFollowStats.stream()
.mapToLong(ShardFollowStats::getFollowerGlobalCheckpoint)
.max()
.getAsLong();
assertThat(followerGlobalCheckpoint, equalTo(1L));
SearchRequest followerSearchRequest = new SearchRequest("follower");
SearchResponse followerSearchResponse = highLevelClient().search(followerSearchRequest, RequestOptions.DEFAULT);
assertThat(followerSearchResponse.getHits().getTotalHits().value, equalTo(2L));
});
// Need to pause prior to unfollowing it:
pauseFollowRequest = new PauseFollowRequest("follower");
pauseFollowResponse = execute(pauseFollowRequest, ccrClient::pauseFollow, ccrClient::pauseFollowAsync);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
assertBusy(() -> {
FollowInfoRequest followInfoRequest = new FollowInfoRequest("follower");
FollowInfoResponse followInfoResponse =
execute(followInfoRequest, ccrClient::getFollowInfo, ccrClient::getFollowInfoAsync);
assertThat(followInfoResponse.getInfos().size(), equalTo(1));
assertThat(followInfoResponse.getInfos().get(0).getFollowerIndex(), equalTo("follower"));
assertThat(followInfoResponse.getInfos().get(0).getLeaderIndex(), equalTo("leader"));
assertThat(followInfoResponse.getInfos().get(0).getRemoteCluster(), equalTo("local_cluster"));
assertThat(followInfoResponse.getInfos().get(0).getStatus(), equalTo(FollowInfoResponse.Status.PAUSED));
});
// Need to close index prior to unfollowing it:
CloseIndexRequest closeIndexRequest = new CloseIndexRequest("follower");
org.elasticsearch.action.support.master.AcknowledgedResponse closeIndexReponse =
highLevelClient().indices().close(closeIndexRequest, RequestOptions.DEFAULT);
assertThat(closeIndexReponse.isAcknowledged(), is(true));
UnfollowRequest unfollowRequest = new UnfollowRequest("follower");
AcknowledgedResponse unfollowResponse = execute(unfollowRequest, ccrClient::unfollow, ccrClient::unfollowAsync);
assertThat(unfollowResponse.isAcknowledged(), is(true));
}
public void testForgetFollower() throws IOException {
final CcrClient ccrClient = highLevelClient().ccr();
final CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
final Map<String, String> settings = new HashMap<>(3);
final int numberOfShards = randomIntBetween(1, 2);
settings.put("index.number_of_replicas", "0");
settings.put("index.number_of_shards", Integer.toString(numberOfShards));
createIndexRequest.settings(settings);
final CreateIndexResponse response = highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
final PutFollowRequest putFollowRequest = new PutFollowRequest("local_cluster", "leader", "follower", ActiveShardCount.ONE);
final PutFollowResponse putFollowResponse = execute(putFollowRequest, ccrClient::putFollow, ccrClient::putFollowAsync);
assertTrue(putFollowResponse.isFollowIndexCreated());
assertTrue(putFollowResponse.isFollowIndexShardsAcked());
assertTrue(putFollowResponse.isIndexFollowingStarted());
final String clusterName = highLevelClient().info(RequestOptions.DEFAULT).getClusterName();
final Request statsRequest = new Request("GET", "/follower/_stats");
final Response statsResponse = client().performRequest(statsRequest);
final ObjectPath statsObjectPath = ObjectPath.createFromResponse(statsResponse);
final String followerIndexUUID = statsObjectPath.evaluate("indices.follower.uuid");
final PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = execute(pauseFollowRequest, ccrClient::pauseFollow, ccrClient::pauseFollowAsync);
assertTrue(pauseFollowResponse.isAcknowledged());
final ForgetFollowerRequest forgetFollowerRequest =
new ForgetFollowerRequest(clusterName, "follower", followerIndexUUID, "local_cluster", "leader");
final BroadcastResponse forgetFollowerResponse =
execute(forgetFollowerRequest, ccrClient::forgetFollower, ccrClient::forgetFollowerAsync);
assertThat(forgetFollowerResponse.shards().total(), equalTo(numberOfShards));
assertThat(forgetFollowerResponse.shards().successful(), equalTo(numberOfShards));
assertThat(forgetFollowerResponse.shards().skipped(), equalTo(0));
assertThat(forgetFollowerResponse.shards().failed(), equalTo(0));
assertThat(forgetFollowerResponse.shards().failures(), empty());
final Request retentionLeasesRequest = new Request("GET", "/leader/_stats");
retentionLeasesRequest.addParameter("level", "shards");
final Response retentionLeasesResponse = client().performRequest(retentionLeasesRequest);
final Map<?, ?> shardsStats = ObjectPath.createFromResponse(retentionLeasesResponse).evaluate("indices.leader.shards");
assertThat(shardsStats.keySet(), hasSize(numberOfShards));
for (int i = 0; i < numberOfShards; i++) {
final List<?> shardStats = (List<?>) shardsStats.get(Integer.toString(i));
assertThat(shardStats, hasSize(1));
final Map<?, ?> shardStatsAsMap = (Map<?, ?>) shardStats.get(0);
final Map<?, ?> retentionLeasesStats = (Map<?, ?>) shardStatsAsMap.get("retention_leases");
final List<?> leases = (List<?>) retentionLeasesStats.get("leases");
for (final Object lease : leases) {
assertThat(((Map<?, ?>) lease).get("source"), equalTo(ReplicationTracker.PEER_RECOVERY_RETENTION_LEASE_SOURCE));
}
}
}
public void testAutoFollowing() throws Exception {
CcrClient ccrClient = highLevelClient().ccr();
PutAutoFollowPatternRequest putAutoFollowPatternRequest =
new PutAutoFollowPatternRequest("pattern1", "local_cluster", Collections.singletonList("logs-*"));
putAutoFollowPatternRequest.setFollowIndexNamePattern("copy-{{leader_index}}");
final int followerNumberOfReplicas = randomIntBetween(0, 4);
final Settings autoFollowerPatternSettings =
Settings.builder().put("index.number_of_replicas", followerNumberOfReplicas).build();
putAutoFollowPatternRequest.setSettings(autoFollowerPatternSettings);
AcknowledgedResponse putAutoFollowPatternResponse =
execute(putAutoFollowPatternRequest, ccrClient::putAutoFollowPattern, ccrClient::putAutoFollowPatternAsync);
assertThat(putAutoFollowPatternResponse.isAcknowledged(), is(true));
CreateIndexRequest createIndexRequest = new CreateIndexRequest("logs-20200101");
CreateIndexResponse response = highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
assertBusy(() -> {
CcrStatsRequest ccrStatsRequest = new CcrStatsRequest();
CcrStatsResponse ccrStatsResponse = execute(ccrStatsRequest, ccrClient::getCcrStats, ccrClient::getCcrStatsAsync);
assertThat(ccrStatsResponse.getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), equalTo(1L));
assertThat(ccrStatsResponse.getIndicesFollowStats().getShardFollowStats("copy-logs-20200101"), notNullValue());
});
assertThat(indexExists("copy-logs-20200101"), is(true));
assertThat(
getIndexSettingsAsMap("copy-logs-20200101"),
hasEntry("index.number_of_replicas", Integer.toString(followerNumberOfReplicas)));
GetAutoFollowPatternRequest getAutoFollowPatternRequest =
randomBoolean() ? new GetAutoFollowPatternRequest("pattern1") : new GetAutoFollowPatternRequest();
GetAutoFollowPatternResponse getAutoFollowPatternResponse =
execute(getAutoFollowPatternRequest, ccrClient::getAutoFollowPattern, ccrClient::getAutoFollowPatternAsync);
assertThat(getAutoFollowPatternResponse.getPatterns().size(), equalTo(1));
GetAutoFollowPatternResponse.Pattern pattern = getAutoFollowPatternResponse.getPatterns().get("pattern1");
assertThat(pattern, notNullValue());
assertThat(pattern.getRemoteCluster(), equalTo(putAutoFollowPatternRequest.getRemoteCluster()));
assertThat(pattern.getLeaderIndexPatterns(), equalTo(putAutoFollowPatternRequest.getLeaderIndexPatterns()));
assertThat(pattern.getFollowIndexNamePattern(), equalTo(putAutoFollowPatternRequest.getFollowIndexNamePattern()));
assertThat(pattern.getSettings(), equalTo(autoFollowerPatternSettings));
// Cleanup:
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);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
}
}

View File

@ -1,228 +0,0 @@
/*
* 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.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.ccr.CcrStatsRequest;
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.FollowConfig;
import org.elasticsearch.client.ccr.FollowInfoRequest;
import org.elasticsearch.client.ccr.FollowStatsRequest;
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseFollowRequest;
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PutFollowRequest;
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.ResumeFollowRequest;
import org.elasticsearch.client.ccr.UnfollowRequest;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
public class CcrRequestConvertersTests extends ESTestCase {
public void testPutFollow() throws Exception {
PutFollowRequest putFollowRequest = new PutFollowRequest(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4),
randomBoolean() ? randomFrom(ActiveShardCount.NONE, ActiveShardCount.ONE, ActiveShardCount.DEFAULT, ActiveShardCount.ALL) : null
);
randomizeRequest(putFollowRequest);
Request result = CcrRequestConverters.putFollow(putFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPut.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + putFollowRequest.getFollowerIndex() + "/_ccr/follow"));
if (putFollowRequest.waitForActiveShards() != null && putFollowRequest.waitForActiveShards() != ActiveShardCount.DEFAULT) {
String expectedValue = putFollowRequest.waitForActiveShards().toString().toLowerCase(Locale.ROOT);
assertThat(result.getParameters().get("wait_for_active_shards"), equalTo(expectedValue));
} else {
assertThat(result.getParameters().size(), equalTo(0));
}
RequestConvertersTests.assertToXContentBody(putFollowRequest, result.getEntity());
}
public void testPauseFollow() {
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.pauseFollow(pauseFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + pauseFollowRequest.getFollowerIndex() + "/_ccr/pause_follow"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testResumeFollow() throws Exception {
ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.resumeFollow(resumeFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + resumeFollowRequest.getFollowerIndex() + "/_ccr/resume_follow"));
assertThat(result.getParameters().size(), equalTo(0));
RequestConvertersTests.assertToXContentBody(resumeFollowRequest, result.getEntity());
}
public void testUnfollow() {
UnfollowRequest pauseFollowRequest = new UnfollowRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.unfollow(pauseFollowRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + pauseFollowRequest.getFollowerIndex() + "/_ccr/unfollow"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testForgetFollower() throws IOException {
final ForgetFollowerRequest request = new ForgetFollowerRequest(
randomAlphaOfLength(8),
randomAlphaOfLength(8),
randomAlphaOfLength(8),
randomAlphaOfLength(8),
randomAlphaOfLength(8));
final Request convertedRequest = CcrRequestConverters.forgetFollower(request);
assertThat(convertedRequest.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(convertedRequest.getEndpoint(), equalTo("/" + request.leaderIndex() + "/_ccr/forget_follower"));
assertThat(convertedRequest.getParameters().keySet(), empty());
RequestConvertersTests.assertToXContentBody(request, convertedRequest.getEntity());
}
public void testPutAutofollowPattern() throws Exception {
PutAutoFollowPatternRequest putAutoFollowPatternRequest = new PutAutoFollowPatternRequest(randomAlphaOfLength(4),
randomAlphaOfLength(4), Arrays.asList(generateRandomStringArray(4, 4, false)));
if (randomBoolean()) {
putAutoFollowPatternRequest.setFollowIndexNamePattern(randomAlphaOfLength(4));
}
randomizeRequest(putAutoFollowPatternRequest);
Request result = CcrRequestConverters.putAutoFollowPattern(putAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpPut.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + putAutoFollowPatternRequest.getName()));
assertThat(result.getParameters().size(), equalTo(0));
RequestConvertersTests.assertToXContentBody(putAutoFollowPatternRequest, result.getEntity());
}
public void testDeleteAutofollowPattern() throws Exception {
DeleteAutoFollowPatternRequest deleteAutoFollowPatternRequest = new DeleteAutoFollowPatternRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.deleteAutoFollowPattern(deleteAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpDelete.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + deleteAutoFollowPatternRequest.getName()));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testGetAutofollowPattern() throws Exception {
GetAutoFollowPatternRequest deleteAutoFollowPatternRequest = new GetAutoFollowPatternRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.getAutoFollowPattern(deleteAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + deleteAutoFollowPatternRequest.getName()));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testPauseAutofollowPattern() throws Exception {
PauseAutoFollowPatternRequest pauseAutoFollowPatternRequest = new PauseAutoFollowPatternRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.pauseAutoFollowPattern(pauseAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + pauseAutoFollowPatternRequest.getName() + "/pause"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testResumeAutofollowPattern() throws Exception {
ResumeAutoFollowPatternRequest resumeAutoFollowPatternRequest = new ResumeAutoFollowPatternRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.resumeAutoFollowPattern(resumeAutoFollowPatternRequest);
assertThat(result.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/auto_follow/" + resumeAutoFollowPatternRequest.getName() + "/resume"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testGetCcrStats() throws Exception {
CcrStatsRequest ccrStatsRequest = new CcrStatsRequest();
Request result = CcrRequestConverters.getCcrStats(ccrStatsRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/_ccr/stats"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testGetFollowStats() throws Exception {
FollowStatsRequest followStatsRequest = new FollowStatsRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.getFollowStats(followStatsRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + followStatsRequest.getFollowerIndex() + "/_ccr/stats"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
public void testGetFollowInfo() throws Exception {
FollowInfoRequest followInfoRequest = new FollowInfoRequest(randomAlphaOfLength(4));
Request result = CcrRequestConverters.getFollowInfo(followInfoRequest);
assertThat(result.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(result.getEndpoint(), equalTo("/" + followInfoRequest.getFollowerIndex() + "/_ccr/info"));
assertThat(result.getParameters().size(), equalTo(0));
assertThat(result.getEntity(), nullValue());
}
private static void randomizeRequest(FollowConfig request) {
if (randomBoolean()) {
request.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
request.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
request.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
}
}
}

View File

@ -916,7 +916,6 @@ public class RestHighLevelClientTests extends ESTestCase {
apiName.startsWith("migration.") == false &&
apiName.startsWith("security.") == false &&
apiName.startsWith("index_lifecycle.") == false &&
apiName.startsWith("ccr.") == false &&
apiName.startsWith("transform.") == false &&
apiName.endsWith("freeze") == false &&
apiName.endsWith("reload_analyzers") == false &&

View File

@ -1,236 +0,0 @@
/*
* 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.ElasticsearchException;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.client.ccr.IndicesFollowStats.ShardFollowStats;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus;
import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction;
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
public class CcrStatsResponseTests extends AbstractResponseTestCase<CcrStatsAction.Response, CcrStatsResponse> {
@Override
protected CcrStatsAction.Response createServerTestInstance(XContentType xContentType) {
org.elasticsearch.xpack.core.ccr.AutoFollowStats autoFollowStats = new org.elasticsearch.xpack.core.ccr.AutoFollowStats(
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomReadExceptions(),
randomTrackingClusters()
);
FollowStatsAction.StatsResponses statsResponse = createStatsResponse();
return new CcrStatsAction.Response(autoFollowStats, statsResponse);
}
static NavigableMap<String, Tuple<Long, ElasticsearchException>> randomReadExceptions() {
final int count = randomIntBetween(0, 16);
final NavigableMap<String, Tuple<Long, ElasticsearchException>> readExceptions = new TreeMap<>();
for (int i = 0; i < count; i++) {
readExceptions.put("" + i, Tuple.tuple(randomNonNegativeLong(),
new ElasticsearchException(new IllegalStateException("index [" + i + "]"))));
}
return readExceptions;
}
static NavigableMap<String, org.elasticsearch.xpack.core.ccr.AutoFollowStats.AutoFollowedCluster> randomTrackingClusters() {
final int count = randomIntBetween(0, 16);
final NavigableMap<String, org.elasticsearch.xpack.core.ccr.AutoFollowStats.AutoFollowedCluster> readExceptions = new TreeMap<>();
for (int i = 0; i < count; i++) {
readExceptions.put("" + i,
new org.elasticsearch.xpack.core.ccr.AutoFollowStats.AutoFollowedCluster(randomLong(), randomNonNegativeLong()));
}
return readExceptions;
}
static FollowStatsAction.StatsResponses createStatsResponse() {
int numResponses = randomIntBetween(0, 8);
List<FollowStatsAction.StatsResponse> responses = new ArrayList<>(numResponses);
for (int i = 0; i < numResponses; i++) {
ShardFollowNodeTaskStatus status = new ShardFollowNodeTaskStatus(
randomAlphaOfLength(4),
randomAlphaOfLength(4),
randomAlphaOfLength(4),
randomInt(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomIntBetween(0, Integer.MAX_VALUE),
randomIntBetween(0, Integer.MAX_VALUE),
randomIntBetween(0, Integer.MAX_VALUE),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
Collections.emptyNavigableMap(),
randomNonNegativeLong(),
randomBoolean() ? new ElasticsearchException("fatal error") : null);
responses.add(new FollowStatsAction.StatsResponse(status));
}
return new FollowStatsAction.StatsResponses(Collections.emptyList(), Collections.emptyList(), responses);
}
@Override
protected CcrStatsResponse doParseToClientInstance(XContentParser parser) throws IOException {
return CcrStatsResponse.fromXContent(parser);
}
@Override
protected void assertInstances(CcrStatsAction.Response serverTestInstance, CcrStatsResponse clientInstance) {
{
AutoFollowStats newAutoFollowStats = clientInstance.getAutoFollowStats();
org.elasticsearch.xpack.core.ccr.AutoFollowStats expectedAutoFollowStats = serverTestInstance.getAutoFollowStats();
assertThat(newAutoFollowStats.getNumberOfSuccessfulFollowIndices(),
equalTo(expectedAutoFollowStats.getNumberOfSuccessfulFollowIndices()));
assertThat(newAutoFollowStats.getNumberOfFailedRemoteClusterStateRequests(),
equalTo(expectedAutoFollowStats.getNumberOfFailedRemoteClusterStateRequests()));
assertThat(newAutoFollowStats.getNumberOfFailedFollowIndices(),
equalTo(expectedAutoFollowStats.getNumberOfFailedFollowIndices()));
assertThat(newAutoFollowStats.getRecentAutoFollowErrors().size(),
equalTo(expectedAutoFollowStats.getRecentAutoFollowErrors().size()));
assertThat(newAutoFollowStats.getRecentAutoFollowErrors().keySet(),
equalTo(expectedAutoFollowStats.getRecentAutoFollowErrors().keySet()));
for (final Map.Entry<String, Tuple<Long, ElasticsearchException>> entry :
newAutoFollowStats.getRecentAutoFollowErrors().entrySet()) {
// x-content loses the exception
final Tuple<Long, ElasticsearchException> expected =
expectedAutoFollowStats.getRecentAutoFollowErrors().get(entry.getKey());
assertThat(entry.getValue().v2().getMessage(), containsString(expected.v2().getMessage()));
assertThat(entry.getValue().v1(), equalTo(expected.v1()));
assertNotNull(entry.getValue().v2().getCause());
assertThat(
entry.getValue().v2().getCause(),
anyOf(instanceOf(ElasticsearchException.class), instanceOf(IllegalStateException.class)));
assertThat(entry.getValue().v2().getCause().getMessage(), containsString(expected.v2().getCause().getMessage()));
}
}
{
IndicesFollowStats newIndicesFollowStats = clientInstance.getIndicesFollowStats();
// sort by index name, then shard ID
final Map<String, Map<Integer, FollowStatsAction.StatsResponse>> expectedIndicesFollowStats = new TreeMap<>();
for (final FollowStatsAction.StatsResponse statsResponse : serverTestInstance.getFollowStats().getStatsResponses()) {
expectedIndicesFollowStats.computeIfAbsent(
statsResponse.status().followerIndex(),
k -> new TreeMap<>()).put(statsResponse.status().getShardId(), statsResponse);
}
assertThat(newIndicesFollowStats.getShardFollowStats().size(),
equalTo(expectedIndicesFollowStats.size()));
assertThat(newIndicesFollowStats.getShardFollowStats().keySet(),
equalTo(expectedIndicesFollowStats.keySet()));
for (Map.Entry<String, List<ShardFollowStats>> indexEntry : newIndicesFollowStats.getShardFollowStats().entrySet()) {
List<ShardFollowStats> newStats = indexEntry.getValue();
Map<Integer, FollowStatsAction.StatsResponse> expectedStats = expectedIndicesFollowStats.get(indexEntry.getKey());
assertThat(newStats.size(), equalTo(expectedStats.size()));
for (int i = 0; i < newStats.size(); i++) {
ShardFollowStats actualShardFollowStats = newStats.get(i);
ShardFollowNodeTaskStatus expectedShardFollowStats = expectedStats.get(actualShardFollowStats.getShardId()).status();
assertThat(actualShardFollowStats.getRemoteCluster(), equalTo(expectedShardFollowStats.getRemoteCluster()));
assertThat(actualShardFollowStats.getLeaderIndex(), equalTo(expectedShardFollowStats.leaderIndex()));
assertThat(actualShardFollowStats.getFollowerIndex(), equalTo(expectedShardFollowStats.followerIndex()));
assertThat(actualShardFollowStats.getShardId(), equalTo(expectedShardFollowStats.getShardId()));
assertThat(actualShardFollowStats.getLeaderGlobalCheckpoint(),
equalTo(expectedShardFollowStats.leaderGlobalCheckpoint()));
assertThat(actualShardFollowStats.getLeaderMaxSeqNo(), equalTo(expectedShardFollowStats.leaderMaxSeqNo()));
assertThat(actualShardFollowStats.getFollowerGlobalCheckpoint(),
equalTo(expectedShardFollowStats.followerGlobalCheckpoint()));
assertThat(actualShardFollowStats.getLastRequestedSeqNo(), equalTo(expectedShardFollowStats.lastRequestedSeqNo()));
assertThat(actualShardFollowStats.getOutstandingReadRequests(),
equalTo(expectedShardFollowStats.outstandingReadRequests()));
assertThat(actualShardFollowStats.getOutstandingWriteRequests(),
equalTo(expectedShardFollowStats.outstandingWriteRequests()));
assertThat(actualShardFollowStats.getWriteBufferOperationCount(),
equalTo(expectedShardFollowStats.writeBufferOperationCount()));
assertThat(actualShardFollowStats.getFollowerMappingVersion(),
equalTo(expectedShardFollowStats.followerMappingVersion()));
assertThat(actualShardFollowStats.getFollowerSettingsVersion(),
equalTo(expectedShardFollowStats.followerSettingsVersion()));
assertThat(actualShardFollowStats.getFollowerAliasesVersion(),
equalTo(expectedShardFollowStats.followerAliasesVersion()));
assertThat(actualShardFollowStats.getTotalReadTimeMillis(),
equalTo(expectedShardFollowStats.totalReadTimeMillis()));
assertThat(actualShardFollowStats.getSuccessfulReadRequests(),
equalTo(expectedShardFollowStats.successfulReadRequests()));
assertThat(actualShardFollowStats.getFailedReadRequests(), equalTo(expectedShardFollowStats.failedReadRequests()));
assertThat(actualShardFollowStats.getOperationsReads(), equalTo(expectedShardFollowStats.operationsReads()));
assertThat(actualShardFollowStats.getBytesRead(), equalTo(expectedShardFollowStats.bytesRead()));
assertThat(actualShardFollowStats.getTotalWriteTimeMillis(),
equalTo(expectedShardFollowStats.totalWriteTimeMillis()));
assertThat(actualShardFollowStats.getSuccessfulWriteRequests(),
equalTo(expectedShardFollowStats.successfulWriteRequests()));
assertThat(actualShardFollowStats.getFailedWriteRequests(),
equalTo(expectedShardFollowStats.failedWriteRequests()));
assertThat(actualShardFollowStats.getOperationWritten(), equalTo(expectedShardFollowStats.operationWritten()));
assertThat(actualShardFollowStats.getReadExceptions().size(),
equalTo(expectedShardFollowStats.readExceptions().size()));
assertThat(actualShardFollowStats.getReadExceptions().keySet(),
equalTo(expectedShardFollowStats.readExceptions().keySet()));
for (final Map.Entry<Long, Tuple<Integer, ElasticsearchException>> entry :
actualShardFollowStats.getReadExceptions().entrySet()) {
final Tuple<Integer, ElasticsearchException> expectedTuple =
expectedShardFollowStats.readExceptions().get(entry.getKey());
assertThat(entry.getValue().v1(), equalTo(expectedTuple.v1()));
// x-content loses the exception
final ElasticsearchException expected = expectedTuple.v2();
assertThat(entry.getValue().v2().getMessage(), containsString(expected.getMessage()));
assertNotNull(entry.getValue().v2().getCause());
assertThat(
entry.getValue().v2().getCause(),
anyOf(instanceOf(ElasticsearchException.class), instanceOf(IllegalStateException.class)));
assertThat(entry.getValue().v2().getCause().getMessage(), containsString(expected.getCause().getMessage()));
}
assertThat(actualShardFollowStats.getTimeSinceLastReadMillis(),
equalTo(expectedShardFollowStats.timeSinceLastReadMillis()));
}
}
}
}
}

View File

@ -1,80 +0,0 @@
/*
* 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.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
public class FollowConfigTests extends ESTestCase {
public void testFromXContent() throws IOException {
xContentTester(this::createParser,
FollowConfigTests::createTestInstance,
(followConfig, xContentBuilder) -> {
xContentBuilder.startObject();
followConfig.toXContentFragment(xContentBuilder, ToXContent.EMPTY_PARAMS);
xContentBuilder.endObject();
},
FollowConfig::fromXContent)
.supportsUnknownFields(true)
.test();
}
static FollowConfig createTestInstance() {
FollowConfig followConfig = new FollowConfig();
if (randomBoolean()) {
followConfig.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
followConfig.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
followConfig.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
followConfig.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
followConfig.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
followConfig.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
followConfig.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
followConfig.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
followConfig.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
followConfig.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
}
return followConfig;
}
}

View File

@ -1,108 +0,0 @@
/*
* 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.AbstractResponseTestCase;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction;
import org.elasticsearch.xpack.core.ccr.action.FollowParameters;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
public class FollowInfoResponseTests extends AbstractResponseTestCase<FollowInfoAction.Response, FollowInfoResponse> {
@Override
protected FollowInfoAction.Response createServerTestInstance(XContentType xContentType) {
int numInfos = randomIntBetween(0, 32);
List<FollowInfoAction.Response.FollowerInfo> infos = new ArrayList<>(numInfos);
for (int i = 0; i < numInfos; i++) {
FollowParameters followParameters = null;
if (randomBoolean()) {
followParameters = randomFollowParameters();
}
infos.add(new FollowInfoAction.Response.FollowerInfo(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4),
randomFrom(FollowInfoAction.Response.Status.values()), followParameters));
}
return new FollowInfoAction.Response(infos);
}
static FollowParameters randomFollowParameters() {
FollowParameters followParameters = new FollowParameters();
followParameters.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
followParameters.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
followParameters.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
followParameters.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
followParameters.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
followParameters.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
followParameters.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
followParameters.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
followParameters.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
followParameters.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
return followParameters;
}
@Override
protected FollowInfoResponse doParseToClientInstance(XContentParser parser) throws IOException {
return FollowInfoResponse.fromXContent(parser);
}
@Override
protected void assertInstances(FollowInfoAction.Response serverTestInstance, FollowInfoResponse clientInstance) {
assertThat(serverTestInstance.getFollowInfos().size(), equalTo(clientInstance.getInfos().size()));
for (int i = 0; i < serverTestInstance.getFollowInfos().size(); i++) {
FollowInfoAction.Response.FollowerInfo serverFollowInfo = serverTestInstance.getFollowInfos().get(i);
FollowInfoResponse.FollowerInfo clientFollowerInfo = clientInstance.getInfos().get(i);
assertThat(serverFollowInfo.getRemoteCluster(), equalTo(clientFollowerInfo.getRemoteCluster()));
assertThat(serverFollowInfo.getLeaderIndex(), equalTo(clientFollowerInfo.getLeaderIndex()));
assertThat(serverFollowInfo.getFollowerIndex(), equalTo(clientFollowerInfo.getFollowerIndex()));
assertThat(serverFollowInfo.getStatus().toString().toLowerCase(Locale.ROOT),
equalTo(clientFollowerInfo.getStatus().getName().toLowerCase(Locale.ROOT)));
FollowParameters serverParams = serverFollowInfo.getParameters();
FollowConfig clientParams = clientFollowerInfo.getParameters();
if (serverParams != null) {
assertThat(serverParams.getMaxReadRequestOperationCount(), equalTo(clientParams.getMaxReadRequestOperationCount()));
assertThat(serverParams.getMaxWriteRequestOperationCount(), equalTo(clientParams.getMaxWriteRequestOperationCount()));
assertThat(serverParams.getMaxOutstandingReadRequests(), equalTo(clientParams.getMaxOutstandingReadRequests()));
assertThat(serverParams.getMaxOutstandingWriteRequests(), equalTo(clientParams.getMaxOutstandingWriteRequests()));
assertThat(serverParams.getMaxReadRequestSize(), equalTo(clientParams.getMaxReadRequestSize()));
assertThat(serverParams.getMaxWriteRequestSize(), equalTo(clientParams.getMaxWriteRequestSize()));
assertThat(serverParams.getMaxWriteBufferCount(), equalTo(clientParams.getMaxWriteBufferCount()));
assertThat(serverParams.getMaxWriteBufferSize(), equalTo(clientParams.getMaxWriteBufferSize()));
assertThat(serverParams.getMaxRetryDelay(), equalTo(clientParams.getMaxRetryDelay()));
assertThat(serverParams.getReadPollTimeout(), equalTo(clientParams.getReadPollTimeout()));
} else {
assertThat(clientParams, nullValue());
}
}
}
}

View File

@ -1,137 +0,0 @@
/*
* 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.ElasticsearchException;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.client.ccr.IndicesFollowStats.ShardFollowStats;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus;
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static org.elasticsearch.client.ccr.CcrStatsResponseTests.createStatsResponse;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
public class FollowStatsResponseTests extends AbstractResponseTestCase<FollowStatsAction.StatsResponses, FollowStatsResponse> {
@Override
protected FollowStatsAction.StatsResponses createServerTestInstance(XContentType xContentType) {
return createStatsResponse();
}
@Override
protected FollowStatsResponse doParseToClientInstance(XContentParser parser) throws IOException {
return FollowStatsResponse.fromXContent(parser);
}
@Override
protected void assertInstances(FollowStatsAction.StatsResponses serverTestInstance, FollowStatsResponse clientInstance) {
IndicesFollowStats newIndicesFollowStats = clientInstance.getIndicesFollowStats();
// sort by index name, then shard ID
final Map<String, Map<Integer, FollowStatsAction.StatsResponse>> expectedIndicesFollowStats = new TreeMap<>();
for (final FollowStatsAction.StatsResponse statsResponse : serverTestInstance.getStatsResponses()) {
expectedIndicesFollowStats.computeIfAbsent(
statsResponse.status().followerIndex(),
k -> new TreeMap<>()).put(statsResponse.status().getShardId(), statsResponse);
}
assertThat(newIndicesFollowStats.getShardFollowStats().size(),
equalTo(expectedIndicesFollowStats.size()));
assertThat(newIndicesFollowStats.getShardFollowStats().keySet(),
equalTo(expectedIndicesFollowStats.keySet()));
for (Map.Entry<String, List<ShardFollowStats>> indexEntry : newIndicesFollowStats.getShardFollowStats().entrySet()) {
List<ShardFollowStats> newStats = indexEntry.getValue();
Map<Integer, FollowStatsAction.StatsResponse> expectedStats = expectedIndicesFollowStats.get(indexEntry.getKey());
assertThat(newStats.size(), equalTo(expectedStats.size()));
for (int i = 0; i < newStats.size(); i++) {
ShardFollowStats actualShardFollowStats = newStats.get(i);
ShardFollowNodeTaskStatus expectedShardFollowStats = expectedStats.get(actualShardFollowStats.getShardId()).status();
assertThat(actualShardFollowStats.getRemoteCluster(), equalTo(expectedShardFollowStats.getRemoteCluster()));
assertThat(actualShardFollowStats.getLeaderIndex(), equalTo(expectedShardFollowStats.leaderIndex()));
assertThat(actualShardFollowStats.getFollowerIndex(), equalTo(expectedShardFollowStats.followerIndex()));
assertThat(actualShardFollowStats.getShardId(), equalTo(expectedShardFollowStats.getShardId()));
assertThat(actualShardFollowStats.getLeaderGlobalCheckpoint(),
equalTo(expectedShardFollowStats.leaderGlobalCheckpoint()));
assertThat(actualShardFollowStats.getLeaderMaxSeqNo(), equalTo(expectedShardFollowStats.leaderMaxSeqNo()));
assertThat(actualShardFollowStats.getFollowerGlobalCheckpoint(),
equalTo(expectedShardFollowStats.followerGlobalCheckpoint()));
assertThat(actualShardFollowStats.getLastRequestedSeqNo(), equalTo(expectedShardFollowStats.lastRequestedSeqNo()));
assertThat(actualShardFollowStats.getOutstandingReadRequests(),
equalTo(expectedShardFollowStats.outstandingReadRequests()));
assertThat(actualShardFollowStats.getOutstandingWriteRequests(),
equalTo(expectedShardFollowStats.outstandingWriteRequests()));
assertThat(actualShardFollowStats.getWriteBufferOperationCount(),
equalTo(expectedShardFollowStats.writeBufferOperationCount()));
assertThat(actualShardFollowStats.getFollowerMappingVersion(),
equalTo(expectedShardFollowStats.followerMappingVersion()));
assertThat(actualShardFollowStats.getFollowerSettingsVersion(),
equalTo(expectedShardFollowStats.followerSettingsVersion()));
assertThat(actualShardFollowStats.getFollowerAliasesVersion(),
equalTo(expectedShardFollowStats.followerAliasesVersion()));
assertThat(actualShardFollowStats.getTotalReadTimeMillis(),
equalTo(expectedShardFollowStats.totalReadTimeMillis()));
assertThat(actualShardFollowStats.getSuccessfulReadRequests(),
equalTo(expectedShardFollowStats.successfulReadRequests()));
assertThat(actualShardFollowStats.getFailedReadRequests(), equalTo(expectedShardFollowStats.failedReadRequests()));
assertThat(actualShardFollowStats.getOperationsReads(), equalTo(expectedShardFollowStats.operationsReads()));
assertThat(actualShardFollowStats.getBytesRead(), equalTo(expectedShardFollowStats.bytesRead()));
assertThat(actualShardFollowStats.getTotalWriteTimeMillis(),
equalTo(expectedShardFollowStats.totalWriteTimeMillis()));
assertThat(actualShardFollowStats.getSuccessfulWriteRequests(),
equalTo(expectedShardFollowStats.successfulWriteRequests()));
assertThat(actualShardFollowStats.getFailedWriteRequests(),
equalTo(expectedShardFollowStats.failedWriteRequests()));
assertThat(actualShardFollowStats.getOperationWritten(), equalTo(expectedShardFollowStats.operationWritten()));
assertThat(actualShardFollowStats.getReadExceptions().size(),
equalTo(expectedShardFollowStats.readExceptions().size()));
assertThat(actualShardFollowStats.getReadExceptions().keySet(),
equalTo(expectedShardFollowStats.readExceptions().keySet()));
for (final Map.Entry<Long, Tuple<Integer, ElasticsearchException>> entry :
actualShardFollowStats.getReadExceptions().entrySet()) {
final Tuple<Integer, ElasticsearchException> expectedTuple =
expectedShardFollowStats.readExceptions().get(entry.getKey());
assertThat(entry.getValue().v1(), equalTo(expectedTuple.v1()));
// x-content loses the exception
final ElasticsearchException expected = expectedTuple.v2();
assertThat(entry.getValue().v2().getMessage(), containsString(expected.getMessage()));
assertNotNull(entry.getValue().v2().getCause());
assertThat(
entry.getValue().v2().getCause(),
anyOf(instanceOf(ElasticsearchException.class), instanceOf(IllegalStateException.class)));
assertThat(entry.getValue().v2().getCause().getMessage(), containsString(expected.getCause().getMessage()));
}
assertThat(actualShardFollowStats.getTimeSinceLastReadMillis(),
equalTo(expectedShardFollowStats.timeSinceLastReadMillis()));
}
}
}
}

View File

@ -1,152 +0,0 @@
/*
* 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.AbstractResponseTestCase;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata;
import org.elasticsearch.xpack.core.ccr.action.GetAutoFollowPatternAction;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
public class GetAutoFollowPatternResponseTests extends AbstractResponseTestCase<
GetAutoFollowPatternAction.Response,
GetAutoFollowPatternResponse> {
@Override
protected GetAutoFollowPatternAction.Response createServerTestInstance(XContentType xContentType) {
int numPatterns = randomIntBetween(0, 16);
NavigableMap<String, AutoFollowMetadata.AutoFollowPattern> patterns = new TreeMap<>();
for (int i = 0; i < numPatterns; i++) {
String remoteCluster = randomAlphaOfLength(4);
List<String> leaderIndexPatterns = Collections.singletonList(randomAlphaOfLength(4));
String followIndexNamePattern = randomAlphaOfLength(4);
final Settings settings =
Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), randomIntBetween(0, 4)).build();
boolean active = randomBoolean();
Integer maxOutstandingReadRequests = null;
if (randomBoolean()) {
maxOutstandingReadRequests = randomIntBetween(0, Integer.MAX_VALUE);
}
Integer maxOutstandingWriteRequests = null;
if (randomBoolean()) {
maxOutstandingWriteRequests = randomIntBetween(0, Integer.MAX_VALUE);
}
Integer maxReadRequestOperationCount = null;
if (randomBoolean()) {
maxReadRequestOperationCount = randomIntBetween(0, Integer.MAX_VALUE);
}
ByteSizeValue maxReadRequestSize = null;
if (randomBoolean()) {
maxReadRequestSize = new ByteSizeValue(randomNonNegativeLong());
}
Integer maxWriteBufferCount = null;
if (randomBoolean()) {
maxWriteBufferCount = randomIntBetween(0, Integer.MAX_VALUE);
}
ByteSizeValue maxWriteBufferSize = null;
if (randomBoolean()) {
maxWriteBufferSize = new ByteSizeValue(randomNonNegativeLong());
}
Integer maxWriteRequestOperationCount = null;
if (randomBoolean()) {
maxWriteRequestOperationCount = randomIntBetween(0, Integer.MAX_VALUE);
}
ByteSizeValue maxWriteRequestSize = null;
if (randomBoolean()) {
maxWriteRequestSize = new ByteSizeValue(randomNonNegativeLong());
}
TimeValue maxRetryDelay = null;
if (randomBoolean()) {
maxRetryDelay = new TimeValue(randomNonNegativeLong());
}
TimeValue readPollTimeout = null;
if (randomBoolean()) {
readPollTimeout = new TimeValue(randomNonNegativeLong());
}
patterns.put(
randomAlphaOfLength(4),
new AutoFollowMetadata.AutoFollowPattern(
remoteCluster,
leaderIndexPatterns,
followIndexNamePattern,
settings,
active,
maxReadRequestOperationCount,
maxWriteRequestOperationCount,
maxOutstandingReadRequests,
maxOutstandingWriteRequests,
maxReadRequestSize,
maxWriteRequestSize,
maxWriteBufferCount,
maxWriteBufferSize,
maxRetryDelay,
readPollTimeout
)
);
}
return new GetAutoFollowPatternAction.Response(patterns);
}
@Override
protected GetAutoFollowPatternResponse doParseToClientInstance(XContentParser parser) throws IOException {
return GetAutoFollowPatternResponse.fromXContent(parser);
}
@Override
protected void assertInstances(GetAutoFollowPatternAction.Response serverTestInstance, GetAutoFollowPatternResponse clientInstance) {
assertThat(serverTestInstance.getAutoFollowPatterns().size(), equalTo(clientInstance.getPatterns().size()));
for (Map.Entry<String, AutoFollowMetadata.AutoFollowPattern> entry : serverTestInstance.getAutoFollowPatterns().entrySet()) {
AutoFollowMetadata.AutoFollowPattern serverPattern = entry.getValue();
GetAutoFollowPatternResponse.Pattern clientPattern = clientInstance.getPatterns().get(entry.getKey());
assertThat(clientPattern, notNullValue());
assertThat(serverPattern.getRemoteCluster(), equalTo(clientPattern.getRemoteCluster()));
assertThat(serverPattern.getLeaderIndexPatterns(), equalTo(clientPattern.getLeaderIndexPatterns()));
assertThat(serverPattern.getFollowIndexPattern(), equalTo(clientPattern.getFollowIndexNamePattern()));
assertThat(serverPattern.getSettings(), equalTo(clientPattern.getSettings()));
assertThat(serverPattern.getMaxOutstandingReadRequests(), equalTo(clientPattern.getMaxOutstandingReadRequests()));
assertThat(serverPattern.getMaxOutstandingWriteRequests(), equalTo(clientPattern.getMaxOutstandingWriteRequests()));
assertThat(serverPattern.getMaxReadRequestOperationCount(), equalTo(clientPattern.getMaxReadRequestOperationCount()));
assertThat(serverPattern.getMaxWriteRequestOperationCount(), equalTo(clientPattern.getMaxWriteRequestOperationCount()));
assertThat(serverPattern.getMaxReadRequestSize(), equalTo(clientPattern.getMaxReadRequestSize()));
assertThat(serverPattern.getMaxWriteRequestSize(), equalTo(clientPattern.getMaxWriteRequestSize()));
assertThat(serverPattern.getMaxWriteBufferCount(), equalTo(clientPattern.getMaxWriteBufferCount()));
assertThat(serverPattern.getMaxWriteBufferSize(), equalTo(clientPattern.getMaxWriteBufferSize()));
assertThat(serverPattern.getMaxRetryDelay(), equalTo(clientPattern.getMaxRetryDelay()));
assertThat(serverPattern.getReadPollTimeout(), equalTo(clientPattern.getReadPollTimeout()));
}
}
}

View File

@ -1,93 +0,0 @@
/*
* 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.AbstractRequestTestCase;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction;
import java.io.IOException;
import java.util.Arrays;
import static org.elasticsearch.client.ccr.PutFollowRequestTests.assertFollowConfig;
import static org.hamcrest.Matchers.equalTo;
public class PutAutoFollowPatternRequestTests extends AbstractRequestTestCase<
PutAutoFollowPatternRequest,
PutAutoFollowPatternAction.Request> {
@Override
protected PutAutoFollowPatternRequest createClientTestInstance() {
// Name isn't serialized, because it specified in url path, so no need to randomly generate it here.
PutAutoFollowPatternRequest putAutoFollowPatternRequest = new PutAutoFollowPatternRequest("name",
randomAlphaOfLength(4), Arrays.asList(generateRandomStringArray(4, 4, false)));
if (randomBoolean()) {
putAutoFollowPatternRequest.setFollowIndexNamePattern(randomAlphaOfLength(4));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putAutoFollowPatternRequest.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
}
return putAutoFollowPatternRequest;
}
@Override
protected PutAutoFollowPatternAction.Request doParseToServerInstance(XContentParser parser) throws IOException {
return PutAutoFollowPatternAction.Request.fromXContent(parser, "name");
}
@Override
protected void assertInstances(PutAutoFollowPatternAction.Request serverInstance, PutAutoFollowPatternRequest clientTestInstance) {
assertThat(serverInstance.getName(), equalTo(clientTestInstance.getName()));
assertThat(serverInstance.getRemoteCluster(), equalTo(clientTestInstance.getRemoteCluster()));
assertThat(serverInstance.getLeaderIndexPatterns(), equalTo(clientTestInstance.getLeaderIndexPatterns()));
assertThat(serverInstance.getFollowIndexNamePattern(), equalTo(clientTestInstance.getFollowIndexNamePattern()));
assertFollowConfig(serverInstance.getParameters(), clientTestInstance);
}
}

View File

@ -1,99 +0,0 @@
/*
* 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.action.support.ActiveShardCount;
import org.elasticsearch.client.AbstractRequestTestCase;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ccr.action.FollowParameters;
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
public class PutFollowRequestTests extends AbstractRequestTestCase<PutFollowRequest, PutFollowAction.Request> {
@Override
protected PutFollowRequest createClientTestInstance() {
PutFollowRequest putFollowRequest =
new PutFollowRequest(randomAlphaOfLength(4), randomAlphaOfLength(4), "followerIndex");
if (randomBoolean()) {
putFollowRequest.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putFollowRequest.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putFollowRequest.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putFollowRequest.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putFollowRequest.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putFollowRequest.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putFollowRequest.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
putFollowRequest.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putFollowRequest.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
putFollowRequest.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
}
return putFollowRequest;
}
@Override
protected PutFollowAction.Request doParseToServerInstance(XContentParser parser) throws IOException {
return PutFollowAction.Request.fromXContent(parser, "followerIndex", ActiveShardCount.DEFAULT);
}
@Override
protected void assertInstances(PutFollowAction.Request serverInstance, PutFollowRequest clientTestInstance) {
assertThat(serverInstance.getRemoteCluster(), equalTo(clientTestInstance.getRemoteCluster()));
assertThat(serverInstance.getLeaderIndex(), equalTo(clientTestInstance.getLeaderIndex()));
assertThat(serverInstance.getFollowerIndex(), equalTo(clientTestInstance.getFollowerIndex()));
assertFollowConfig(serverInstance.getParameters(), clientTestInstance);
}
static void assertFollowConfig(FollowParameters serverParameters, FollowConfig clientConfig) {
assertThat(serverParameters.getMaxReadRequestOperationCount(), equalTo(clientConfig.getMaxReadRequestOperationCount()));
assertThat(serverParameters.getMaxWriteRequestOperationCount(), equalTo(clientConfig.getMaxWriteRequestOperationCount()));
assertThat(serverParameters.getMaxOutstandingReadRequests(), equalTo(clientConfig.getMaxOutstandingReadRequests()));
assertThat(serverParameters.getMaxOutstandingWriteRequests(), equalTo(clientConfig.getMaxOutstandingWriteRequests()));
assertThat(serverParameters.getMaxReadRequestSize(), equalTo(clientConfig.getMaxReadRequestSize()));
assertThat(serverParameters.getMaxWriteRequestSize(), equalTo(clientConfig.getMaxWriteRequestSize()));
assertThat(serverParameters.getMaxWriteBufferCount(), equalTo(clientConfig.getMaxWriteBufferCount()));
assertThat(serverParameters.getMaxWriteBufferSize(), equalTo(clientConfig.getMaxWriteBufferSize()));
assertThat(serverParameters.getMaxRetryDelay(), equalTo(clientConfig.getMaxRetryDelay()));
assertThat(serverParameters.getReadPollTimeout(), equalTo(clientConfig.getReadPollTimeout()));
}
}

View File

@ -1,49 +0,0 @@
/*
* 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.AbstractResponseTestCase;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
import java.io.IOException;
import static org.hamcrest.Matchers.is;
public class PutFollowResponseTests extends AbstractResponseTestCase<PutFollowAction.Response, PutFollowResponse> {
@Override
protected PutFollowAction.Response createServerTestInstance(XContentType xContentType) {
return new PutFollowAction.Response(randomBoolean(), randomBoolean(), randomBoolean());
}
@Override
protected PutFollowResponse doParseToClientInstance(XContentParser parser) throws IOException {
return PutFollowResponse.fromXContent(parser);
}
@Override
protected void assertInstances(PutFollowAction.Response serverTestInstance, PutFollowResponse clientInstance) {
assertThat(serverTestInstance.isFollowIndexCreated(), is(clientInstance.isFollowIndexCreated()));
assertThat(serverTestInstance.isFollowIndexShardsAcked(), is(clientInstance.isFollowIndexShardsAcked()));
assertThat(serverTestInstance.isIndexFollowingStarted(), is(clientInstance.isIndexFollowingStarted()));
}
}

View File

@ -1,82 +0,0 @@
/*
* 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.AbstractRequestTestCase;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction;
import java.io.IOException;
import static org.elasticsearch.client.ccr.PutFollowRequestTests.assertFollowConfig;
import static org.hamcrest.Matchers.equalTo;
public class ResumeFollowRequestTests extends AbstractRequestTestCase<ResumeFollowRequest, ResumeFollowAction.Request> {
@Override
protected ResumeFollowRequest createClientTestInstance() {
ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest("followerIndex");
if (randomBoolean()) {
resumeFollowRequest.setMaxOutstandingReadRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxOutstandingWriteRequests(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxReadRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxReadRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxWriteBufferCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxWriteBufferSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxWriteRequestOperationCount(randomIntBetween(0, Integer.MAX_VALUE));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxWriteRequestSize(new ByteSizeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
resumeFollowRequest.setMaxRetryDelay(new TimeValue(randomNonNegativeLong()));
}
if (randomBoolean()) {
resumeFollowRequest.setReadPollTimeout(new TimeValue(randomNonNegativeLong()));
}
return resumeFollowRequest;
}
@Override
protected ResumeFollowAction.Request doParseToServerInstance(XContentParser parser) throws IOException {
return ResumeFollowAction.Request.fromXContent(parser, "followerIndex");
}
@Override
protected void assertInstances(ResumeFollowAction.Request serverInstance, ResumeFollowRequest clientTestInstance) {
assertThat(serverInstance.getFollowerIndex(), equalTo(clientTestInstance.getFollowerIndex()));
assertFollowConfig(serverInstance.getParameters(), clientTestInstance);
}
}

View File

@ -1,972 +0,0 @@
/*
* 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.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
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.AutoFollowStats;
import org.elasticsearch.client.ccr.CcrStatsRequest;
import org.elasticsearch.client.ccr.CcrStatsResponse;
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.FollowInfoRequest;
import org.elasticsearch.client.ccr.FollowInfoResponse;
import org.elasticsearch.client.ccr.FollowStatsRequest;
import org.elasticsearch.client.ccr.FollowStatsResponse;
import org.elasticsearch.client.ccr.ForgetFollowerRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse;
import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse.Pattern;
import org.elasticsearch.client.ccr.IndicesFollowStats;
import org.elasticsearch.client.ccr.PauseAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PauseFollowRequest;
import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.PutFollowRequest;
import org.elasticsearch.client.ccr.PutFollowResponse;
import org.elasticsearch.client.ccr.ResumeAutoFollowPatternRequest;
import org.elasticsearch.client.ccr.ResumeFollowRequest;
import org.elasticsearch.client.ccr.UnfollowRequest;
import org.elasticsearch.client.core.AcknowledgedResponse;
import org.elasticsearch.client.core.BroadcastResponse;
import org.elasticsearch.client.indices.CloseIndexRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.junit.Before;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.is;
public class CCRDocumentationIT extends ESRestHighLevelClientTestCase {
@Before
public void setupRemoteClusterConfig() throws Exception {
setupRemoteClusterConfig("local");
}
public void testPutFollow() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// Create leader index:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
// tag::ccr-put-follow-request
PutFollowRequest putFollowRequest = new PutFollowRequest(
"local", // <1>
"leader", // <2>
"follower", // <3>
ActiveShardCount.ONE // <4>
);
Settings settings =
Settings.builder().put("index.number_of_replicas", 0L).build();
putFollowRequest.setSettings(settings); // <5>
// end::ccr-put-follow-request
// tag::ccr-put-follow-execute
PutFollowResponse putFollowResponse =
client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
// end::ccr-put-follow-execute
// tag::ccr-put-follow-response
boolean isFollowIndexCreated =
putFollowResponse.isFollowIndexCreated(); // <1>
boolean isFollowIndexShardsAcked =
putFollowResponse.isFollowIndexShardsAcked(); // <2>
boolean isIndexFollowingStarted =
putFollowResponse.isIndexFollowingStarted(); // <3>
// end::ccr-put-follow-response
// Pause following and delete follower index, so that we can execute put follow api again:
{
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("follower");
assertThat(client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true));
}
// tag::ccr-put-follow-execute-listener
ActionListener<PutFollowResponse> listener =
new ActionListener<PutFollowResponse>() {
@Override
public void onResponse(PutFollowResponse response) { // <1>
boolean isFollowIndexCreated =
putFollowResponse.isFollowIndexCreated();
boolean isFollowIndexShardsAcked =
putFollowResponse.isFollowIndexShardsAcked();
boolean isIndexFollowingStarted =
putFollowResponse.isIndexFollowingStarted();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-put-follow-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-put-follow-execute-async
client.ccr().putFollowAsync(putFollowRequest,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-put-follow-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
{
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
}
}
public void testPauseFollow() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// Create leader index:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
String followIndex = "follower";
// Follow index, so that it can be paused:
{
PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE);
PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
}
// tag::ccr-pause-follow-request
PauseFollowRequest request = new PauseFollowRequest(followIndex); // <1>
// end::ccr-pause-follow-request
// tag::ccr-pause-follow-execute
AcknowledgedResponse response =
client.ccr().pauseFollow(request, RequestOptions.DEFAULT);
// end::ccr-pause-follow-execute
// tag::ccr-pause-follow-response
boolean acknowledged = response.isAcknowledged(); // <1>
// end::ccr-pause-follow-response
// tag::ccr-pause-follow-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) {
boolean acknowledged = response.isAcknowledged(); // <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-pause-follow-execute-listener
// Resume follow index, so that it can be paused again:
{
ResumeFollowRequest resumeFollowRequest = new ResumeFollowRequest(followIndex);
AcknowledgedResponse resumeResponse = client.ccr().resumeFollow(resumeFollowRequest, RequestOptions.DEFAULT);
assertThat(resumeResponse.isAcknowledged(), is(true));
}
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::ccr-pause-follow-execute-async
client.ccr()
.pauseFollowAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::ccr-pause-follow-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
public void testResumeFollow() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// Create leader index:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
String followIndex = "follower";
// Follow index, so that it can be paused:
{
PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE);
PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
}
// Pause follow index, so that it can be resumed:
{
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex);
AcknowledgedResponse pauseResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(pauseResponse.isAcknowledged(), is(true));
}
// tag::ccr-resume-follow-request
ResumeFollowRequest request = new ResumeFollowRequest(followIndex); // <1>
// end::ccr-resume-follow-request
// tag::ccr-resume-follow-execute
AcknowledgedResponse response =
client.ccr().resumeFollow(request, RequestOptions.DEFAULT);
// end::ccr-resume-follow-execute
// tag::ccr-resume-follow-response
boolean acknowledged = response.isAcknowledged(); // <1>
// end::ccr-resume-follow-response
// Pause follow index, so that it can be resumed again:
{
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex);
AcknowledgedResponse pauseResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(pauseResponse.isAcknowledged(), is(true));
}
// tag::ccr-resume-follow-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) {
boolean acknowledged = response.isAcknowledged(); // <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-resume-follow-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-resume-follow-execute-async
client.ccr()
.resumeFollowAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::ccr-resume-follow-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
// Cleanup:
client.ccr().pauseFollow(new PauseFollowRequest(followIndex), RequestOptions.DEFAULT);
}
public void testUnfollow() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// Create leader index:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
String followIndex = "follower";
// Follow index, pause and close, so that it can be unfollowed:
{
PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE);
PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex);
AcknowledgedResponse unfollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(unfollowResponse.isAcknowledged(), is(true));
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followIndex);
assertThat(client.indices().close(closeIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true));
}
// tag::ccr-unfollow-request
UnfollowRequest request = new UnfollowRequest(followIndex); // <1>
// end::ccr-unfollow-request
// tag::ccr-unfollow-execute
AcknowledgedResponse response =
client.ccr().unfollow(request, RequestOptions.DEFAULT);
// end::ccr-unfollow-execute
// tag::ccr-unfollow-response
boolean acknowledged = response.isAcknowledged(); // <1>
// end::ccr-unfollow-response
// Delete, put follow index, pause and close, so that it can be unfollowed again:
{
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(followIndex);
assertThat(client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true));
PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followIndex, ActiveShardCount.ONE);
PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest(followIndex);
AcknowledgedResponse unfollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(unfollowResponse.isAcknowledged(), is(true));
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followIndex);
assertThat(client.indices().close(closeIndexRequest, RequestOptions.DEFAULT).isAcknowledged(), is(true));
}
// tag::ccr-unfollow-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) {
boolean acknowledged = response.isAcknowledged(); // <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-unfollow-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-unfollow-execute-async
client.ccr()
.unfollowAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::ccr-unfollow-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
public void testForgetFollower() throws InterruptedException, IOException {
final RestHighLevelClient client = highLevelClient();
final String leaderIndex = "leader";
{
// create leader index
final CreateIndexRequest createIndexRequest = new CreateIndexRequest(leaderIndex);
final Map<String, String> settings = new HashMap<>(2);
final int numberOfShards = randomIntBetween(1, 2);
settings.put("index.number_of_shards", Integer.toString(numberOfShards));
createIndexRequest.settings(settings);
final CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
final String followerIndex = "follower";
final PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", followerIndex, ActiveShardCount.ONE);
final PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertTrue(putFollowResponse.isFollowIndexCreated());
assertTrue((putFollowResponse.isFollowIndexShardsAcked()));
assertTrue(putFollowResponse.isIndexFollowingStarted());
final PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertTrue(pauseFollowResponse.isAcknowledged());
final String followerCluster = highLevelClient().info(RequestOptions.DEFAULT).getClusterName();
final Request statsRequest = new Request("GET", "/follower/_stats");
final Response statsResponse = client().performRequest(statsRequest);
final ObjectPath statsObjectPath = ObjectPath.createFromResponse(statsResponse);
final String followerIndexUUID = statsObjectPath.evaluate("indices.follower.uuid");
final String leaderCluster = "local";
// tag::ccr-forget-follower-request
final ForgetFollowerRequest request = new ForgetFollowerRequest(
followerCluster, // <1>
followerIndex, // <2>
followerIndexUUID, // <3>
leaderCluster, // <4>
leaderIndex); // <5>
// end::ccr-forget-follower-request
// tag::ccr-forget-follower-execute
final BroadcastResponse response = client
.ccr()
.forgetFollower(request, RequestOptions.DEFAULT);
// end::ccr-forget-follower-execute
// tag::ccr-forget-follower-response
final BroadcastResponse.Shards shards = response.shards(); // <1>
final int total = shards.total(); // <2>
final int successful = shards.successful(); // <3>
final int skipped = shards.skipped(); // <4>
final int failed = shards.failed(); // <5>
shards.failures().forEach(failure -> {}); // <6>
// end::ccr-forget-follower-response
// tag::ccr-forget-follower-execute-listener
ActionListener<BroadcastResponse> listener =
new ActionListener<BroadcastResponse>() {
@Override
public void onResponse(final BroadcastResponse response) {
final BroadcastResponse.Shards shards = // <1>
response.shards();
final int total = shards.total();
final int successful = shards.successful();
final int skipped = shards.skipped();
final int failed = shards.failed();
shards.failures().forEach(failure -> {});
}
@Override
public void onFailure(final Exception e) {
// <2>
}
};
// end::ccr-forget-follower-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-forget-follower-execute-async
client.ccr().forgetFollowerAsync(
request,
RequestOptions.DEFAULT,
listener); // <1>
// end::ccr-forget-follower-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
public void testPutAutoFollowPattern() throws Exception {
RestHighLevelClient client = highLevelClient();
// tag::ccr-put-auto-follow-pattern-request
PutAutoFollowPatternRequest request =
new PutAutoFollowPatternRequest(
"my_pattern", // <1>
"local", // <2>
Arrays.asList("logs-*", "metrics-*") // <3>
);
request.setFollowIndexNamePattern("copy-{{leader_index}}"); // <4>
Settings settings =
Settings.builder().put("index.number_of_replicas", 0L).build();
request.setSettings(settings); // <5>
// end::ccr-put-auto-follow-pattern-request
// tag::ccr-put-auto-follow-pattern-execute
AcknowledgedResponse response = client.ccr()
.putAutoFollowPattern(request, RequestOptions.DEFAULT);
// end::ccr-put-auto-follow-pattern-execute
// tag::ccr-put-auto-follow-pattern-response
boolean acknowledged = response.isAcknowledged(); // <1>
// end::ccr-put-auto-follow-pattern-response
// Delete auto follow pattern, so that we can store it again:
{
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
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-put-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-put-auto-follow-pattern-execute-async
client.ccr().putAutoFollowPatternAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-put-auto-follow-pattern-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
// Cleanup:
{
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));
}
public void testGetAutoFollowPattern() throws Exception {
RestHighLevelClient client = highLevelClient();
// Put auto follow pattern, so that we can get 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-get-auto-follow-pattern-request
GetAutoFollowPatternRequest request =
new GetAutoFollowPatternRequest("my_pattern"); // <1>
// end::ccr-get-auto-follow-pattern-request
// tag::ccr-get-auto-follow-pattern-execute
GetAutoFollowPatternResponse response = client.ccr()
.getAutoFollowPattern(request, RequestOptions.DEFAULT);
// end::ccr-get-auto-follow-pattern-execute
// tag::ccr-get-auto-follow-pattern-response
Map<String, Pattern> patterns = response.getPatterns();
Pattern pattern = patterns.get("my_pattern"); // <1>
pattern.getLeaderIndexPatterns();
// end::ccr-get-auto-follow-pattern-response
// tag::ccr-get-auto-follow-pattern-execute-listener
ActionListener<GetAutoFollowPatternResponse> listener =
new ActionListener<GetAutoFollowPatternResponse>() {
@Override
public void onResponse(GetAutoFollowPatternResponse
response) { // <1>
Map<String, Pattern> patterns = response.getPatterns();
Pattern pattern = patterns.get("my_pattern");
pattern.getLeaderIndexPatterns();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-get-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-get-auto-follow-pattern-execute-async
client.ccr().getAutoFollowPatternAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-get-auto-follow-pattern-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
// Cleanup:
{
DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
assertThat(deleteResponse.isAcknowledged(), is(true));
}
}
public void testPauseAutoFollowPattern() throws Exception {
final RestHighLevelClient client = highLevelClient();
{
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-pause-auto-follow-pattern-request
PauseAutoFollowPatternRequest request =
new PauseAutoFollowPatternRequest("my_pattern"); // <1>
// end::ccr-pause-auto-follow-pattern-request
// tag::ccr-pause-auto-follow-pattern-execute
AcknowledgedResponse response = client.ccr()
.pauseAutoFollowPattern(request, RequestOptions.DEFAULT);
// end::ccr-pause-auto-follow-pattern-execute
// tag::ccr-pause-auto-follow-pattern-response
boolean acknowledged = response.isAcknowledged(); // <1>
// end::ccr-pause-auto-follow-pattern-response
// tag::ccr-pause-auto-follow-pattern-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) { // <1>
boolean paused = response.isAcknowledged();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-pause-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-pause-auto-follow-pattern-execute-async
client.ccr().pauseAutoFollowPatternAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-pause-auto-follow-pattern-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
// Cleanup:
{
DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
assertThat(deleteResponse.isAcknowledged(), is(true));
}
}
public void testResumeAutoFollowPattern() throws Exception {
final RestHighLevelClient client = highLevelClient();
{
final PutAutoFollowPatternRequest putRequest =
new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*"));
AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT);
assertThat(putResponse.isAcknowledged(), is(true));
final PauseAutoFollowPatternRequest pauseRequest = new PauseAutoFollowPatternRequest("my_pattern");
AcknowledgedResponse pauseResponse = client.ccr().pauseAutoFollowPattern(pauseRequest, RequestOptions.DEFAULT);
assertThat(pauseResponse.isAcknowledged(), is(true));
}
// tag::ccr-resume-auto-follow-pattern-request
ResumeAutoFollowPatternRequest request =
new ResumeAutoFollowPatternRequest("my_pattern"); // <1>
// end::ccr-resume-auto-follow-pattern-request
// tag::ccr-resume-auto-follow-pattern-execute
AcknowledgedResponse response = client.ccr()
.resumeAutoFollowPattern(request, RequestOptions.DEFAULT);
// end::ccr-resume-auto-follow-pattern-execute
// tag::ccr-resume-auto-follow-pattern-response
boolean acknowledged = response.isAcknowledged(); // <1>
// end::ccr-resume-auto-follow-pattern-response
// tag::ccr-resume-auto-follow-pattern-execute-listener
ActionListener<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) { // <1>
boolean resumed = response.isAcknowledged();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-resume-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-resume-auto-follow-pattern-execute-async
client.ccr().resumeAutoFollowPatternAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-resume-auto-follow-pattern-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
// Cleanup:
{
DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern");
AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT);
assertThat(deleteResponse.isAcknowledged(), is(true));
}
}
public void testGetCCRStats() throws Exception {
RestHighLevelClient client = highLevelClient();
// tag::ccr-get-stats-request
CcrStatsRequest request =
new CcrStatsRequest(); // <1>
// end::ccr-get-stats-request
// tag::ccr-get-stats-execute
CcrStatsResponse response = client.ccr()
.getCcrStats(request, RequestOptions.DEFAULT);
// end::ccr-get-stats-execute
// tag::ccr-get-stats-response
IndicesFollowStats indicesFollowStats =
response.getIndicesFollowStats(); // <1>
AutoFollowStats autoFollowStats =
response.getAutoFollowStats(); // <2>
// end::ccr-get-stats-response
// tag::ccr-get-stats-execute-listener
ActionListener<CcrStatsResponse> listener =
new ActionListener<CcrStatsResponse>() {
@Override
public void onResponse(CcrStatsResponse response) { // <1>
IndicesFollowStats indicesFollowStats =
response.getIndicesFollowStats();
AutoFollowStats autoFollowStats =
response.getAutoFollowStats();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-get-stats-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-get-stats-execute-async
client.ccr().getCcrStatsAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-get-stats-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
public void testGetFollowStats() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// Create leader index:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
{
// Follow index, so that we can query for follow stats:
PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", "follower", ActiveShardCount.ONE);
PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
}
// tag::ccr-get-follow-stats-request
FollowStatsRequest request =
new FollowStatsRequest("follower"); // <1>
// end::ccr-get-follow-stats-request
// tag::ccr-get-follow-stats-execute
FollowStatsResponse response = client.ccr()
.getFollowStats(request, RequestOptions.DEFAULT);
// end::ccr-get-follow-stats-execute
// tag::ccr-get-follow-stats-response
IndicesFollowStats indicesFollowStats =
response.getIndicesFollowStats(); // <1>
// end::ccr-get-follow-stats-response
// tag::ccr-get-follow-stats-execute-listener
ActionListener<FollowStatsResponse> listener =
new ActionListener<FollowStatsResponse>() {
@Override
public void onResponse(FollowStatsResponse response) { // <1>
IndicesFollowStats indicesFollowStats =
response.getIndicesFollowStats();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-get-follow-stats-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-get-follow-stats-execute-async
client.ccr().getFollowStatsAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-get-follow-stats-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
{
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
}
}
public void testGetFollowInfos() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// Create leader index:
CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader");
CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertThat(response.isAcknowledged(), is(true));
}
{
// Follow index, so that we can query for follow stats:
PutFollowRequest putFollowRequest = new PutFollowRequest("local", "leader", "follower", ActiveShardCount.ONE);
PutFollowResponse putFollowResponse = client.ccr().putFollow(putFollowRequest, RequestOptions.DEFAULT);
assertThat(putFollowResponse.isFollowIndexCreated(), is(true));
assertThat(putFollowResponse.isFollowIndexShardsAcked(), is(true));
assertThat(putFollowResponse.isIndexFollowingStarted(), is(true));
}
// tag::ccr-get-follow-info-request
FollowInfoRequest request =
new FollowInfoRequest("follower"); // <1>
// end::ccr-get-follow-info-request
// tag::ccr-get-follow-info-execute
FollowInfoResponse response = client.ccr()
.getFollowInfo(request, RequestOptions.DEFAULT);
// end::ccr-get-follow-info-execute
// tag::ccr-get-follow-info-response
List<FollowInfoResponse.FollowerInfo> infos =
response.getInfos(); // <1>
// end::ccr-get-follow-info-response
// tag::ccr-get-follow-info-execute-listener
ActionListener<FollowInfoResponse> listener =
new ActionListener<FollowInfoResponse>() {
@Override
public void onResponse(FollowInfoResponse response) { // <1>
List<FollowInfoResponse.FollowerInfo> infos =
response.getInfos();
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ccr-get-follow-info-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-get-follow-info-execute-async
client.ccr().getFollowInfoAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ccr-get-follow-info-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
{
PauseFollowRequest pauseFollowRequest = new PauseFollowRequest("follower");
AcknowledgedResponse pauseFollowResponse = client.ccr().pauseFollow(pauseFollowRequest, RequestOptions.DEFAULT);
assertThat(pauseFollowResponse.isAcknowledged(), is(true));
}
}
}

View File

@ -122,8 +122,6 @@ def projectPathsToExclude = [
':test:logger-usage',
':x-pack:license-tools',
':x-pack:plugin:analytics',
':x-pack:plugin:ccr',
':x-pack:plugin:ccr:qa',
':x-pack:plugin:core',
':x-pack:plugin:deprecation',
':x-pack:plugin:frozen-indices',

View File

@ -528,15 +528,6 @@ public abstract class ESRestTestCase extends ESTestCase {
"watch-history-ilm-policy", "ml-size-based-ilm-policy", "logs", "metrics");
}
/**
* Returns whether to preserve auto-follow patterns. Defaults to not
* preserving them. Only runs at all if xpack is installed on the cluster
* being tested.
*/
protected boolean preserveAutoFollowPatternsUponCompletion() {
return false;
}
/**
* Returns whether to wait to make absolutely certain that all snapshots
* have been deleted.
@ -665,10 +656,6 @@ public abstract class ESRestTestCase extends ESTestCase {
deleteAllILMPolicies(preserveILMPolicyIds());
}
if (hasXPack && false == preserveAutoFollowPatternsUponCompletion()) {
deleteAllAutoFollowPatterns();
}
assertThat("Found in progress snapshots [" + inProgressSnapshots.get() + "].", inProgressSnapshots.get(), anEmptyMap());
}
@ -904,31 +891,6 @@ public abstract class ESRestTestCase extends ESTestCase {
}
}
private static void deleteAllAutoFollowPatterns() throws IOException {
final List<Map<?, ?>> patterns;
try {
Response response = adminClient().performRequest(new Request("GET", "/_ccr/auto_follow"));
patterns = (List<Map<?, ?>>) entityAsMap(response).get("patterns");
} catch (ResponseException e) {
if (RestStatus.METHOD_NOT_ALLOWED.getStatus() == e.getResponse().getStatusLine().getStatusCode() ||
RestStatus.BAD_REQUEST.getStatus() == e.getResponse().getStatusLine().getStatusCode()) {
// If bad request returned, CCR is not enabled.
return;
}
throw e;
}
if (patterns == null || patterns.isEmpty()) {
return;
}
for (Map<?, ?> pattern : patterns) {
String patternName = (String) pattern.get("name");
adminClient().performRequest(new Request("DELETE", "/_ccr/auto_follow/" + patternName));
}
}
/**
* Logs a message if there are still running tasks. The reasoning is that any tasks still running are state the is trying to bleed into
* other tests.