HLRC: migration get assistance API (#32744)

The request and response classes have been extracted from `IndexUpgradeInfoAction` into top-level classes, and moved to the protocol jar. The `UpgradeActionRequired` enum is also moved.

Relates to #29827
This commit is contained in:
Luca Cavanna 2018-08-13 11:05:27 +02:00 committed by GitHub
parent 02f2fad57b
commit 3e692c3f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 709 additions and 254 deletions

View File

@ -48,7 +48,7 @@ import static java.util.Collections.emptySet;
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/licensing-apis.html"> * See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/licensing-apis.html">
* X-Pack Licensing APIs on elastic.co</a> for more information. * X-Pack Licensing APIs on elastic.co</a> for more information.
*/ */
public class LicenseClient { public final class LicenseClient {
private final RestHighLevelClient restHighLevelClient; private final RestHighLevelClient restHighLevelClient;
@ -98,9 +98,8 @@ public class LicenseClient {
response -> new GetLicenseResponse(convertResponseToJson(response)), listener, emptySet()); 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 * 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 * such as in case of the license JSON

View File

@ -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
* <p>
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api.html">
* X-Pack Migration APIs on elastic.co</a> 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());
}
}

View File

@ -110,6 +110,7 @@ import org.elasticsearch.protocol.xpack.XPackInfoRequest;
import org.elasticsearch.protocol.xpack.XPackUsageRequest; import org.elasticsearch.protocol.xpack.XPackUsageRequest;
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest; import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest; 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.ml.PutJobRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
@ -1196,12 +1197,22 @@ final class RequestConverters {
.addPathPartAsIs("anomaly_detectors") .addPathPartAsIs("anomaly_detectors")
.addPathPart(putJobRequest.getJob().getId()) .addPathPart(putJobRequest.getJob().getId())
.build(); .build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint); Request request = new Request(HttpPut.METHOD_NAME, endpoint);
request.setEntity(createEntity(putJobRequest, REQUEST_BODY_CONTENT_TYPE)); request.setEntity(createEntity(putJobRequest, REQUEST_BODY_CONTENT_TYPE));
return request; 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 { private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef(); BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType)); return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));

View File

@ -210,6 +210,7 @@ public class RestHighLevelClient implements Closeable {
private final XPackClient xPackClient = new XPackClient(this); private final XPackClient xPackClient = new XPackClient(this);
private final WatcherClient watcherClient = new WatcherClient(this); private final WatcherClient watcherClient = new WatcherClient(this);
private final LicenseClient licenseClient = new LicenseClient(this); private final LicenseClient licenseClient = new LicenseClient(this);
private final MigrationClient migrationClient = new MigrationClient(this);
private final MachineLearningClient machineLearningClient = new MachineLearningClient(this); private final MachineLearningClient machineLearningClient = new MachineLearningClient(this);
/** /**
@ -334,6 +335,18 @@ public class RestHighLevelClient implements Closeable {
*/ */
public LicenseClient license() { return licenseClient; } 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.
* <p>
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api.html">
* Migration APIs on elastic.co</a> for more information.
*/
public MigrationClient migration() {
return migrationClient;
}
/** /**
* Provides methods for accessing the Elastic Licensed Machine Learning APIs that * Provides methods for accessing the Elastic Licensed Machine Learning APIs that
* are shipped with the Elastic Stack distribution of Elasticsearch. All of * are shipped with the Elastic Stack distribution of Elasticsearch. All of

View File

@ -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());
}
}
}

View File

@ -126,6 +126,7 @@ import org.elasticsearch.index.rankeval.RankEvalSpec;
import org.elasticsearch.index.rankeval.RatedRequest; import org.elasticsearch.index.rankeval.RatedRequest;
import org.elasticsearch.index.rankeval.RestRankEvalAction; import org.elasticsearch.index.rankeval.RestRankEvalAction;
import org.elasticsearch.protocol.xpack.XPackInfoRequest; 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.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.repositories.fs.FsRepository; import org.elasticsearch.repositories.fs.FsRepository;
@ -2552,6 +2553,23 @@ public class RequestConvertersTests extends ESTestCase {
assertEquals(expectedParams, request.getParameters()); 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<String, String> 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 { public void testXPackPutWatch() throws Exception {
PutWatchRequest putWatchRequest = new PutWatchRequest(); PutWatchRequest putWatchRequest = new PutWatchRequest();
String watchId = randomAlphaOfLength(10); String watchId = randomAlphaOfLength(10);

View File

@ -757,7 +757,8 @@ public class RestHighLevelClientTests extends ESTestCase {
if (apiName.startsWith("xpack.") == false && if (apiName.startsWith("xpack.") == false &&
apiName.startsWith("license.") == false && apiName.startsWith("license.") == false &&
apiName.startsWith("machine_learning.") == false && apiName.startsWith("machine_learning.") == false &&
apiName.startsWith("watcher.") == false) { apiName.startsWith("watcher.") == false &&
apiName.startsWith("migration.") == false) {
apiNotFound.add(apiName); apiNotFound.add(apiName);
} }
} }

View File

@ -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<String, UpgradeActionRequired> actions = response.getActions();
for (Map.Entry<String, UpgradeActionRequired> entry : actions.entrySet()) {
String index = entry.getKey(); // <1>
UpgradeActionRequired actionRequired = entry.getValue(); // <2>
}
// end::get-assistance-response
}
}

View File

@ -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

View File

@ -198,6 +198,14 @@ The Java High Level REST Client supports the following Licensing APIs:
include::licensing/put-license.asciidoc[] include::licensing/put-license.asciidoc[]
include::licensing/get-license.asciidoc[] include::licensing/get-license.asciidoc[]
== Migration APIs
The Java High Level REST Client supports the following Migration APIs:
* <<java-rest-high-migration-get-assistance>>
include::migration/get-assistance.asciidoc[]
== Watcher APIs == Watcher APIs
The Java High Level REST Client supports the following Watcher APIs: The Java High Level REST Client supports the following Watcher APIs:

View File

@ -6,27 +6,13 @@
package org.elasticsearch.xpack.core.upgrade.actions; package org.elasticsearch.xpack.core.upgrade.actions;
import org.elasticsearch.action.Action; 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.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import java.io.IOException; public class IndexUpgradeInfoAction extends Action<IndexUpgradeInfoResponse> {
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import static org.elasticsearch.action.ValidateActions.addValidationError;
public class IndexUpgradeInfoAction extends Action<IndexUpgradeInfoAction.Response> {
public static final IndexUpgradeInfoAction INSTANCE = new IndexUpgradeInfoAction(); public static final IndexUpgradeInfoAction INSTANCE = new IndexUpgradeInfoAction();
public static final String NAME = "cluster:admin/xpack/upgrade/info"; public static final String NAME = "cluster:admin/xpack/upgrade/info";
@ -36,149 +22,15 @@ public class IndexUpgradeInfoAction extends Action<IndexUpgradeInfoAction.Respon
} }
@Override @Override
public Response newResponse() { public IndexUpgradeInfoResponse newResponse() {
return new Response(); return new IndexUpgradeInfoResponse();
} }
public static class Response extends ActionResponse implements ToXContentObject { public static class RequestBuilder
private Map<String, UpgradeActionRequired> actions; extends MasterNodeReadOperationRequestBuilder<IndexUpgradeInfoRequest, IndexUpgradeInfoResponse, RequestBuilder> {
public Response() {
}
public Response(Map<String, UpgradeActionRequired> 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<String, UpgradeActionRequired> getActions() {
return actions;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
{
builder.startObject("indices");
for (Map.Entry<String, UpgradeActionRequired> 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<Request> 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<Request, Response, RequestBuilder> {
public RequestBuilder(ElasticsearchClient client) { public RequestBuilder(ElasticsearchClient client) {
super(client, INSTANCE, new Request()); super(client, INSTANCE, new IndexUpgradeInfoRequest());
} }
public RequestBuilder setIndices(String... indices) { public RequestBuilder setIndices(String... indices) {
@ -191,5 +43,4 @@ public class IndexUpgradeInfoAction extends Action<IndexUpgradeInfoAction.Respon
return this; return this;
} }
} }
}
}

View File

@ -13,11 +13,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.reindex.BulkByScrollResponse; import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.transport.TransportResponse; import org.elasticsearch.transport.TransportResponse;
import org.elasticsearch.xpack.core.upgrade.IndexUpgradeCheckVersion; import org.elasticsearch.xpack.core.upgrade.IndexUpgradeCheckVersion;
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;

View File

@ -16,8 +16,8 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.reindex.BulkByScrollResponse; import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;

View File

@ -17,17 +17,19 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.XPackField;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction; import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
import org.elasticsearch.xpack.upgrade.IndexUpgradeService; import org.elasticsearch.xpack.upgrade.IndexUpgradeService;
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import java.util.Map; import java.util.Map;
public class TransportIndexUpgradeInfoAction extends TransportMasterNodeReadAction<IndexUpgradeInfoAction.Request, public class TransportIndexUpgradeInfoAction
IndexUpgradeInfoAction.Response> { extends TransportMasterNodeReadAction<IndexUpgradeInfoRequest, IndexUpgradeInfoResponse> {
private final IndexUpgradeService indexUpgradeService; private final IndexUpgradeService indexUpgradeService;
private final XPackLicenseState licenseState; private final XPackLicenseState licenseState;
@ -40,7 +42,7 @@ public class TransportIndexUpgradeInfoAction extends TransportMasterNodeReadActi
IndexNameExpressionResolver indexNameExpressionResolver, IndexNameExpressionResolver indexNameExpressionResolver,
XPackLicenseState licenseState) { XPackLicenseState licenseState) {
super(settings, IndexUpgradeInfoAction.NAME, transportService, clusterService, threadPool, actionFilters, super(settings, IndexUpgradeInfoAction.NAME, transportService, clusterService, threadPool, actionFilters,
IndexUpgradeInfoAction.Request::new, indexNameExpressionResolver); IndexUpgradeInfoRequest::new, indexNameExpressionResolver);
this.indexUpgradeService = indexUpgradeService; this.indexUpgradeService = indexUpgradeService;
this.licenseState = licenseState; this.licenseState = licenseState;
} }
@ -51,23 +53,23 @@ public class TransportIndexUpgradeInfoAction extends TransportMasterNodeReadActi
} }
@Override @Override
protected IndexUpgradeInfoAction.Response newResponse() { protected IndexUpgradeInfoResponse newResponse() {
return new IndexUpgradeInfoAction.Response(); return new IndexUpgradeInfoResponse();
} }
@Override @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 // Cluster is not affected but we look up repositories in metadata
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
} }
@Override @Override
protected final void masterOperation(final IndexUpgradeInfoAction.Request request, ClusterState state, protected final void masterOperation(final IndexUpgradeInfoRequest request, ClusterState state,
final ActionListener<IndexUpgradeInfoAction.Response> listener) { final ActionListener<IndexUpgradeInfoResponse> listener) {
if (licenseState.isUpgradeAllowed()) { if (licenseState.isUpgradeAllowed()) {
Map<String, UpgradeActionRequired> results = Map<String, UpgradeActionRequired> results =
indexUpgradeService.upgradeInfo(request.indices(), request.indicesOptions(), state); indexUpgradeService.upgradeInfo(request.indices(), request.indicesOptions(), state);
listener.onResponse(new IndexUpgradeInfoAction.Response(results)); listener.onResponse(new IndexUpgradeInfoResponse(results));
} else { } else {
listener.onFailure(LicenseUtils.newComplianceException(XPackField.UPGRADE)); listener.onFailure(LicenseUtils.newComplianceException(XPackField.UPGRADE));
} }

View File

@ -9,12 +9,12 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction; import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction.Request;
import java.io.IOException; import java.io.IOException;
@ -41,7 +41,7 @@ public class RestIndexUpgradeInfoAction extends BaseRestHandler {
} }
private RestChannelConsumer handleGet(final RestRequest request, NodeClient client) { 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())); infoRequest.indicesOptions(IndicesOptions.fromRequest(request, infoRequest.indicesOptions()));
return channel -> client.execute(IndexUpgradeInfoAction.INSTANCE, infoRequest, new RestToXContentListener<>(channel)); return channel -> client.execute(IndexUpgradeInfoAction.INSTANCE, infoRequest, new RestToXContentListener<>(channel));
} }

View File

@ -14,12 +14,12 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.reindex.BulkByScrollResponse; 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.tasks.TaskId;
import org.elasticsearch.transport.TransportResponse; 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.IndexUpgradeAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction; import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction.Response;
import org.junit.Before; import org.junit.Before;
import java.util.Collections; 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 // Testing only negative case here, the positive test is done in bwcTests
assertAcked(client().admin().indices().prepareCreate("test").get()); assertAcked(client().admin().indices().prepareCreate("test").get());
ensureYellow("test"); 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()); assertThat(response.getActions().entrySet(), empty());
} }
@ -57,7 +57,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase {
() -> new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get()); () -> new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get());
assertThat(e.getMessage(), equalTo("current license is non-compliant for [upgrade]")); assertThat(e.getMessage(), equalTo("current license is non-compliant for [upgrade]"));
enableLicensing(); enableLicensing();
Response response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get(); IndexUpgradeInfoResponse response = new IndexUpgradeInfoAction.RequestBuilder(client()).setIndices("test").get();
assertThat(response.getActions().entrySet(), empty()); assertThat(response.getActions().entrySet(), empty());
} }
@ -132,7 +132,7 @@ public class IndexUpgradeIT extends IndexUpgradeIntegTestCase {
public void testIndexUpgradeInfoOnEmptyCluster() { public void testIndexUpgradeInfoOnEmptyCluster() {
// On empty cluster asking for all indices shouldn't fail since no indices means nothing needs to be upgraded // 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()); assertThat(response.getActions().entrySet(), empty());
// but calling on a particular index should fail // but calling on a particular index should fail

View File

@ -15,8 +15,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;

View File

@ -30,6 +30,8 @@ import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.plugins.ScriptPlugin; 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.MockScriptEngine;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContext;
@ -39,7 +41,6 @@ import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService; 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.UpgradeField;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction; import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction;
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction; import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
@ -171,7 +172,7 @@ public class IndexUpgradeTasksIT extends ESIntegTestCase {
ensureYellow("test"); 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().keySet(), contains("test"));
assertThat(infoResponse.getActions().get("test"), equalTo(UpgradeActionRequired.UPGRADE)); assertThat(infoResponse.getActions().get("test"), equalTo(UpgradeActionRequired.UPGRADE));

View File

@ -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<Request> {
@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<Request> instanceReader() {
return Request::new;
}
}

View File

@ -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<Response> {
@Override
protected Response createTestInstance() {
int actionsCount = randomIntBetween(0, 5);
Map<String, UpgradeActionRequired> 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();
}
}

View File

@ -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<IndexUpgradeInfoRequest> 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());
}
}

View File

@ -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<IndexUpgradeInfoResponse, String> PARSER =
new ConstructingObjectParser<>("IndexUpgradeInfoResponse",
true,
(a, c) -> {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>)a[0];
Map<String, UpgradeActionRequired> actionsRequired = map.entrySet().stream()
.filter(e -> {
if (e.getValue() instanceof Map == false) {
return false;
}
@SuppressWarnings("unchecked")
Map<String, Object> value =(Map<String, Object>)e.getValue();
return value.containsKey(ACTION_REQUIRED.getPreferredName());
})
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> {
@SuppressWarnings("unchecked")
Map<String, Object> value = (Map<String, Object>) 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<String, UpgradeActionRequired> actions;
public IndexUpgradeInfoResponse() {
}
public IndexUpgradeInfoResponse(Map<String, UpgradeActionRequired> 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<String, UpgradeActionRequired> getActions() {
return actions;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
{
builder.startObject(INDICES.getPreferredName());
for (Map.Entry<String, UpgradeActionRequired> 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);
}
}

View File

@ -1,9 +1,22 @@
/* /*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * Licensed to Elasticsearch under one or more contributor
* or more contributor license agreements. Licensed under the Elastic License; * license agreements. See the NOTICE file distributed with
* you may not use this file except in compliance with the Elastic License. * 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.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;

View File

@ -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;

View File

@ -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<IndexUpgradeInfoRequest> {
@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<IndexUpgradeInfoRequest> instanceReader() {
return IndexUpgradeInfoRequest::new;
}
public void testNullIndices() {
expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest((String[])null));
expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest().indices((String[])null));
}
}

View File

@ -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<IndexUpgradeInfoResponse> {
@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<String, UpgradeActionRequired> 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<String, UpgradeActionRequired> actions = new HashMap<>(instance.getActions());
if (randomBoolean()) {
Iterator<Map.Entry<String, UpgradeActionRequired>> iterator = actions.entrySet().iterator();
iterator.next();
iterator.remove();
} else {
actions.put(randomAlphaOfLength(5), randomFrom(UpgradeActionRequired.values()));
}
return new IndexUpgradeInfoResponse(actions);
}
}