From de3cb3e374dbaee7741a0979dc90ef09d610fd27 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 2 Nov 2018 17:54:35 +0100 Subject: [PATCH 1/8] [CCR] Added support for pause follow API Relates to #33824 --- .../org/elasticsearch/client/CcrClient.java | 88 ++++++++++++ .../client/CcrRequestConverters.java | 35 +++++ .../client/RestHighLevelClient.java | 15 ++ .../client/ccr/PauseFollowRequest.java | 37 +++++ .../client/ccr/PauseFollowResponse.java | 40 ++++++ .../client/RestHighLevelClientTests.java | 3 +- .../client/ccr/PauseFollowResponseTests.java | 43 ++++++ .../documentation/CCRDocumentationIT.java | 136 ++++++++++++++++++ .../high-level/ccr/pause_follow.asciidoc | 35 +++++ .../high-level/supported-apis.asciidoc | 11 ++ 10 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowRequest.java create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java create mode 100644 docs/java-rest/high-level/ccr/pause_follow.asciidoc diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java new file mode 100644 index 0000000000000..32e2661399b57 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java @@ -0,0 +1,88 @@ +/* + * 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.PauseFollowRequest; +import org.elasticsearch.client.ccr.PauseFollowResponse; + +import java.io.IOException; +import java.util.Collections; + +/** + * A wrapper for the {@link RestHighLevelClient} that provides methods for + * accessing the Elastic ccr related methods + *

+ * See the + * X-Pack Rollup APIs on elastic.co for more information. + */ +public final class CcrClient { + + private final RestHighLevelClient restHighLevelClient; + + CcrClient(RestHighLevelClient restHighLevelClient) { + this.restHighLevelClient = restHighLevelClient; + } + + /** + * Instructs a follower index the pause the following of a leader index. + * + * See + * the docs 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 PauseFollowResponse pauseFollow(PauseFollowRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity( + request, + CcrRequestConverters::pauseFollow, + options, + PauseFollowResponse::fromXContent, + Collections.emptySet() + ); + } + + /** + * Asynchronously instruct a follower index the pause the following of a leader index. + * + * See + * the docs 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 void pauseFollowAsync(PauseFollowRequest request, + RequestOptions options, + ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity( + request, + CcrRequestConverters::pauseFollow, + options, + PauseFollowResponse::fromXContent, + listener, + Collections.emptySet()); + } + +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java new file mode 100644 index 0000000000000..bbab4f91a92f2 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java @@ -0,0 +1,35 @@ +/* + * 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.HttpPost; +import org.elasticsearch.client.ccr.PauseFollowRequest; + +final class CcrRequestConverters { + + 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); + } + +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index d8dce990a4d0b..b5eb93052c60f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -226,6 +226,7 @@ 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); /** * Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the @@ -319,6 +320,20 @@ public RollupClient rollup() { 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. + *

+ * See the + * CCR APIs on elastic.co 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. * diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowRequest.java new file mode 100644 index 0000000000000..44ac443542caf --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowRequest.java @@ -0,0 +1,37 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.ccr; + +import org.elasticsearch.client.Validatable; + +import java.util.Objects; + +public final class PauseFollowRequest implements Validatable { + + private final String followerIndex; + + public PauseFollowRequest(String followerIndex) { + this.followerIndex = Objects.requireNonNull(followerIndex); + } + + public String getFollowerIndex() { + return followerIndex; + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java new file mode 100644 index 0000000000000..c1103d9c3232d --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java @@ -0,0 +1,40 @@ +/* + * 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.rollup.AcknowledgedResponse; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.XContentParser; + +import java.io.IOException; + +public final class PauseFollowResponse extends AcknowledgedResponse { + + private static final ConstructingObjectParser PARSER = AcknowledgedResponse + .generateParser("pause_follow_response", PauseFollowResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME); + + public static PauseFollowResponse fromXContent(final XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + + public PauseFollowResponse(boolean acknowledged) { + super(acknowledged); + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index d6c77d6f2a5ae..54e418aeb0d0a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -786,7 +786,8 @@ public void testApiNamingConventions() throws Exception { apiName.startsWith("graph.") == false && apiName.startsWith("migration.") == false && apiName.startsWith("security.") == false && - apiName.startsWith("index_lifecycle.") == false) { + apiName.startsWith("index_lifecycle.") == false && + apiName.startsWith("ccr.") == false){ apiNotFound.add(apiName); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java new file mode 100644 index 0000000000000..1a40be1f3a9c1 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java @@ -0,0 +1,43 @@ +/* + * 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; +import org.elasticsearch.test.AbstractXContentTestCase; + +import java.io.IOException; + +public class PauseFollowResponseTests extends AbstractXContentTestCase { + + @Override + protected PauseFollowResponse createTestInstance() { + return new PauseFollowResponse(randomBoolean()); + } + + @Override + protected PauseFollowResponse doParseInstance(XContentParser parser) throws IOException { + return PauseFollowResponse.fromXContent(parser); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java new file mode 100644 index 0000000000000..f60719e5631a3 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java @@ -0,0 +1,136 @@ +/* + * 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.apache.http.util.EntityUtils; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.LatchedActionListener; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; +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.PauseFollowRequest; +import org.elasticsearch.client.ccr.PauseFollowResponse; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.json.JsonXContent; + +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +public class CCRDocumentationIT extends ESRestHighLevelClientTestCase { + + public void testPauseFollow() throws Exception { + RestHighLevelClient client = highLevelClient(); + + { + // Configure local cluster as remote cluster: + + // TODO: replace with nodes info highlevel rest client code when it is available: + final Request request = new Request("GET", "/_nodes"); + Map nodesResponse = (Map) toMap(client().performRequest(request)).get("nodes"); + // Select node info of first node (we don't know the node id): + nodesResponse = (Map) nodesResponse.get(nodesResponse.keySet().iterator().next()); + String transportAddress = (String) nodesResponse.get("transport_address"); + + ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); + updateSettingsRequest.transientSettings(Collections.singletonMap("cluster.remote.local.seeds", transportAddress)); + ClusterUpdateSettingsResponse updateSettingsResponse = + client.cluster().putSettings(updateSettingsRequest, RequestOptions.DEFAULT); + assertThat(updateSettingsResponse.isAcknowledged(), is(true)); + } + { + // Create leader index: + CreateIndexRequest createIndexRequest = new CreateIndexRequest("leader"); + createIndexRequest.settings(Collections.singletonMap("index.soft_deletes.enabled", true)); + CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); + assertThat(response.isAcknowledged(), is(true)); + } + String followIndex = "follower"; + // Follow index, so that it can be paused: + { + // TODO: Replace this with high level rest client code when put follow API is available: + final Request request = new Request("PUT", "/" + followIndex + "/_ccr/follow"); + request.setJsonEntity("{\"remote_cluster\": \"local\", \"leader_index\": \"leader\"}"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); + } + + // tag::ccr-pause-follow-request + PauseFollowRequest request = new PauseFollowRequest(followIndex); // <1> + // end::ccr-pause-follow-request + + // tag::ccr-pause-follow-execute + PauseFollowResponse 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 listener = new ActionListener() { + @Override + public void onResponse(PauseFollowResponse 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: + { + // TODO: Replace this with high level rest client code when resume follow API is available: + final Request req = new Request("POST", "/" + followIndex + "/_ccr/resume_follow"); + req.setJsonEntity("{}"); + Response res = client().performRequest(req); + assertThat(res.getStatusLine().getStatusCode(), equalTo(200)); + } + + // 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)); + } + + static Map toMap(Response response) throws IOException { + return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); + } + +} diff --git a/docs/java-rest/high-level/ccr/pause_follow.asciidoc b/docs/java-rest/high-level/ccr/pause_follow.asciidoc new file mode 100644 index 0000000000000..08acf7cadce8a --- /dev/null +++ b/docs/java-rest/high-level/ccr/pause_follow.asciidoc @@ -0,0 +1,35 @@ +-- +:api: ccr-pause-follow +:request: PauseFollowRequest +:response: PauseFollowResponse +-- + +[id="{upid}-{api}"] +=== Pause Follow API + + +[id="{upid}-{api}-request"] +==== Request + +The Pause Follow API allows you to pause following by follow index name. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[{api}-request] +-------------------------------------------------- +<1> The name of follow index. + +[id="{upid}-{api}-response"] +==== Response + +The returned +{response}+ indicates if the pause follow request was received. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[{api}-response] +-------------------------------------------------- +<1> Whether or not the pause follow was acknowledge. + +include::../execution.asciidoc[] + + diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 4411a6b375f91..3a0445cc2a5a5 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -389,3 +389,14 @@ don't leak into the rest of the documentation. :doc-tests-file!: :upid!: -- + +== CCR APIs + +:upid: {mainid}-ccr +:doc-tests-file: {doc-tests}/CCRDocumentationIT.java + +The Java High Level REST Client supports the following CCR APIs: + +* <<{upid}-ccr-pause-follow>> + +include::ccr/pause_follow.asciidoc[] From 2f4e2ed225d35a09d4f124cb31d20a602f04177c Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 2 Nov 2018 18:10:36 +0100 Subject: [PATCH 2/8] fixed checkstyle violations --- .../main/java/org/elasticsearch/client/CcrClient.java | 2 -- .../client/documentation/CCRDocumentationIT.java | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java index 32e2661399b57..44cd3a008afff 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java @@ -70,8 +70,6 @@ public PauseFollowResponse pauseFollow(PauseFollowRequest request, RequestOption * * @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 void pauseFollowAsync(PauseFollowRequest request, RequestOptions options, diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java index f60719e5631a3..7417f1059414e 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java @@ -88,7 +88,8 @@ public void testPauseFollow() throws Exception { // end::ccr-pause-follow-request // tag::ccr-pause-follow-execute - PauseFollowResponse response = client.ccr().pauseFollow(request, RequestOptions.DEFAULT); + PauseFollowResponse response = + client.ccr().pauseFollow(request, RequestOptions.DEFAULT); // end::ccr-pause-follow-execute // tag::ccr-pause-follow-response @@ -96,7 +97,8 @@ public void testPauseFollow() throws Exception { // end::ccr-pause-follow-response // tag::ccr-pause-follow-execute-listener - ActionListener listener = new ActionListener() { + ActionListener listener = + new ActionListener() { @Override public void onResponse(PauseFollowResponse response) { boolean acknowledged = response.isAcknowledged(); // <1> @@ -123,7 +125,8 @@ public void onFailure(Exception e) { listener = new LatchedActionListener<>(listener, latch); // tag::ccr-pause-follow-execute-async - client.ccr().pauseFollowAsync(request, RequestOptions.DEFAULT, listener); // <1> + client.ccr() + .pauseFollowAsync(request, RequestOptions.DEFAULT, listener); // <1> // end::ccr-pause-follow-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); From 7517fb8b1208814201b8a2aaadfa7711d61c10c9 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 6 Nov 2018 07:43:42 +0100 Subject: [PATCH 3/8] added space --- .../java/org/elasticsearch/client/RestHighLevelClientTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 54e418aeb0d0a..a6de67e098e5f 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -787,7 +787,7 @@ public void testApiNamingConventions() throws Exception { apiName.startsWith("migration.") == false && apiName.startsWith("security.") == false && apiName.startsWith("index_lifecycle.") == false && - apiName.startsWith("ccr.") == false){ + apiName.startsWith("ccr.") == false) { apiNotFound.add(apiName); } } From 3abf3353c56786498af29d64f1116a423909f55f Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 6 Nov 2018 07:45:22 +0100 Subject: [PATCH 4/8] moved `AcknowledgedResponse` to core package --- .../java/org/elasticsearch/client/ccr/PauseFollowResponse.java | 2 +- .../client/{rollup => core}/AcknowledgedResponse.java | 2 +- .../elasticsearch/client/rollup/DeleteRollupJobResponse.java | 1 + .../org/elasticsearch/client/rollup/PutRollupJobResponse.java | 1 + .../org/elasticsearch/client/rollup/StartRollupJobResponse.java | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) rename client/rest-high-level/src/main/java/org/elasticsearch/client/{rollup => core}/AcknowledgedResponse.java (98%) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java index c1103d9c3232d..0c55adfc0f655 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.client.ccr; -import org.elasticsearch.client.rollup.AcknowledgedResponse; +import org.elasticsearch.client.core.AcknowledgedResponse; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java similarity index 98% rename from client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java rename to client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java index 4e279844afc59..2d6fdb6f00b21 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.client.rollup; +package org.elasticsearch.client.core; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ConstructingObjectParser; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java index 35734c4a8358a..a4f2cd45a2a26 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java @@ -19,6 +19,7 @@ package org.elasticsearch.client.rollup; +import org.elasticsearch.client.core.AcknowledgedResponse; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java index 31c656b033479..6a93f364c68e6 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.client.rollup; +import org.elasticsearch.client.core.AcknowledgedResponse; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/StartRollupJobResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/StartRollupJobResponse.java index b953901ce0c84..be388ba8bc3b7 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/StartRollupJobResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/StartRollupJobResponse.java @@ -19,6 +19,7 @@ package org.elasticsearch.client.rollup; +import org.elasticsearch.client.core.AcknowledgedResponse; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; From 342310b0e60e6bb7ed435cabe596c5a1bec05007 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 6 Nov 2018 07:54:04 +0100 Subject: [PATCH 5/8] Made AcknowledgedResponse not abstract and provided a default parser, so that in cases when the field name is not overwritten then there is no need for a subclass. --- .../org/elasticsearch/client/CcrClient.java | 10 ++--- .../client/ccr/PauseFollowResponse.java | 40 ------------------- .../client/core/AcknowledgedResponse.java | 11 ++++- .../AcknowledgedResponseResponseTests.java} | 12 +++--- .../documentation/CCRDocumentationIT.java | 10 ++--- 5 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java rename client/rest-high-level/src/test/java/org/elasticsearch/client/{ccr/PauseFollowResponseTests.java => core/AcknowledgedResponseResponseTests.java} (72%) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java index 44cd3a008afff..2857ec970908a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java @@ -21,7 +21,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.ccr.PauseFollowRequest; -import org.elasticsearch.client.ccr.PauseFollowResponse; +import org.elasticsearch.client.core.AcknowledgedResponse; import java.io.IOException; import java.util.Collections; @@ -52,12 +52,12 @@ public final class CcrClient { * @return the response * @throws IOException in case there is a problem sending the request or parsing back the response */ - public PauseFollowResponse pauseFollow(PauseFollowRequest request, RequestOptions options) throws IOException { + public AcknowledgedResponse pauseFollow(PauseFollowRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity( request, CcrRequestConverters::pauseFollow, options, - PauseFollowResponse::fromXContent, + AcknowledgedResponse::fromXContent, Collections.emptySet() ); } @@ -73,12 +73,12 @@ public PauseFollowResponse pauseFollow(PauseFollowRequest request, RequestOption */ public void pauseFollowAsync(PauseFollowRequest request, RequestOptions options, - ActionListener listener) { + ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity( request, CcrRequestConverters::pauseFollow, options, - PauseFollowResponse::fromXContent, + AcknowledgedResponse::fromXContent, listener, Collections.emptySet()); } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java deleted file mode 100644 index 0c55adfc0f655..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ccr/PauseFollowResponse.java +++ /dev/null @@ -1,40 +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.core.AcknowledgedResponse; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.io.IOException; - -public final class PauseFollowResponse extends AcknowledgedResponse { - - private static final ConstructingObjectParser PARSER = AcknowledgedResponse - .generateParser("pause_follow_response", PauseFollowResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME); - - public static PauseFollowResponse fromXContent(final XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - public PauseFollowResponse(boolean acknowledged) { - super(acknowledged); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java index 2d6fdb6f00b21..50befeb79f39e 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; import java.util.Objects; @@ -31,9 +32,17 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; -public abstract class AcknowledgedResponse implements ToXContentObject { +public class AcknowledgedResponse implements ToXContentObject { protected static final String PARSE_FIELD_NAME = "acknowledged"; + + private static final ConstructingObjectParser PARSER = AcknowledgedResponse + .generateParser("acknowledged_response", AcknowledgedResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME); + + public static AcknowledgedResponse fromXContent(final XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + private final boolean acknowledged; public AcknowledgedResponse(final boolean acknowledged) { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseResponseTests.java similarity index 72% rename from client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseResponseTests.java index 1a40be1f3a9c1..016defb7f8425 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ccr/PauseFollowResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseResponseTests.java @@ -16,23 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.client.ccr; +package org.elasticsearch.client.core; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractXContentTestCase; import java.io.IOException; -public class PauseFollowResponseTests extends AbstractXContentTestCase { +public class AcknowledgedResponseResponseTests extends AbstractXContentTestCase { @Override - protected PauseFollowResponse createTestInstance() { - return new PauseFollowResponse(randomBoolean()); + protected AcknowledgedResponse createTestInstance() { + return new AcknowledgedResponse(randomBoolean()); } @Override - protected PauseFollowResponse doParseInstance(XContentParser parser) throws IOException { - return PauseFollowResponse.fromXContent(parser); + protected AcknowledgedResponse doParseInstance(XContentParser parser) throws IOException { + return AcknowledgedResponse.fromXContent(parser); } @Override diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java index 7417f1059414e..e61123f722f40 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CCRDocumentationIT.java @@ -32,7 +32,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.ccr.PauseFollowRequest; -import org.elasticsearch.client.ccr.PauseFollowResponse; +import org.elasticsearch.client.core.AcknowledgedResponse; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.json.JsonXContent; @@ -88,7 +88,7 @@ public void testPauseFollow() throws Exception { // end::ccr-pause-follow-request // tag::ccr-pause-follow-execute - PauseFollowResponse response = + AcknowledgedResponse response = client.ccr().pauseFollow(request, RequestOptions.DEFAULT); // end::ccr-pause-follow-execute @@ -97,10 +97,10 @@ public void testPauseFollow() throws Exception { // end::ccr-pause-follow-response // tag::ccr-pause-follow-execute-listener - ActionListener listener = - new ActionListener() { + ActionListener listener = + new ActionListener() { @Override - public void onResponse(PauseFollowResponse response) { + public void onResponse(AcknowledgedResponse response) { boolean acknowledged = response.isAcknowledged(); // <1> } From 5686daa8ebfd1429208f11e7439e9218a677ccac Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 6 Nov 2018 07:55:13 +0100 Subject: [PATCH 6/8] moved method --- .../elasticsearch/client/core/AcknowledgedResponse.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java index 50befeb79f39e..f46ea88d473d0 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/AcknowledgedResponse.java @@ -35,14 +35,9 @@ public class AcknowledgedResponse implements ToXContentObject { protected static final String PARSE_FIELD_NAME = "acknowledged"; - private static final ConstructingObjectParser PARSER = AcknowledgedResponse .generateParser("acknowledged_response", AcknowledgedResponse::new, AcknowledgedResponse.PARSE_FIELD_NAME); - public static AcknowledgedResponse fromXContent(final XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - private final boolean acknowledged; public AcknowledgedResponse(final boolean acknowledged) { @@ -59,6 +54,10 @@ protected static ConstructingObjectParser generateParser(String nam return p; } + public static AcknowledgedResponse fromXContent(final XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + @Override public boolean equals(Object o) { if (this == o) { From 4e3c5df8224d05e71fb1c1de11e9f60a2aa1e06a Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 7 Nov 2018 09:51:51 +0100 Subject: [PATCH 7/8] whoops --- ...esponseResponseTests.java => AcknowledgedResponseTests.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename client/rest-high-level/src/test/java/org/elasticsearch/client/core/{AcknowledgedResponseResponseTests.java => AcknowledgedResponseTests.java} (92%) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseTests.java similarity index 92% rename from client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseTests.java index 016defb7f8425..36ba953073987 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/AcknowledgedResponseTests.java @@ -23,7 +23,7 @@ import java.io.IOException; -public class AcknowledgedResponseResponseTests extends AbstractXContentTestCase { +public class AcknowledgedResponseTests extends AbstractXContentTestCase { @Override protected AcknowledgedResponse createTestInstance() { From 6102637e9d34a3fb15856a98399ee33e129949b8 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 7 Nov 2018 09:55:52 +0100 Subject: [PATCH 8/8] iter --- .../java/org/elasticsearch/client/CcrRequestConverters.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java index bbab4f91a92f2..c33ed5e4bf05d 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java @@ -27,7 +27,7 @@ final class CcrRequestConverters { static Request pauseFollow(PauseFollowRequest pauseFollowRequest) { String endpoint = new RequestConverters.EndpointBuilder() .addPathPart(pauseFollowRequest.getFollowerIndex()) - .addPathPartAsIs("_ccr/pause_follow") + .addPathPartAsIs("_ccr", "pause_follow") .build(); return new Request(HttpPost.METHOD_NAME, endpoint); }