From a47e4325ebf0363adc4edf8d12f0ef9dbf8f4393 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Wed, 24 Oct 2018 17:39:23 +0200 Subject: [PATCH 01/10] HLRC: migration api - upgrade Implement high level client for migration upgrade API. It should wrap RestHighLevelClient and expose high level IndexUpgradeRequest (new), IndexTaskResponse for submissions with wait_for_completion=false and BulkByScrollResponse (already used) objects. refers: #29827 --- .../elasticsearch/client/MigrationClient.java | 21 ++++ .../client/MigrationRequestConverters.java | 23 +++++ .../client/RequestConverters.java | 5 +- .../client/migration/IndexUpgradeRequest.java | 92 ++++++++++++++++++ .../IndexUpgradeSubmissionResponse.java | 96 +++++++++++++++++++ .../org/elasticsearch/client/MigrationIT.java | 56 ++++++++++- .../MigrationClientDocumentationIT.java | 82 +++++++++++++++- .../high-level/migration/upgrade.asciidoc | 79 +++++++++++++++ .../high-level/supported-apis.asciidoc | 2 + 9 files changed, 446 insertions(+), 10 deletions(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java create mode 100644 docs/java-rest/high-level/migration/upgrade.asciidoc diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java index 15bf71bc8db8f..d0dba8942ce57 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java @@ -21,6 +21,11 @@ import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.elasticsearch.client.migration.IndexUpgradeRequest; + import java.io.IOException; import java.util.Collections; @@ -52,4 +57,20 @@ public IndexUpgradeInfoResponse getAssistance(IndexUpgradeInfoRequest request, R return restHighLevelClient.performRequestAndParseEntity(request, MigrationRequestConverters::getMigrationAssistance, options, IndexUpgradeInfoResponse::fromXContent, Collections.emptySet()); } + + public BulkByScrollResponse upgrade(IndexUpgradeRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, MigrationRequestConverters::migrate, options, + BulkByScrollResponse::fromXContent, Collections.emptySet()); + } + + public IndexUpgradeSubmissionResponse submitUpgradeTask(IndexUpgradeRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, MigrationRequestConverters::submitMigrateTask, options, + IndexUpgradeSubmissionResponse::fromXContent, Collections.emptySet()); + } + + + public void upgradeAsync(IndexUpgradeRequest request, RequestOptions options, ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, MigrationRequestConverters::migrate, options, + BulkByScrollResponse::fromXContent, listener, Collections.emptySet()); + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java index 50d21f844d4e3..20935b0e07048 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java @@ -20,6 +20,8 @@ package org.elasticsearch.client; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.elasticsearch.client.migration.IndexUpgradeRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; final class MigrationRequestConverters { @@ -36,4 +38,25 @@ static Request getMigrationAssistance(IndexUpgradeInfoRequest indexUpgradeInfoRe parameters.withIndicesOptions(indexUpgradeInfoRequest.indicesOptions()); return request; } + + static Request migrate(IndexUpgradeRequest indexUpgradeRequest) { + return prepareMigrateRequest(indexUpgradeRequest, true); + } + + static Request submitMigrateTask(IndexUpgradeRequest indexUpgradeRequest) { + return prepareMigrateRequest(indexUpgradeRequest, false); + } + + private static Request prepareMigrateRequest(IndexUpgradeRequest indexUpgradeRequest, boolean waitForCompletion) { + RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder() + .addPathPartAsIs("_xpack/migration/upgrade") + .addCommaSeparatedPathParts(indexUpgradeRequest.indices()); + String endpoint = endpointBuilder.build(); + Request request = new Request(HttpPost.METHOD_NAME, endpoint); + + RequestConverters.Params params = new RequestConverters.Params(request); + params.withWaitForCompletion(waitForCompletion); + + return request; + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 3acb8d8297306..c10a9a070ca73 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -886,10 +886,7 @@ Params withDetailed(boolean detailed) { } Params withWaitForCompletion(boolean waitForCompletion) { - if (waitForCompletion) { - return putParam("wait_for_completion", Boolean.TRUE.toString()); - } - return this; + return putParam("wait_for_completion", Boolean.toString(waitForCompletion)); } Params withNodes(String[] nodes) { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java new file mode 100644 index 0000000000000..fe7b7a0e23e70 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java @@ -0,0 +1,92 @@ +/* + * 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.migration; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.IndicesRequest; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.action.support.master.MasterNodeReadRequest; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; + +public class IndexUpgradeRequest extends MasterNodeReadRequest implements IndicesRequest { + + private String[] indices ; + private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true); + + public IndexUpgradeRequest(String index) { + indices = new String[]{index}; + } + + public IndexUpgradeRequest(StreamInput in) throws IOException { + super(in); + indices = in.readStringArray(); + indicesOptions = IndicesOptions.readIndicesOptions(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringArray(indices); + indicesOptions.writeIndicesOptions(out); + } + + @Override + public String[] indices() { + return indices; + } + + + @Override + public IndicesOptions indicesOptions() { + return indicesOptions; + } + + public void indicesOptions(IndicesOptions indicesOptions) { + this.indicesOptions = indicesOptions; + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + IndexUpgradeRequest request = (IndexUpgradeRequest) o; + return Arrays.equals(indices, request.indices) && + Objects.equals(indicesOptions.toString(), request.indicesOptions.toString()); + } + + @Override + public int hashCode() { + return Objects.hash(Arrays.hashCode(indices), indicesOptions.toString()); + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java new file mode 100644 index 0000000000000..7c0aefc722f7d --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java @@ -0,0 +1,96 @@ +/* + * 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.migration; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.tasks.TaskId; + +import java.io.IOException; +import java.util.Objects; + +/** + * Response object that contains the taskID from submitted IndexUpgradeRequest + */ +public class IndexUpgradeSubmissionResponse extends ActionResponse implements ToXContentObject { + + private static final ParseField TASK = new ParseField("task"); + + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "upgrade_submission_response", + true, a-> new IndexUpgradeSubmissionResponse( (TaskId) a[0])); + + static { + PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), TaskId.parser(), TASK, ObjectParser.ValueType.STRING); + } + + public static IndexUpgradeSubmissionResponse fromXContent(XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + + private final TaskId task; + + IndexUpgradeSubmissionResponse(@Nullable TaskId task) { + this.task = task; + } + + + /** + * Get the task id + * @return the id of the upgrade task. + */ + public TaskId getTask() { + return task; + } + + @Override + public int hashCode() { + return Objects.hash(task); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (other == null || getClass() != other.getClass()) { + return false; + } + + IndexUpgradeSubmissionResponse that = (IndexUpgradeSubmissionResponse) other; + return Objects.equals(task, that.task); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + if (task != null) { + builder.field(TASK.getPreferredName(), task.toString()); + } + builder.endObject(); + return builder; + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java index f83986829d529..0e60e1c99134d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java @@ -19,25 +19,71 @@ package org.elasticsearch.client; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; +import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.client.migration.IndexUpgradeRequest; +import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; + import java.io.IOException; +import java.util.function.BooleanSupplier; + +import static org.hamcrest.Matchers.containsString; public class MigrationIT extends ESRestHighLevelClientTestCase { public void testGetAssistance() throws IOException { - RestHighLevelClient client = highLevelClient(); { - IndexUpgradeInfoResponse response = client.migration().getAssistance(new IndexUpgradeInfoRequest(), RequestOptions.DEFAULT); + IndexUpgradeInfoResponse response = highLevelClient().migration() + .getAssistance(new IndexUpgradeInfoRequest(), RequestOptions.DEFAULT); assertEquals(0, response.getActions().size()); } { - client.indices().create(new CreateIndexRequest("test"), RequestOptions.DEFAULT); - IndexUpgradeInfoResponse response = client.migration().getAssistance( + createIndex("test", Settings.EMPTY); + IndexUpgradeInfoResponse response = highLevelClient().migration().getAssistance( new IndexUpgradeInfoRequest("test"), RequestOptions.DEFAULT); assertEquals(0, response.getActions().size()); } } + + public void testUpgrade() throws IOException { + createIndex("test", Settings.EMPTY); + + ThrowingRunnable execute = () -> execute(new IndexUpgradeRequest("test"), + highLevelClient().migration()::upgrade, + highLevelClient().migration()::upgradeAsync); + + ElasticsearchStatusException responseException = expectThrows(ElasticsearchStatusException.class, execute); + + assertThat(responseException.getDetailedMessage(), containsString("cannot be upgraded")); + } + + public void testUpgradeWithTaskApi() throws IOException, InterruptedException { + createIndex("test", Settings.EMPTY); + + IndexUpgradeRequest request = new IndexUpgradeRequest("test"); + + IndexUpgradeSubmissionResponse upgrade = highLevelClient().migration() + .submitUpgradeTask(request, RequestOptions.DEFAULT); + + assertNotNull(upgrade.getTask()); + + BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(upgrade); + awaitBusy(hasUpgradeCompleted); + } + + private BooleanSupplier checkCompletionStatus(IndexUpgradeSubmissionResponse upgrade) { + return () -> { + try { + Response response = client().performRequest(new Request("GET", "/_tasks/" + upgrade.getTask().toString())); + return (boolean) entityAsMap(response).get("completed"); + } catch (IOException e) { + e.printStackTrace(); + fail(); + return false; + } + }; + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java index 57f8a8314fa97..21865087a45ca 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java @@ -19,17 +19,29 @@ package org.elasticsearch.client.documentation; +import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.LatchedActionListener; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.ESRestHighLevelClientTestCase; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.common.Strings; import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; +import org.elasticsearch.client.migration.IndexUpgradeRequest; import org.elasticsearch.client.migration.UpgradeActionRequired; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; +import org.elasticsearch.tasks.TaskId; import java.io.IOException; import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.Matchers.containsString; /** * This class is used to generate the Java Migration API documentation. @@ -80,4 +92,72 @@ public void testGetAssistance() throws IOException { } // end::get-assistance-response } + + public void testUpgrade() throws IOException { + + RestHighLevelClient client = highLevelClient(); + createIndex("test", Settings.EMPTY); + + + // tag::upgrade-request + IndexUpgradeRequest request = new IndexUpgradeRequest("test"); // <1> + // end::upgrade-request + + // tag::upgrade-request-indices-options + request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> + // end::upgrade-request-indices-options + try { + + // tag::upgrade-execute + BulkByScrollResponse response = client.migration().upgrade(request, RequestOptions.DEFAULT); + // end::upgrade-execute + + }catch(ElasticsearchStatusException e){ + assertThat(e.getMessage(), containsString("cannot be upgraded")); + } + } + + + public void testUpgradeAsync() throws IOException, InterruptedException { + RestHighLevelClient client = highLevelClient(); + createIndex("test", Settings.EMPTY); + final CountDownLatch latch = new CountDownLatch(1); + + // tag::upgrade-async-listener + ActionListener listener = new ActionListener() { + @Override + public void onResponse(BulkByScrollResponse bulkResponse) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::upgrade-async-listener + + listener = new LatchedActionListener<>(listener, latch); + + // tag::upgrade-async-execute + client.migration().upgradeAsync(new IndexUpgradeRequest("test"), RequestOptions.DEFAULT, listener); // <1> + // end::upgrade-async-execute + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + + } + + public void testUpgradeWithTaskApi() throws IOException, InterruptedException { + createIndex("test", Settings.EMPTY); + RestHighLevelClient client = highLevelClient(); + // tag::upgrade-task-api + IndexUpgradeRequest request = new IndexUpgradeRequest("test"); + + IndexUpgradeSubmissionResponse response = client.migration() + .submitUpgradeTask(request, RequestOptions.DEFAULT); + TaskId taskId = response.getTask(); + // end::upgrade-task-api + assertNotNull(taskId); + + } } diff --git a/docs/java-rest/high-level/migration/upgrade.asciidoc b/docs/java-rest/high-level/migration/upgrade.asciidoc new file mode 100644 index 0000000000000..33da3e2192f2b --- /dev/null +++ b/docs/java-rest/high-level/migration/upgrade.asciidoc @@ -0,0 +1,79 @@ +[[java-rest-high-migration-upgrade]] +=== Migration Upgrade + +[[java-rest-high-migraton-upgrade-request]] +==== Index Upgrade Request + +An `IndexUpgradeRequest` requires an index argument. Only one index at the time should be upgraded: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-request] +-------------------------------------------------- +<1> Create a new request instance + +==== Optional arguments +The following arguments can optionally be provided: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-request-indices-options] +-------------------------------------------------- +<1> Set the `IndicesOptions` to control how unavailable indices are resolved and +how wildcard expressions are expanded + +[[java-rest-high-migration-upgrade-execution]] +==== Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-execute] +-------------------------------------------------- + +[[java-rest-high-migration-upgrade-response]] +==== Response +The returned `BulkByScrollResponse` contains information about the executed operation + + +[[java-rest-high-migraton-async-upgrade-request]] +==== Asynchronous Execution + +The asynchronous execution of a upgrade request requires both the `IndexUpgradeRequest` +instance and an `ActionListener` instance to be passed to the asynchronous +method: + +A typical listener for `BulkResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-async-listener] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument and contains a list of individual results for each +operation that was executed. Note that one or more operations might have +failed while the others have been successfully executed. +<2> Called when the whole `IndexUpgradeRequest` fails. In this case the raised +exception is provided as an argument and no operation has been executed. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-async-execute] +-------------------------------------------------- +<1> The `IndexUpgradeRequest` to execute and the `ActionListener` to use when +the execution completes + +The asynchronous method does not block and returns immediately. Once it is +completed the `ActionListener` is called back using the `onResponse` method +if the execution successfully completed or using the `onFailure` method if +it failed. + + +=== Migration Upgrade with Task API +Submission of upgrade request task will requires the `IndexUpgradeRequest` and will return +`IndexUpgradeSubmissionResponse`. The `IndexUpgradeSubmissionResponse` can later be use to fetch +TaskId and query the Task API for results. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-task-api] +-------------------------------------------------- diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index b7f4cba952083..d952b36169453 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -292,8 +292,10 @@ include::ml/delete-calendar.asciidoc[] The Java High Level REST Client supports the following Migration APIs: * <> +* <> include::migration/get-assistance.asciidoc[] +include::migration/upgrade.asciidoc[] == Rollup APIs From ff3ddd18ce20d0b08401bf6d99de29af8042c78b Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 2 Nov 2018 07:54:09 +0100 Subject: [PATCH 02/10] fix exception handling --- .../src/test/java/org/elasticsearch/client/MigrationIT.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java index 0e60e1c99134d..0c05d3d650ba8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java @@ -80,8 +80,7 @@ private BooleanSupplier checkCompletionStatus(IndexUpgradeSubmissionResponse upg Response response = client().performRequest(new Request("GET", "/_tasks/" + upgrade.getTask().toString())); return (boolean) entityAsMap(response).get("completed"); } catch (IOException e) { - e.printStackTrace(); - fail(); + fail(e.getMessage()); return false; } }; From 1af129cbac848a775d504e6797592af6ce41d916 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Fri, 2 Nov 2018 12:13:40 +0100 Subject: [PATCH 03/10] fix failing tests due to wait_for_completion changes --- .../SnapshotRequestConvertersTests.java | 66 +++++++++---------- .../client/TasksRequestConvertersTests.java | 10 ++- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotRequestConvertersTests.java index efd321aa7ee34..ca86a9120422b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotRequestConvertersTests.java @@ -51,7 +51,7 @@ import static org.hamcrest.Matchers.nullValue; public class SnapshotRequestConvertersTests extends ESTestCase { - + public void testGetRepositories() { Map expectedParams = new HashMap<>(); StringBuilder endpoint = new StringBuilder("/_snapshot"); @@ -61,14 +61,14 @@ public void testGetRepositories() { RequestConvertersTests.setRandomLocal(getRepositoriesRequest, expectedParams); if (randomBoolean()) { - String[] entries = new String[] { "a", "b", "c" }; + String[] entries = new String[]{"a", "b", "c"}; getRepositoriesRequest.repositories(entries); endpoint.append("/" + String.join(",", entries)); } Request request = SnapshotRequestConverters.getRepositories(getRepositoriesRequest); - assertThat(endpoint.toString(), equalTo(request.getEndpoint())); - assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); + assertThat(request.getEndpoint(), equalTo(endpoint.toString())); + assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); assertThat(expectedParams, equalTo(request.getParameters())); } @@ -88,8 +88,8 @@ public void testCreateRepository() throws IOException { .build()); Request request = SnapshotRequestConverters.createRepository(putRepositoryRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpPut.METHOD_NAME, equalTo(request.getMethod())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME)); RequestConvertersTests.assertToXContentBody(putRepositoryRequest, request.getEntity()); } @@ -105,9 +105,9 @@ public void testDeleteRepository() { RequestConvertersTests.setRandomTimeout(deleteRepositoryRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); Request request = SnapshotRequestConverters.deleteRepository(deleteRepositoryRequest); - assertThat(endpoint.toString(), equalTo(request.getEndpoint())); - assertThat(HttpDelete.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint.toString())); + assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); assertNull(request.getEntity()); } @@ -121,9 +121,9 @@ public void testVerifyRepository() { RequestConvertersTests.setRandomTimeout(verifyRepositoryRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); Request request = SnapshotRequestConverters.verifyRepository(verifyRepositoryRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpPost.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); } public void testCreateSnapshot() throws IOException { @@ -137,14 +137,12 @@ public void testCreateSnapshot() throws IOException { Boolean waitForCompletion = randomBoolean(); createSnapshotRequest.waitForCompletion(waitForCompletion); - if (waitForCompletion) { - expectedParams.put("wait_for_completion", waitForCompletion.toString()); - } + expectedParams.put("wait_for_completion", waitForCompletion.toString()); Request request = SnapshotRequestConverters.createSnapshot(createSnapshotRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpPut.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); RequestConvertersTests.assertToXContentBody(createSnapshotRequest, request.getEntity()); } @@ -178,9 +176,9 @@ public void testGetSnapshots() { } Request request = SnapshotRequestConverters.getSnapshots(getSnapshotsRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); assertNull(request.getEntity()); } @@ -202,9 +200,9 @@ public void testGetAllSnapshots() { expectedParams.put("verbose", Boolean.toString(verbose)); Request request = SnapshotRequestConverters.getSnapshots(getSnapshotsRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); assertNull(request.getEntity()); } @@ -239,10 +237,10 @@ public void testRestoreSnapshot() throws IOException { RestoreSnapshotRequest restoreSnapshotRequest = new RestoreSnapshotRequest(repository, snapshot); RequestConvertersTests.setRandomMasterTimeout(restoreSnapshotRequest, expectedParams); - if (randomBoolean()) { - restoreSnapshotRequest.waitForCompletion(true); - expectedParams.put("wait_for_completion", "true"); - } + boolean waitForCompletion = randomBoolean(); + restoreSnapshotRequest.waitForCompletion(waitForCompletion); + expectedParams.put("wait_for_completion", Boolean.toString(waitForCompletion)); + if (randomBoolean()) { String timeout = randomTimeValue(); restoreSnapshotRequest.masterNodeTimeout(timeout); @@ -250,9 +248,9 @@ public void testRestoreSnapshot() throws IOException { } Request request = SnapshotRequestConverters.restoreSnapshot(restoreSnapshotRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpPost.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); RequestConvertersTests.assertToXContentBody(restoreSnapshotRequest, request.getEntity()); } @@ -269,9 +267,9 @@ public void testDeleteSnapshot() { RequestConvertersTests.setRandomMasterTimeout(deleteSnapshotRequest, expectedParams); Request request = SnapshotRequestConverters.deleteSnapshot(deleteSnapshotRequest); - assertThat(endpoint, equalTo(request.getEndpoint())); - assertThat(HttpDelete.METHOD_NAME, equalTo(request.getMethod())); - assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getEndpoint(), equalTo(endpoint)); + assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME)); + assertThat(request.getParameters(), equalTo(expectedParams)); assertNull(request.getEntity()); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksRequestConvertersTests.java index ff6726faee18d..4b7889d3b7e7a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksRequestConvertersTests.java @@ -62,12 +62,10 @@ public void testListTasks() { expectedParams.put("detailed", "true"); } } - if (randomBoolean()) { - request.setWaitForCompletion(randomBoolean()); - if (request.getWaitForCompletion()) { - expectedParams.put("wait_for_completion", "true"); - } - } + + request.setWaitForCompletion(randomBoolean()); + expectedParams.put("wait_for_completion", Boolean.toString(request.getWaitForCompletion())); + if (randomBoolean()) { String timeout = randomTimeValue(); request.setTimeout(timeout); From b6683d12a39e48dfbb56f00a23ac34d5e71ad124 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Sat, 3 Nov 2018 16:44:05 +0100 Subject: [PATCH 04/10] javadocs and cleanup --- .../migration/IndexUpgradeInfoRequest.java | 4 ++++ .../migration/IndexUpgradeInfoResponse.java | 3 +++ .../client/migration/IndexUpgradeRequest.java | 4 ++++ .../IndexUpgradeSubmissionResponse.java | 16 +--------------- .../org/elasticsearch/client/MigrationIT.java | 11 +++++++---- .../MigrationClientDocumentationIT.java | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoRequest.java index fb37a449435f4..7a93bce1376b5 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoRequest.java @@ -26,6 +26,10 @@ import java.util.Arrays; import java.util.Objects; +/** + * A request for retrieving upgrade information + * Part of Migration API + */ public class IndexUpgradeInfoRequest extends TimedRequest implements IndicesRequest.Replaceable { private String[] indices = Strings.EMPTY_ARRAY; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoResponse.java index a9af1e36cc258..29b0b1907969b 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeInfoResponse.java @@ -28,6 +28,9 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; +/** + * Response object that contains information about indices to be upgraded + */ public class IndexUpgradeInfoResponse { private static final ParseField INDICES = new ParseField("indices"); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java index fe7b7a0e23e70..ba27321f287db 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java @@ -29,6 +29,10 @@ import java.util.Arrays; import java.util.Objects; +/** + * A request for performing Upgrade on Index + * Part of Migration API + */ public class IndexUpgradeRequest extends MasterNodeReadRequest implements IndicesRequest { private String[] indices ; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java index 7c0aefc722f7d..6f7bb42735daf 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java @@ -18,13 +18,10 @@ */ package org.elasticsearch.client.migration; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.tasks.TaskId; @@ -34,7 +31,7 @@ /** * Response object that contains the taskID from submitted IndexUpgradeRequest */ -public class IndexUpgradeSubmissionResponse extends ActionResponse implements ToXContentObject { +public class IndexUpgradeSubmissionResponse { private static final ParseField TASK = new ParseField("task"); @@ -56,7 +53,6 @@ public static IndexUpgradeSubmissionResponse fromXContent(XContentParser parser) this.task = task; } - /** * Get the task id * @return the id of the upgrade task. @@ -83,14 +79,4 @@ public boolean equals(Object other) { IndexUpgradeSubmissionResponse that = (IndexUpgradeSubmissionResponse) other; return Objects.equals(task, that.task); } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - if (task != null) { - builder.field(TASK.getPreferredName(), task.toString()); - } - builder.endObject(); - return builder; - } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java index 0c05d3d650ba8..d5b29a86361b7 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java @@ -19,13 +19,12 @@ package org.elasticsearch.client; +import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; -import org.elasticsearch.ElasticsearchStatusException; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.client.migration.IndexUpgradeRequest; import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; - +import org.elasticsearch.common.settings.Settings; import java.io.IOException; import java.util.function.BooleanSupplier; @@ -48,7 +47,7 @@ public void testGetAssistance() throws IOException { } } - public void testUpgrade() throws IOException { + public void testUpgradeWhenIndexCannotBeUpgraded() throws IOException { createIndex("test", Settings.EMPTY); ThrowingRunnable execute = () -> execute(new IndexUpgradeRequest("test"), @@ -74,6 +73,10 @@ public void testUpgradeWithTaskApi() throws IOException, InterruptedException { awaitBusy(hasUpgradeCompleted); } + /** + * Using low-level api as high-level-rest-client's getTaskById work is in progress. + * TODO revisit once that work is finished + */ private BooleanSupplier checkCompletionStatus(IndexUpgradeSubmissionResponse upgrade) { return () -> { try { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java index 21865087a45ca..f71e4bce4800b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java @@ -112,7 +112,7 @@ public void testUpgrade() throws IOException { BulkByScrollResponse response = client.migration().upgrade(request, RequestOptions.DEFAULT); // end::upgrade-execute - }catch(ElasticsearchStatusException e){ + } catch (ElasticsearchStatusException e) { assertThat(e.getMessage(), containsString("cannot be upgraded")); } } @@ -147,7 +147,7 @@ public void onFailure(Exception e) { } - public void testUpgradeWithTaskApi() throws IOException, InterruptedException { + public void testUpgradeWithTaskApi() throws IOException { createIndex("test", Settings.EMPTY); RestHighLevelClient client = highLevelClient(); // tag::upgrade-task-api From bcb8f38c85a451d3d48c14646b626da99bd21403 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 5 Nov 2018 11:00:52 +0100 Subject: [PATCH 05/10] add response parsing test --- .../IndexUpgradeSubmissionResponseTests.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java new file mode 100644 index 0000000000000..e0c4ad0f8088a --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java @@ -0,0 +1,51 @@ +/* + * 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.migration; + +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.tasks.TaskId; +import org.elasticsearch.test.ESTestCase; + +import java.io.IOException; + +import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; + +public class IndexUpgradeSubmissionResponseTests extends ESTestCase { + public void testFromXContent() throws IOException { + xContentTester( + this::createParser, + this::createTestInstance, + this::toXContent, + IndexUpgradeSubmissionResponse::fromXContent) + .supportsUnknownFields(true) + .test(); + } + + private void toXContent(IndexUpgradeSubmissionResponse response, XContentBuilder xContentBuilder) throws IOException { + xContentBuilder.startObject(); + xContentBuilder.field("task", response.getTask().toString()); + xContentBuilder.endObject(); + } + + private IndexUpgradeSubmissionResponse createTestInstance() { + TaskId taskId = new TaskId(randomAlphaOfLength(5), randomLong()); + return new IndexUpgradeSubmissionResponse(taskId); + } +} From 0deb3c1401cf65269c15f65038c15737840e6728 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 6 Nov 2018 12:08:34 +0100 Subject: [PATCH 06/10] review follow up --- .../elasticsearch/client/MigrationClient.java | 1 - .../client/migration/IndexUpgradeRequest.java | 37 +++---------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java index d0dba8942ce57..9afaffd3d81b0 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java @@ -68,7 +68,6 @@ public IndexUpgradeSubmissionResponse submitUpgradeTask(IndexUpgradeRequest requ IndexUpgradeSubmissionResponse::fromXContent, Collections.emptySet()); } - public void upgradeAsync(IndexUpgradeRequest request, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, MigrationRequestConverters::migrate, options, BulkByScrollResponse::fromXContent, listener, Collections.emptySet()); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java index ba27321f287db..f039fe1a46071 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java @@ -18,14 +18,10 @@ */ package org.elasticsearch.client.migration; -import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.MasterNodeReadRequest; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.client.TimedRequest; -import java.io.IOException; import java.util.Arrays; import java.util.Objects; @@ -33,34 +29,21 @@ * A request for performing Upgrade on Index * Part of Migration API */ -public class IndexUpgradeRequest extends MasterNodeReadRequest implements IndicesRequest { - private String[] indices ; +public class IndexUpgradeRequest extends TimedRequest implements IndicesRequest { + + private String[] indices; private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true); public IndexUpgradeRequest(String index) { indices = new String[]{index}; } - public IndexUpgradeRequest(StreamInput in) throws IOException { - super(in); - indices = in.readStringArray(); - indicesOptions = IndicesOptions.readIndicesOptions(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeStringArray(indices); - indicesOptions.writeIndicesOptions(out); - } - @Override public String[] indices() { return indices; } - @Override public IndicesOptions indicesOptions() { return indicesOptions; @@ -70,23 +53,13 @@ public void indicesOptions(IndicesOptions indicesOptions) { this.indicesOptions = indicesOptions; } - @Override - public ActionRequestValidationException validate() { - return null; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IndexUpgradeRequest request = (IndexUpgradeRequest) o; return Arrays.equals(indices, request.indices) && - Objects.equals(indicesOptions.toString(), request.indicesOptions.toString()); + Objects.equals(indicesOptions.toString(), request.indicesOptions.toString()); } @Override From e63914f786156db5b0be5fa8af55cabe1fc3d6cd Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Wed, 7 Nov 2018 11:23:20 +0100 Subject: [PATCH 07/10] remove unused line --- .../org/elasticsearch/client/migration/IndexUpgradeRequest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java index f039fe1a46071..7cafe9b5c5287 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java @@ -29,7 +29,6 @@ * A request for performing Upgrade on Index * Part of Migration API */ - public class IndexUpgradeRequest extends TimedRequest implements IndicesRequest { private String[] indices; From a71d5c82f907429e499008ac138623e2c3c9915c Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 8 Nov 2018 13:34:17 +0100 Subject: [PATCH 08/10] refactor returned type and request --- .../elasticsearch/client/MigrationClient.java | 6 +- .../client/MigrationRequestConverters.java | 14 ++-- .../client/migration/IndexUpgradeRequest.java | 28 +++---- .../IndexUpgradeSubmissionResponse.java | 82 ------------------- .../org/elasticsearch/client/MigrationIT.java | 8 +- .../MigrationClientDocumentationIT.java | 13 ++- .../IndexUpgradeSubmissionResponseTests.java | 51 ------------ 7 files changed, 33 insertions(+), 169 deletions(-) delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java index 9afaffd3d81b0..a317e461b676c 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java @@ -22,7 +22,7 @@ import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; +import org.elasticsearch.client.tasks.TaskSubmissionResponse; import org.elasticsearch.index.reindex.BulkByScrollResponse; import org.elasticsearch.client.migration.IndexUpgradeRequest; @@ -63,9 +63,9 @@ public BulkByScrollResponse upgrade(IndexUpgradeRequest request, RequestOptions BulkByScrollResponse::fromXContent, Collections.emptySet()); } - public IndexUpgradeSubmissionResponse submitUpgradeTask(IndexUpgradeRequest request, RequestOptions options) throws IOException { + public TaskSubmissionResponse submitUpgradeTask(IndexUpgradeRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity(request, MigrationRequestConverters::submitMigrateTask, options, - IndexUpgradeSubmissionResponse::fromXContent, Collections.emptySet()); + TaskSubmissionResponse::fromXContent, Collections.emptySet()); } public void upgradeAsync(IndexUpgradeRequest request, RequestOptions options, ActionListener listener) { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java index 20935b0e07048..52cab21304812 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java @@ -21,12 +21,13 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; -import org.elasticsearch.client.migration.IndexUpgradeRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; +import org.elasticsearch.client.migration.IndexUpgradeRequest; final class MigrationRequestConverters { - private MigrationRequestConverters() {} + private MigrationRequestConverters() { + } static Request getMigrationAssistance(IndexUpgradeInfoRequest indexUpgradeInfoRequest) { RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder() @@ -49,13 +50,14 @@ static Request submitMigrateTask(IndexUpgradeRequest indexUpgradeRequest) { private static Request prepareMigrateRequest(IndexUpgradeRequest indexUpgradeRequest, boolean waitForCompletion) { RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_xpack/migration/upgrade") - .addCommaSeparatedPathParts(indexUpgradeRequest.indices()); + .addPathPartAsIs("_xpack", "migration", "upgrade", indexUpgradeRequest.index()); String endpoint = endpointBuilder.build(); Request request = new Request(HttpPost.METHOD_NAME, endpoint); - RequestConverters.Params params = new RequestConverters.Params(request); - params.withWaitForCompletion(waitForCompletion); + RequestConverters.Params params = new RequestConverters.Params(request) + .withTimeout(indexUpgradeRequest.timeout()) + .withIndicesOptions(indexUpgradeRequest.indicesOptions()) + .withWaitForCompletion(waitForCompletion); return request; } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java index 7cafe9b5c5287..2704c82a044b8 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java @@ -18,38 +18,34 @@ */ package org.elasticsearch.client.migration; -import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.TimedRequest; -import java.util.Arrays; import java.util.Objects; /** * A request for performing Upgrade on Index * Part of Migration API */ -public class IndexUpgradeRequest extends TimedRequest implements IndicesRequest { +public class IndexUpgradeRequest extends TimedRequest { - private String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true); + private String index; + private IndicesOptions indicesOptions = IndicesOptions.STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED; public IndexUpgradeRequest(String index) { - indices = new String[]{index}; + this.index = index; } - @Override - public String[] indices() { - return indices; + public void indicesOptions(IndicesOptions indicesOptions) { + this.indicesOptions = indicesOptions; } - @Override - public IndicesOptions indicesOptions() { - return indicesOptions; + public String index() { + return index; } - public void indicesOptions(IndicesOptions indicesOptions) { - this.indicesOptions = indicesOptions; + public IndicesOptions indicesOptions() { + return indicesOptions; } @Override @@ -57,12 +53,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IndexUpgradeRequest request = (IndexUpgradeRequest) o; - return Arrays.equals(indices, request.indices) && + return Objects.equals(index, request.index) && Objects.equals(indicesOptions.toString(), request.indicesOptions.toString()); } @Override public int hashCode() { - return Objects.hash(Arrays.hashCode(indices), indicesOptions.toString()); + return Objects.hash(index, indicesOptions); } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java deleted file mode 100644 index 6f7bb42735daf..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponse.java +++ /dev/null @@ -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.migration; - -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.tasks.TaskId; - -import java.io.IOException; -import java.util.Objects; - -/** - * Response object that contains the taskID from submitted IndexUpgradeRequest - */ -public class IndexUpgradeSubmissionResponse { - - private static final ParseField TASK = new ParseField("task"); - - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "upgrade_submission_response", - true, a-> new IndexUpgradeSubmissionResponse( (TaskId) a[0])); - - static { - PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), TaskId.parser(), TASK, ObjectParser.ValueType.STRING); - } - - public static IndexUpgradeSubmissionResponse fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - private final TaskId task; - - IndexUpgradeSubmissionResponse(@Nullable TaskId task) { - this.task = task; - } - - /** - * Get the task id - * @return the id of the upgrade task. - */ - public TaskId getTask() { - return task; - } - - @Override - public int hashCode() { - return Objects.hash(task); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - IndexUpgradeSubmissionResponse that = (IndexUpgradeSubmissionResponse) other; - return Objects.equals(task, that.task); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java index d5b29a86361b7..c1c00fefbf9c2 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; import org.elasticsearch.client.migration.IndexUpgradeRequest; -import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; +import org.elasticsearch.client.tasks.TaskSubmissionResponse; import org.elasticsearch.common.settings.Settings; import java.io.IOException; @@ -64,7 +64,7 @@ public void testUpgradeWithTaskApi() throws IOException, InterruptedException { IndexUpgradeRequest request = new IndexUpgradeRequest("test"); - IndexUpgradeSubmissionResponse upgrade = highLevelClient().migration() + TaskSubmissionResponse upgrade = highLevelClient().migration() .submitUpgradeTask(request, RequestOptions.DEFAULT); assertNotNull(upgrade.getTask()); @@ -77,10 +77,10 @@ public void testUpgradeWithTaskApi() throws IOException, InterruptedException { * Using low-level api as high-level-rest-client's getTaskById work is in progress. * TODO revisit once that work is finished */ - private BooleanSupplier checkCompletionStatus(IndexUpgradeSubmissionResponse upgrade) { + private BooleanSupplier checkCompletionStatus(TaskSubmissionResponse upgrade) { return () -> { try { - Response response = client().performRequest(new Request("GET", "/_tasks/" + upgrade.getTask().toString())); + Response response = client().performRequest(new Request("GET", "/_tasks/" + upgrade.getTask())); return (boolean) entityAsMap(response).get("completed"); } catch (IOException e) { fail(e.getMessage()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java index f71e4bce4800b..deb5ed7ae0247 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java @@ -30,11 +30,10 @@ import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; import org.elasticsearch.client.migration.IndexUpgradeRequest; import org.elasticsearch.client.migration.UpgradeActionRequired; +import org.elasticsearch.client.tasks.TaskSubmissionResponse; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.reindex.BulkByScrollResponse; -import org.elasticsearch.client.migration.IndexUpgradeSubmissionResponse; -import org.elasticsearch.tasks.TaskId; import java.io.IOException; import java.util.Map; @@ -42,6 +41,8 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.isEmptyOrNullString; +import static org.hamcrest.Matchers.not; /** * This class is used to generate the Java Migration API documentation. @@ -144,7 +145,6 @@ public void onFailure(Exception e) { // end::upgrade-async-execute assertTrue(latch.await(30L, TimeUnit.SECONDS)); - } public void testUpgradeWithTaskApi() throws IOException { @@ -153,11 +153,10 @@ public void testUpgradeWithTaskApi() throws IOException { // tag::upgrade-task-api IndexUpgradeRequest request = new IndexUpgradeRequest("test"); - IndexUpgradeSubmissionResponse response = client.migration() + TaskSubmissionResponse response = client.migration() .submitUpgradeTask(request, RequestOptions.DEFAULT); - TaskId taskId = response.getTask(); + String taskId = response.getTask(); // end::upgrade-task-api - assertNotNull(taskId); - + assertThat(taskId, not(isEmptyOrNullString())); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java deleted file mode 100644 index e0c4ad0f8088a..0000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/IndexUpgradeSubmissionResponseTests.java +++ /dev/null @@ -1,51 +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.migration; - -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.tasks.TaskId; -import org.elasticsearch.test.ESTestCase; - -import java.io.IOException; - -import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; - -public class IndexUpgradeSubmissionResponseTests extends ESTestCase { - public void testFromXContent() throws IOException { - xContentTester( - this::createParser, - this::createTestInstance, - this::toXContent, - IndexUpgradeSubmissionResponse::fromXContent) - .supportsUnknownFields(true) - .test(); - } - - private void toXContent(IndexUpgradeSubmissionResponse response, XContentBuilder xContentBuilder) throws IOException { - xContentBuilder.startObject(); - xContentBuilder.field("task", response.getTask().toString()); - xContentBuilder.endObject(); - } - - private IndexUpgradeSubmissionResponse createTestInstance() { - TaskId taskId = new TaskId(randomAlphaOfLength(5), randomLong()); - return new IndexUpgradeSubmissionResponse(taskId); - } -} From 30a169464812052af0b63b919da31f7be06044ad Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 8 Nov 2018 18:36:47 +0100 Subject: [PATCH 09/10] remove index options and timeout as these are not used. causing requests to fail --- .../client/MigrationRequestConverters.java | 2 -- .../client/migration/IndexUpgradeRequest.java | 19 ++++--------------- .../MigrationRequestConvertersTests.java | 18 ++++++++++++++++++ .../MigrationClientDocumentationIT.java | 4 ---- .../high-level/migration/upgrade.asciidoc | 10 ---------- 5 files changed, 22 insertions(+), 31 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java index 52cab21304812..b61ac515ab5f8 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java @@ -55,8 +55,6 @@ private static Request prepareMigrateRequest(IndexUpgradeRequest indexUpgradeReq Request request = new Request(HttpPost.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(request) - .withTimeout(indexUpgradeRequest.timeout()) - .withIndicesOptions(indexUpgradeRequest.indicesOptions()) .withWaitForCompletion(waitForCompletion); return request; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java index 2704c82a044b8..6b49fcc9979c2 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/IndexUpgradeRequest.java @@ -18,8 +18,7 @@ */ package org.elasticsearch.client.migration; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.client.TimedRequest; +import org.elasticsearch.client.Validatable; import java.util.Objects; @@ -27,38 +26,28 @@ * A request for performing Upgrade on Index * Part of Migration API */ -public class IndexUpgradeRequest extends TimedRequest { +public class IndexUpgradeRequest implements Validatable { private String index; - private IndicesOptions indicesOptions = IndicesOptions.STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED; public IndexUpgradeRequest(String index) { this.index = index; } - public void indicesOptions(IndicesOptions indicesOptions) { - this.indicesOptions = indicesOptions; - } - public String index() { return index; } - public IndicesOptions indicesOptions() { - return indicesOptions; - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IndexUpgradeRequest request = (IndexUpgradeRequest) o; - return Objects.equals(index, request.index) && - Objects.equals(indicesOptions.toString(), request.indicesOptions.toString()); + return Objects.equals(index, request.index); } @Override public int hashCode() { - return Objects.hash(index, indicesOptions); + return Objects.hash(index); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationRequestConvertersTests.java index e3adefcb262a3..3b3c649bf5aab 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationRequestConvertersTests.java @@ -20,7 +20,9 @@ package org.elasticsearch.client; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; import org.elasticsearch.client.migration.IndexUpgradeInfoRequest; +import org.elasticsearch.client.migration.IndexUpgradeRequest; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; @@ -45,4 +47,20 @@ public void testGetMigrationAssistance() { assertNull(request.getEntity()); assertEquals(expectedParams, request.getParameters()); } + + public void testUpgradeRequest() { + String[] indices = RequestConvertersTests.randomIndicesNames(1, 1); + IndexUpgradeRequest upgradeInfoRequest = new IndexUpgradeRequest(indices[0]); + + String expectedEndpoint = "/_xpack/migration/upgrade/" + indices[0]; + Map expectedParams = new HashMap<>(); + expectedParams.put("wait_for_completion", Boolean.TRUE.toString()); + + Request request = MigrationRequestConverters.migrate(upgradeInfoRequest); + + assertEquals(HttpPost.METHOD_NAME, request.getMethod()); + assertEquals(expectedEndpoint, request.getEndpoint()); + assertNull(request.getEntity()); + assertEquals(expectedParams, request.getParameters()); + } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java index deb5ed7ae0247..2cedc106c9500 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java @@ -104,9 +104,6 @@ public void testUpgrade() throws IOException { IndexUpgradeRequest request = new IndexUpgradeRequest("test"); // <1> // end::upgrade-request - // tag::upgrade-request-indices-options - request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::upgrade-request-indices-options try { // tag::upgrade-execute @@ -118,7 +115,6 @@ public void testUpgrade() throws IOException { } } - public void testUpgradeAsync() throws IOException, InterruptedException { RestHighLevelClient client = highLevelClient(); createIndex("test", Settings.EMPTY); diff --git a/docs/java-rest/high-level/migration/upgrade.asciidoc b/docs/java-rest/high-level/migration/upgrade.asciidoc index 33da3e2192f2b..76eae0652d9bf 100644 --- a/docs/java-rest/high-level/migration/upgrade.asciidoc +++ b/docs/java-rest/high-level/migration/upgrade.asciidoc @@ -12,16 +12,6 @@ include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-request] -------------------------------------------------- <1> Create a new request instance -==== Optional arguments -The following arguments can optionally be provided: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-request-indices-options] --------------------------------------------------- -<1> Set the `IndicesOptions` to control how unavailable indices are resolved and -how wildcard expressions are expanded - [[java-rest-high-migration-upgrade-execution]] ==== Execution From 614e711e3cd40a0cbd784ac7d241596ef90c8a24 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 13 Nov 2018 08:14:06 +0100 Subject: [PATCH 10/10] cleanup migration request endpoint builder --- .../elasticsearch/client/MigrationRequestConverters.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java index b61ac515ab5f8..5bc0eed57155a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationRequestConverters.java @@ -49,9 +49,11 @@ static Request submitMigrateTask(IndexUpgradeRequest indexUpgradeRequest) { } private static Request prepareMigrateRequest(IndexUpgradeRequest indexUpgradeRequest, boolean waitForCompletion) { - RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder() - .addPathPartAsIs("_xpack", "migration", "upgrade", indexUpgradeRequest.index()); - String endpoint = endpointBuilder.build(); + String endpoint = new RequestConverters.EndpointBuilder() + .addPathPartAsIs("_xpack", "migration", "upgrade") + .addPathPart(indexUpgradeRequest.index()) + .build(); + Request request = new Request(HttpPost.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(request)