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:
parent
02f2fad57b
commit
3e692c3f3d
|
@ -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">
|
||||
* X-Pack Licensing APIs on elastic.co</a> 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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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.
|
||||
* <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
|
||||
* are shipped with the Elastic Stack distribution of Elasticsearch. All of
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<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 {
|
||||
PutWatchRequest putWatchRequest = new PutWatchRequest();
|
||||
String watchId = randomAlphaOfLength(10);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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:
|
||||
|
||||
* <<java-rest-high-migration-get-assistance>>
|
||||
|
||||
include::migration/get-assistance.asciidoc[]
|
||||
|
||||
== Watcher APIs
|
||||
|
||||
The Java High Level REST Client supports the following Watcher APIs:
|
||||
|
|
|
@ -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<IndexUpgradeInfoAction.Response> {
|
||||
public class IndexUpgradeInfoAction extends Action<IndexUpgradeInfoResponse> {
|
||||
|
||||
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<IndexUpgradeInfoAction.Respon
|
|||
}
|
||||
|
||||
@Override
|
||||
public Response newResponse() {
|
||||
return new Response();
|
||||
public IndexUpgradeInfoResponse newResponse() {
|
||||
return new IndexUpgradeInfoResponse();
|
||||
}
|
||||
|
||||
public static class Response extends ActionResponse implements ToXContentObject {
|
||||
private Map<String, UpgradeActionRequired> actions;
|
||||
|
||||
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 static class RequestBuilder
|
||||
extends MasterNodeReadOperationRequestBuilder<IndexUpgradeInfoRequest, IndexUpgradeInfoResponse, RequestBuilder> {
|
||||
|
||||
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<IndexUpgradeInfoAction.Respon
|
|||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.tasks.TaskId;
|
||||
import org.elasticsearch.transport.TransportResponse;
|
||||
import org.elasticsearch.xpack.core.upgrade.IndexUpgradeCheckVersion;
|
||||
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
|
|
@ -16,8 +16,8 @@ import org.elasticsearch.common.component.AbstractComponent;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
|
||||
import org.elasticsearch.tasks.TaskId;
|
||||
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
|
@ -17,17 +17,19 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.LicenseUtils;
|
||||
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.transport.TransportService;
|
||||
import org.elasticsearch.xpack.core.XPackField;
|
||||
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeInfoAction;
|
||||
import org.elasticsearch.xpack.upgrade.IndexUpgradeService;
|
||||
import org.elasticsearch.xpack.core.upgrade.UpgradeActionRequired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TransportIndexUpgradeInfoAction extends TransportMasterNodeReadAction<IndexUpgradeInfoAction.Request,
|
||||
IndexUpgradeInfoAction.Response> {
|
||||
public class TransportIndexUpgradeInfoAction
|
||||
extends TransportMasterNodeReadAction<IndexUpgradeInfoRequest, IndexUpgradeInfoResponse> {
|
||||
|
||||
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<IndexUpgradeInfoAction.Response> listener) {
|
||||
protected final void masterOperation(final IndexUpgradeInfoRequest request, ClusterState state,
|
||||
final ActionListener<IndexUpgradeInfoResponse> listener) {
|
||||
if (licenseState.isUpgradeAllowed()) {
|
||||
Map<String, UpgradeActionRequired> 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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue