|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.client; |
| 21 | + |
| 22 | +import org.elasticsearch.action.ActionListener; |
| 23 | +import org.elasticsearch.client.ccr.PauseFollowRequest; |
| 24 | +import org.elasticsearch.client.core.AcknowledgedResponse; |
| 25 | + |
| 26 | +import java.io.IOException; |
| 27 | +import java.util.Collections; |
| 28 | + |
| 29 | +/** |
| 30 | + * A wrapper for the {@link RestHighLevelClient} that provides methods for |
| 31 | + * accessing the Elastic ccr related methods |
| 32 | + * <p> |
| 33 | + * See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-apis.html"> |
| 34 | + * X-Pack Rollup APIs on elastic.co</a> for more information. |
| 35 | + */ |
| 36 | +public final class CcrClient { |
| 37 | + |
| 38 | + private final RestHighLevelClient restHighLevelClient; |
| 39 | + |
| 40 | + CcrClient(RestHighLevelClient restHighLevelClient) { |
| 41 | + this.restHighLevelClient = restHighLevelClient; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Instructs a follower index the pause the following of a leader index. |
| 46 | + * |
| 47 | + * See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.html"> |
| 48 | + * the docs</a> for more. |
| 49 | + * |
| 50 | + * @param request the request |
| 51 | + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized |
| 52 | + * @return the response |
| 53 | + * @throws IOException in case there is a problem sending the request or parsing back the response |
| 54 | + */ |
| 55 | + public AcknowledgedResponse pauseFollow(PauseFollowRequest request, RequestOptions options) throws IOException { |
| 56 | + return restHighLevelClient.performRequestAndParseEntity( |
| 57 | + request, |
| 58 | + CcrRequestConverters::pauseFollow, |
| 59 | + options, |
| 60 | + AcknowledgedResponse::fromXContent, |
| 61 | + Collections.emptySet() |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Asynchronously instruct a follower index the pause the following of a leader index. |
| 67 | + * |
| 68 | + * See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.html"> |
| 69 | + * the docs</a> for more. |
| 70 | + * |
| 71 | + * @param request the request |
| 72 | + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized |
| 73 | + */ |
| 74 | + public void pauseFollowAsync(PauseFollowRequest request, |
| 75 | + RequestOptions options, |
| 76 | + ActionListener<AcknowledgedResponse> listener) { |
| 77 | + restHighLevelClient.performRequestAsyncAndParseEntity( |
| 78 | + request, |
| 79 | + CcrRequestConverters::pauseFollow, |
| 80 | + options, |
| 81 | + AcknowledgedResponse::fromXContent, |
| 82 | + listener, |
| 83 | + Collections.emptySet()); |
| 84 | + } |
| 85 | + |
| 86 | +} |
0 commit comments