diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java
index 94bf6243835..fe942f0dde4 100644
--- a/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseClient.java
@@ -48,7 +48,7 @@ import static java.util.Collections.emptySet;
* See the
* X-Pack Licensing APIs on elastic.co for more information.
*/
-public class LicenseClient {
+public final class LicenseClient {
private final RestHighLevelClient restHighLevelClient;
@@ -98,9 +98,8 @@ public class LicenseClient {
response -> new GetLicenseResponse(convertResponseToJson(response)), listener, emptySet());
}
-
/**
- * Converts an entire response into a json sting
+ * Converts an entire response into a json string
*
* This is useful for responses that we don't parse on the client side, but instead work as string
* such as in case of the license JSON
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
new file mode 100644
index 00000000000..7da38329947
--- /dev/null
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java
@@ -0,0 +1,55 @@
+/*
+ * 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.protocol.xpack.migration.IndexUpgradeInfoRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
+
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * A wrapper for the {@link RestHighLevelClient} that provides methods for
+ * accessing the Elastic License-related methods
+ *
+ * See the
+ * X-Pack Migration APIs on elastic.co for more information.
+ */
+public final class MigrationClient {
+
+ private final RestHighLevelClient restHighLevelClient;
+
+ MigrationClient(RestHighLevelClient restHighLevelClient) {
+ this.restHighLevelClient = restHighLevelClient;
+ }
+
+ /**
+ * Get Migration Assistance for one or more indices
+ *
+ * @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 IndexUpgradeInfoResponse getAssistance(IndexUpgradeInfoRequest request, RequestOptions options) throws IOException {
+ return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::getMigrationAssistance, options,
+ IndexUpgradeInfoResponse::fromXContent, Collections.emptySet());
+ }
+}
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 a81060e6624..9470d442163 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
@@ -110,6 +110,7 @@ import org.elasticsearch.protocol.xpack.XPackInfoRequest;
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.protocol.xpack.ml.PutJobRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
@@ -1196,12 +1197,22 @@ final class RequestConverters {
.addPathPartAsIs("anomaly_detectors")
.addPathPart(putJobRequest.getJob().getId())
.build();
-
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
request.setEntity(createEntity(putJobRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
+ static Request getMigrationAssistance(IndexUpgradeInfoRequest indexUpgradeInfoRequest) {
+ EndpointBuilder endpointBuilder = new EndpointBuilder()
+ .addPathPartAsIs("_xpack/migration/assistance")
+ .addCommaSeparatedPathParts(indexUpgradeInfoRequest.indices());
+ String endpoint = endpointBuilder.build();
+ Request request = new Request(HttpGet.METHOD_NAME, endpoint);
+ Params parameters = new Params(request);
+ parameters.withIndicesOptions(indexUpgradeInfoRequest.indicesOptions());
+ return request;
+ }
+
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));
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 e6e98d73c65..50d7465ae33 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
@@ -210,6 +210,7 @@ public class RestHighLevelClient implements Closeable {
private final XPackClient xPackClient = new XPackClient(this);
private final WatcherClient watcherClient = new WatcherClient(this);
private final LicenseClient licenseClient = new LicenseClient(this);
+ private final MigrationClient migrationClient = new MigrationClient(this);
private final MachineLearningClient machineLearningClient = new MachineLearningClient(this);
/**
@@ -334,6 +335,18 @@ public class RestHighLevelClient implements Closeable {
*/
public LicenseClient license() { return licenseClient; }
+ /**
+ * Provides methods for accessing the Elastic Licensed Licensing APIs that
+ * are shipped with the default distribution of Elasticsearch. All of
+ * these APIs will 404 if run against the OSS distribution of Elasticsearch.
+ *
+ * See the
+ * Migration APIs on elastic.co for more information.
+ */
+ public MigrationClient migration() {
+ return migrationClient;
+ }
+
/**
* Provides methods for accessing the Elastic Licensed Machine Learning APIs that
* are shipped with the Elastic Stack distribution of Elasticsearch. All of
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
new file mode 100644
index 00000000000..03614537bfe
--- /dev/null
+++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.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;
+
+import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
+
+import java.io.IOException;
+
+public class MigrationIT extends ESRestHighLevelClientTestCase {
+
+ public void testGetAssistance() throws IOException {
+ RestHighLevelClient client = highLevelClient();
+ {
+ IndexUpgradeInfoResponse response = client.migration().getAssistance(new IndexUpgradeInfoRequest(), RequestOptions.DEFAULT);
+ assertEquals(0, response.getActions().size());
+ }
+ {
+ client.indices().create(new CreateIndexRequest("test"), RequestOptions.DEFAULT);
+ IndexUpgradeInfoResponse response = client.migration().getAssistance(
+ new IndexUpgradeInfoRequest("test"), RequestOptions.DEFAULT);
+ assertEquals(0, response.getActions().size());
+ }
+ }
+}
diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java
index e4aa690acb6..47195f0bb2a 100644
--- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java
+++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java
@@ -126,6 +126,7 @@ import org.elasticsearch.index.rankeval.RankEvalSpec;
import org.elasticsearch.index.rankeval.RatedRequest;
import org.elasticsearch.index.rankeval.RestRankEvalAction;
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.repositories.fs.FsRepository;
@@ -2552,6 +2553,23 @@ public class RequestConvertersTests extends ESTestCase {
assertEquals(expectedParams, request.getParameters());
}
+ public void testGetMigrationAssistance() {
+ IndexUpgradeInfoRequest upgradeInfoRequest = new IndexUpgradeInfoRequest();
+ String expectedEndpoint = "/_xpack/migration/assistance";
+ if (randomBoolean()) {
+ String[] indices = randomIndicesNames(1, 5);
+ upgradeInfoRequest.indices(indices);
+ expectedEndpoint += "/" + String.join(",", indices);
+ }
+ Map expectedParams = new HashMap<>();
+ setRandomIndicesOptions(upgradeInfoRequest::indicesOptions, upgradeInfoRequest::indicesOptions, expectedParams);
+ Request request = RequestConverters.getMigrationAssistance(upgradeInfoRequest);
+ assertEquals(HttpGet.METHOD_NAME, request.getMethod());
+ assertEquals(expectedEndpoint, request.getEndpoint());
+ assertNull(request.getEntity());
+ assertEquals(expectedParams, request.getParameters());
+ }
+
public void testXPackPutWatch() throws Exception {
PutWatchRequest putWatchRequest = new PutWatchRequest();
String watchId = randomAlphaOfLength(10);
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 d04224bacf4..b5d8dbb628e 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
@@ -757,7 +757,8 @@ public class RestHighLevelClientTests extends ESTestCase {
if (apiName.startsWith("xpack.") == false &&
apiName.startsWith("license.") == false &&
apiName.startsWith("machine_learning.") == false &&
- apiName.startsWith("watcher.") == false) {
+ apiName.startsWith("watcher.") == false &&
+ apiName.startsWith("migration.") == false) {
apiNotFound.add(apiName);
}
}
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
new file mode 100644
index 00000000000..c8310be8053
--- /dev/null
+++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.client.documentation;
+
+import org.elasticsearch.action.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.protocol.xpack.migration.IndexUpgradeInfoRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
+import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * This class is used to generate the Java Migration API documentation.
+ * You need to wrap your code between two tags like:
+ * // tag::example
+ * // end::example
+ *
+ * Where example is your tag name.
+ *
+ * Then in the documentation, you can extract what is between tag and end tags with
+ * ["source","java",subs="attributes,callouts,macros"]
+ * --------------------------------------------------
+ * include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[example]
+ * --------------------------------------------------
+ *
+ * The column width of the code block is 84. If the code contains a line longer
+ * than 84, the line will be cut and a horizontal scroll bar will be displayed.
+ * (the code indentation of the tag is not included in the width)
+ */
+public class MigrationClientDocumentationIT extends ESRestHighLevelClientTestCase {
+
+ public void testGetAssistance() throws IOException {
+ RestHighLevelClient client = highLevelClient();
+
+ // tag::get-assistance-request
+ IndexUpgradeInfoRequest request = new IndexUpgradeInfoRequest(); // <1>
+ // end::get-assistance-request
+
+ // tag::get-assistance-request-indices
+ request.indices("index1", "index2"); // <1>
+ // end::get-assistance-request-indices
+
+ request.indices(Strings.EMPTY_ARRAY);
+
+ // tag::get-assistance-request-indices-options
+ request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1>
+ // end::get-assistance-request-indices-options
+
+ // tag::get-assistance-execute
+ IndexUpgradeInfoResponse response = client.migration().getAssistance(request, RequestOptions.DEFAULT);
+ // end::get-assistance-execute
+
+ // tag::get-assistance-response
+ Map actions = response.getActions();
+ for (Map.Entry entry : actions.entrySet()) {
+ String index = entry.getKey(); // <1>
+ UpgradeActionRequired actionRequired = entry.getValue(); // <2>
+ }
+ // end::get-assistance-response
+ }
+}
diff --git a/docs/java-rest/high-level/migration/get-assistance.asciidoc b/docs/java-rest/high-level/migration/get-assistance.asciidoc
new file mode 100644
index 00000000000..20f857eb1fb
--- /dev/null
+++ b/docs/java-rest/high-level/migration/get-assistance.asciidoc
@@ -0,0 +1,49 @@
+[[java-rest-high-migration-get-assistance]]
+=== Migration Get Assistance
+
+[[java-rest-high-migraton-get-assistance-request]]
+==== Index Upgrade Info Request
+
+An `IndexUpgradeInfoRequest` does not require any argument:
+
+["source","java",subs="attributes,callouts,macros"]
+--------------------------------------------------
+include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-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[get-assistance-request-indices]
+--------------------------------------------------
+<1> Set the indices to the request
+
+["source","java",subs="attributes,callouts,macros"]
+--------------------------------------------------
+include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-request-indices-options]
+--------------------------------------------------
+<1> Set the `IndicesOptions` to control how unavailable indices are resolved and
+how wildcard expressions are expanded
+
+[[java-rest-high-migration-get-assistance-execution]]
+==== Execution
+
+["source","java",subs="attributes,callouts,macros"]
+--------------------------------------------------
+include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-execute]
+--------------------------------------------------
+
+[[java-rest-high-migration-get-assistance-response]]
+==== Response
+
+The returned `IndexUpgradeInfoResponse` contains the actions required for each index.
+
+["source","java",subs="attributes,callouts,macros"]
+--------------------------------------------------
+include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-response]
+--------------------------------------------------
+<1> Retrieve the index
+<2> Retrieve the action required for the migration of the current index
diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc
index 1acba882226..1ddee70f1e0 100644
--- a/docs/java-rest/high-level/supported-apis.asciidoc
+++ b/docs/java-rest/high-level/supported-apis.asciidoc
@@ -198,6 +198,14 @@ The Java High Level REST Client supports the following Licensing APIs:
include::licensing/put-license.asciidoc[]
include::licensing/get-license.asciidoc[]
+== Migration APIs
+
+The Java High Level REST Client supports the following Migration APIs:
+
+* <>
+
+include::migration/get-assistance.asciidoc[]
+
== Watcher APIs
The Java High Level REST Client supports the following Watcher APIs:
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java
index f17dfbdb90b..3044c953a3e 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeInfoAction.java
@@ -6,27 +6,13 @@
package org.elasticsearch.xpack.core.upgrade.actions;
import org.elasticsearch.action.Action;
-import org.elasticsearch.action.ActionRequestValidationException;
-import org.elasticsearch.action.ActionResponse;
-import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
-import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.client.ElasticsearchClient;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.xcontent.ToXContentObject;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Objects;
-
-import static org.elasticsearch.action.ValidateActions.addValidationError;
-
-public class IndexUpgradeInfoAction extends Action {
+public class IndexUpgradeInfoAction extends Action {
public static final IndexUpgradeInfoAction INSTANCE = new IndexUpgradeInfoAction();
public static final String NAME = "cluster:admin/xpack/upgrade/info";
@@ -36,149 +22,15 @@ public class IndexUpgradeInfoAction extends Action actions;
-
- public Response() {
-
- }
-
- public Response(Map actions) {
- this.actions = actions;
- }
-
- @Override
- public void readFrom(StreamInput in) throws IOException {
- super.readFrom(in);
- actions = in.readMap(StreamInput::readString, UpgradeActionRequired::readFromStream);
- }
-
- @Override
- public void writeTo(StreamOutput out) throws IOException {
- super.writeTo(out);
- out.writeMap(actions, StreamOutput::writeString, (out1, value) -> value.writeTo(out1));
- }
-
- public Map getActions() {
- return actions;
- }
-
- @Override
- public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
- builder.startObject();
- {
- builder.startObject("indices");
- for (Map.Entry entry : actions.entrySet()) {
- builder.startObject(entry.getKey());
- {
- builder.field("action_required", entry.getValue().toString());
- }
- builder.endObject();
- }
- builder.endObject();
- }
- builder.endObject();
- return builder;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Response response = (Response) o;
- return Objects.equals(actions, response.actions);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(actions);
- }
- }
-
- public static class Request extends MasterNodeReadRequest implements IndicesRequest.Replaceable {
-
- private String[] indices = null;
- private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true);
-
- // for serialization
- public Request() {
-
- }
-
- public Request(String... indices) {
- this.indices = indices;
- }
-
- public Request(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 Request indices(String... indices) {
- this.indices = indices;
- return this;
- }
-
- @Override
- public IndicesOptions indicesOptions() {
- return indicesOptions;
- }
-
- public void indicesOptions(IndicesOptions indicesOptions) {
- this.indicesOptions = indicesOptions;
- }
-
- @Override
- public ActionRequestValidationException validate() {
- ActionRequestValidationException validationException = null;
- if (indices == null) {
- validationException = addValidationError("index/indices is missing", validationException);
- }
- return validationException;
- }
-
- @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;
- Request request = (Request) 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());
- }
- }
-
- public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder {
+ public static class RequestBuilder
+ extends MasterNodeReadOperationRequestBuilder {
public RequestBuilder(ElasticsearchClient client) {
- super(client, INSTANCE, new Request());
+ super(client, INSTANCE, new IndexUpgradeInfoRequest());
}
public RequestBuilder setIndices(String... indices) {
@@ -191,5 +43,4 @@ public class IndexUpgradeInfoAction extends Action {
+public class TransportIndexUpgradeInfoAction
+ extends TransportMasterNodeReadAction {
private final IndexUpgradeService indexUpgradeService;
private final XPackLicenseState licenseState;
@@ -40,7 +42,7 @@ public class TransportIndexUpgradeInfoAction extends TransportMasterNodeReadActi
IndexNameExpressionResolver indexNameExpressionResolver,
XPackLicenseState licenseState) {
super(settings, IndexUpgradeInfoAction.NAME, transportService, clusterService, threadPool, actionFilters,
- IndexUpgradeInfoAction.Request::new, indexNameExpressionResolver);
+ IndexUpgradeInfoRequest::new, indexNameExpressionResolver);
this.indexUpgradeService = indexUpgradeService;
this.licenseState = licenseState;
}
@@ -51,23 +53,23 @@ public class TransportIndexUpgradeInfoAction extends TransportMasterNodeReadActi
}
@Override
- protected IndexUpgradeInfoAction.Response newResponse() {
- return new IndexUpgradeInfoAction.Response();
+ protected IndexUpgradeInfoResponse newResponse() {
+ return new IndexUpgradeInfoResponse();
}
@Override
- protected ClusterBlockException checkBlock(IndexUpgradeInfoAction.Request request, ClusterState state) {
+ protected ClusterBlockException checkBlock(IndexUpgradeInfoRequest request, ClusterState state) {
// Cluster is not affected but we look up repositories in metadata
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}
@Override
- protected final void masterOperation(final IndexUpgradeInfoAction.Request request, ClusterState state,
- final ActionListener listener) {
+ protected final void masterOperation(final IndexUpgradeInfoRequest request, ClusterState state,
+ final ActionListener listener) {
if (licenseState.isUpgradeAllowed()) {
Map results =
indexUpgradeService.upgradeInfo(request.indices(), request.indicesOptions(), state);
- listener.onResponse(new IndexUpgradeInfoAction.Response(results));
+ listener.onResponse(new IndexUpgradeInfoResponse(results));
} else {
listener.onFailure(LicenseUtils.newComplianceException(XPackField.UPGRADE));
}
diff --git a/x-pack/plugin/upgrade/src/main/java/org/elasticsearch/xpack/upgrade/rest/RestIndexUpgradeInfoAction.java b/x-pack/plugin/upgrade/src/main/java/org/elasticsearch/xpack/upgrade/rest/RestIndexUpgradeInfoAction.java
index 24b576187cb..dbb61937642 100644
--- a/x-pack/plugin/upgrade/src/main/java/org/elasticsearch/xpack/upgrade/rest/RestIndexUpgradeInfoAction.java
+++ b/x-pack/plugin/upgrade/src/main/java/org/elasticsearch/xpack/upgrade/rest/RestIndexUpgradeInfoAction.java
@@ -9,12 +9,12 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
-import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction.Request;
import java.io.IOException;
@@ -41,7 +41,7 @@ public class RestIndexUpgradeInfoAction extends BaseRestHandler {
}
private RestChannelConsumer handleGet(final RestRequest request, NodeClient client) {
- Request infoRequest = new Request(Strings.splitStringByCommaToArray(request.param("index")));
+ IndexUpgradeInfoRequest infoRequest = new IndexUpgradeInfoRequest(Strings.splitStringByCommaToArray(request.param("index")));
infoRequest.indicesOptions(IndicesOptions.fromRequest(request, infoRequest.indicesOptions()));
return channel -> client.execute(IndexUpgradeInfoAction.INSTANCE, infoRequest, new RestToXContentListener<>(channel));
}
diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java
index 870261d2515..74eb029e916 100644
--- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java
+++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeIT.java
@@ -14,12 +14,12 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
+import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.transport.TransportResponse;
-import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
-import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction.Response;
import org.junit.Before;
import java.util.Collections;
@@ -41,7 +41,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase {
// Testing only negative case here, the positive test is done in bwcTests
assertAcked(client().admin().indices().prepareCreate("test").get());
ensureYellow("test");
- Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
+ IndexUpgradeInfoResponse response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
assertThat(response.getActions().entrySet(), empty());
}
@@ -57,7 +57,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase {
() -> new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get());
assertThat(e.getMessage(), equalTo("current license is non-compliant for [upgrade]"));
enableLicensing();
- Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
+ IndexUpgradeInfoResponse response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
assertThat(response.getActions().entrySet(), empty());
}
@@ -132,7 +132,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase {
public void testIndexUpgradeInfoOnEmptyCluster() {
// On empty cluster asking for all indices shouldn't fail since no indices means nothing needs to be upgraded
- Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("_all").get();
+ IndexUpgradeInfoResponse response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("_all").get();
assertThat(response.getActions().entrySet(), empty());
// but calling on a particular index should fail
diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeServiceTests.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeServiceTests.java
index 63b1c602bf9..5939777572b 100644
--- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeServiceTests.java
+++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeServiceTests.java
@@ -15,8 +15,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.test.ESTestCase;
-import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import java.io.IOException;
import java.util.Arrays;
diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java
index abc157119b4..7605af041e6 100644
--- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java
+++ b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/IndexUpgradeTasksIT.java
@@ -30,6 +30,8 @@ import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.plugins.ScriptPlugin;
+import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
+import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.script.MockScriptEngine;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext;
@@ -39,7 +41,6 @@ import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
-import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import org.elasticsearch.xpack.core.upgrade.UpgradeField;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
@@ -171,7 +172,7 @@ public class IndexUpgradeTasksIT extends ESIntegTestCase {
ensureYellow("test");
- IndexUpgradeInfoAction.Response infoResponse = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
+ IndexUpgradeInfoResponse infoResponse = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
assertThat(infoResponse.getActions().keySet(), contains("test"));
assertThat(infoResponse.getActions().get("test"), equalTo(UpgradeActionRequired.UPGRADE));
diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/actions/IndexUpgradeInfoActionRequestTests.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/actions/IndexUpgradeInfoActionRequestTests.java
deleted file mode 100644
index 38072755bc3..00000000000
--- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/actions/IndexUpgradeInfoActionRequestTests.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.upgrade.actions;
-
-import org.elasticsearch.action.support.IndicesOptions;
-import org.elasticsearch.common.io.stream.Writeable;
-import org.elasticsearch.test.AbstractWireSerializingTestCase;
-import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction.Request;
-
-public class IndexUpgradeInfoActionRequestTests extends AbstractWireSerializingTestCase {
- @Override
- protected Request createTestInstance() {
- int indexCount = randomInt(4);
- String[] indices = new String[indexCount];
- for (int i = 0; i < indexCount; i++) {
- indices[i] = randomAlphaOfLength(10);
- }
- Request request = new Request(indices);
- if (randomBoolean()) {
- request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
- }
- return request;
- }
-
- @Override
- protected Writeable.Reader instanceReader() {
- return Request::new;
- }
-}
diff --git a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/actions/IndexUpgradeInfoActionResponseTests.java b/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/actions/IndexUpgradeInfoActionResponseTests.java
deleted file mode 100644
index 6893e45dd2e..00000000000
--- a/x-pack/plugin/upgrade/src/test/java/org/elasticsearch/xpack/upgrade/actions/IndexUpgradeInfoActionResponseTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-package org.elasticsearch.xpack.upgrade.actions;
-
-import org.elasticsearch.test.AbstractStreamableTestCase;
-import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
-import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction.Response;
-
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-
-public class IndexUpgradeInfoActionResponseTests extends AbstractStreamableTestCase {
-
-
- @Override
- protected Response createTestInstance() {
- int actionsCount = randomIntBetween(0, 5);
- Map actions = new HashMap<>(actionsCount);
- for (int i = 0; i < actionsCount; i++) {
- actions.put(randomAlphaOfLength(10), randomFrom(EnumSet.allOf(UpgradeActionRequired.class)));
- }
- return new Response(actions);
- }
-
- @Override
- protected Response createBlankInstance() {
- return new Response();
- }
-}
diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java
new file mode 100644
index 00000000000..ae26bc4de8d
--- /dev/null
+++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.protocol.xpack.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.Strings;
+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 IndexUpgradeInfoRequest extends MasterNodeReadRequest implements IndicesRequest.Replaceable {
+
+ private String[] indices = Strings.EMPTY_ARRAY;
+ private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true);
+
+ public IndexUpgradeInfoRequest(String... indices) {
+ indices(indices);
+ }
+
+ public IndexUpgradeInfoRequest(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 IndexUpgradeInfoRequest indices(String... indices) {
+ this.indices = Objects.requireNonNull(indices, "indices cannot be null");
+ return this;
+ }
+
+ @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;
+ IndexUpgradeInfoRequest request = (IndexUpgradeInfoRequest) 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/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoResponse.java
new file mode 100644
index 00000000000..4c1208f960e
--- /dev/null
+++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoResponse.java
@@ -0,0 +1,133 @@
+/*
+ * 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.protocol.xpack.migration;
+
+import org.elasticsearch.action.ActionResponse;
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.xcontent.ConstructingObjectParser;
+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.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
+
+public class IndexUpgradeInfoResponse extends ActionResponse implements ToXContentObject {
+
+ private static final ParseField INDICES = new ParseField("indices");
+ private static final ParseField ACTION_REQUIRED = new ParseField("action_required");
+
+ private static final ConstructingObjectParser PARSER =
+ new ConstructingObjectParser<>("IndexUpgradeInfoResponse",
+ true,
+ (a, c) -> {
+ @SuppressWarnings("unchecked")
+ Map map = (Map)a[0];
+ Map actionsRequired = map.entrySet().stream()
+ .filter(e -> {
+ if (e.getValue() instanceof Map == false) {
+ return false;
+ }
+ @SuppressWarnings("unchecked")
+ Map value =(Map)e.getValue();
+ return value.containsKey(ACTION_REQUIRED.getPreferredName());
+ })
+ .collect(Collectors.toMap(
+ Map.Entry::getKey,
+ e -> {
+ @SuppressWarnings("unchecked")
+ Map value = (Map) e.getValue();
+ return UpgradeActionRequired.fromString((String)value.get(ACTION_REQUIRED.getPreferredName()));
+ }
+ ));
+ return new IndexUpgradeInfoResponse(actionsRequired);
+ });
+
+ static {
+ PARSER.declareObject(constructorArg(), (p, c) -> p.map(), INDICES);
+ }
+
+
+ private Map actions;
+
+ public IndexUpgradeInfoResponse() {
+
+ }
+
+ public IndexUpgradeInfoResponse(Map actions) {
+ this.actions = actions;
+ }
+
+ @Override
+ public void readFrom(StreamInput in) throws IOException {
+ super.readFrom(in);
+ actions = in.readMap(StreamInput::readString, UpgradeActionRequired::readFromStream);
+ }
+
+ @Override
+ public void writeTo(StreamOutput out) throws IOException {
+ super.writeTo(out);
+ out.writeMap(actions, StreamOutput::writeString, (out1, value) -> value.writeTo(out1));
+ }
+
+ public Map getActions() {
+ return actions;
+ }
+
+ @Override
+ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
+ builder.startObject();
+ {
+ builder.startObject(INDICES.getPreferredName());
+ for (Map.Entry entry : actions.entrySet()) {
+ builder.startObject(entry.getKey());
+ {
+ builder.field(ACTION_REQUIRED.getPreferredName(), entry.getValue().toString());
+ }
+ builder.endObject();
+ }
+ builder.endObject();
+ }
+ builder.endObject();
+ return builder;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ IndexUpgradeInfoResponse response = (IndexUpgradeInfoResponse) o;
+ return Objects.equals(actions, response.actions);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(actions);
+ }
+
+ public static IndexUpgradeInfoResponse fromXContent(XContentParser parser) {
+ return PARSER.apply(parser, null);
+ }
+}
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/UpgradeActionRequired.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/UpgradeActionRequired.java
similarity index 59%
rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/UpgradeActionRequired.java
rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/UpgradeActionRequired.java
index 1bc4d92f33d..c87e37be7a5 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/UpgradeActionRequired.java
+++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/UpgradeActionRequired.java
@@ -1,9 +1,22 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * 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.xpack.core.upgrade;
+package org.elasticsearch.protocol.xpack.migration;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/package-info.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/package-info.java
new file mode 100644
index 00000000000..12dc8eebc17
--- /dev/null
+++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/migration/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+/**
+ * Request and Response objects for the default distribution's Migration
+ * APIs.
+ */
+package org.elasticsearch.protocol.xpack.migration;
diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequestTests.java
new file mode 100644
index 00000000000..a4daa395664
--- /dev/null
+++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequestTests.java
@@ -0,0 +1,50 @@
+/*
+ * 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.protocol.xpack.migration;
+
+import org.elasticsearch.action.support.IndicesOptions;
+import org.elasticsearch.common.io.stream.Writeable;
+import org.elasticsearch.test.AbstractWireSerializingTestCase;
+
+public class IndexUpgradeInfoRequestTests extends AbstractWireSerializingTestCase {
+ @Override
+ protected IndexUpgradeInfoRequest createTestInstance() {
+ int indexCount = randomInt(4);
+ String[] indices = new String[indexCount];
+ for (int i = 0; i < indexCount; i++) {
+ indices[i] = randomAlphaOfLength(10);
+ }
+ IndexUpgradeInfoRequest request = new IndexUpgradeInfoRequest(indices);
+ if (randomBoolean()) {
+ request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
+ }
+ return request;
+ }
+
+ @Override
+ protected Writeable.Reader instanceReader() {
+ return IndexUpgradeInfoRequest::new;
+ }
+
+ public void testNullIndices() {
+ expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest((String[])null));
+ expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest().indices((String[])null));
+ }
+}
diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoResponseTests.java
new file mode 100644
index 00000000000..42de1ae6090
--- /dev/null
+++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoResponseTests.java
@@ -0,0 +1,68 @@
+/*
+ * 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.protocol.xpack.migration;
+
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.test.AbstractStreamableXContentTestCase;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class IndexUpgradeInfoResponseTests extends AbstractStreamableXContentTestCase {
+ @Override
+ protected IndexUpgradeInfoResponse doParseInstance(XContentParser parser) {
+ return IndexUpgradeInfoResponse.fromXContent(parser);
+ }
+
+ @Override
+ protected IndexUpgradeInfoResponse createBlankInstance() {
+ return new IndexUpgradeInfoResponse();
+ }
+
+ @Override
+ protected IndexUpgradeInfoResponse createTestInstance() {
+ return randomIndexUpgradeInfoResponse(randomIntBetween(0, 10));
+ }
+
+ private static IndexUpgradeInfoResponse randomIndexUpgradeInfoResponse(int numIndices) {
+ Map actions = new HashMap<>();
+ for (int i = 0; i < numIndices; i++) {
+ actions.put(randomAlphaOfLength(5), randomFrom(UpgradeActionRequired.values()));
+ }
+ return new IndexUpgradeInfoResponse(actions);
+ }
+
+ @Override
+ protected IndexUpgradeInfoResponse mutateInstance(IndexUpgradeInfoResponse instance) {
+ if (instance.getActions().size() == 0) {
+ return randomIndexUpgradeInfoResponse(1);
+ }
+ Map actions = new HashMap<>(instance.getActions());
+ if (randomBoolean()) {
+ Iterator> iterator = actions.entrySet().iterator();
+ iterator.next();
+ iterator.remove();
+ } else {
+ actions.put(randomAlphaOfLength(5), randomFrom(UpgradeActionRequired.values()));
+ }
+ return new IndexUpgradeInfoResponse(actions);
+ }
+}