diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java index 9eed1f757b5b1..99d59ff612221 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java @@ -266,7 +266,6 @@ public void testLargeClusterStatePublishing() throws Exception { MappingMetadata mappingMetadata = client.admin() .indices() .prepareGetMappings(TEST_REQUEST_TIMEOUT, "test") - .setLocal(true) .get() .getMappings() .get("test"); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java index 72e5bb0085de6..622b4d58a6a98 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.tasks.CancellableTask; import org.elasticsearch.tasks.Task; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import java.util.Collections; @@ -49,23 +48,13 @@ public class TransportGetIndexAction extends TransportClusterInfoAction mappings) { this.mappings = mappings; } - GetMappingsResponse(StreamInput in) throws IOException { - super(in); - mappings = in.readImmutableMap(in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> { - int mappingCount = i.readVInt(); - assert mappingCount == 1 || mappingCount == 0 : "Expected 0 or 1 mappings but got " + mappingCount; - if (mappingCount == 1) { - String type = i.readString(); - assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got [" + type + "]"; - return new MappingMetadata(i); - } else { - return MappingMetadata.EMPTY_MAPPINGS; - } - } : i -> i.readBoolean() ? new MappingMetadata(i) : MappingMetadata.EMPTY_MAPPINGS); - } - public Map mappings() { return mappings; } @@ -58,6 +41,11 @@ public Map getMappings() { return mappings(); } + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to write these responses until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) @Override public void writeTo(StreamOutput out) throws IOException { MappingMetadata.writeMappingMetadata(out, mappings); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java index 8b5d15661faf0..8ce321137ee0a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.tasks.CancellableTask; import org.elasticsearch.tasks.Task; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import java.util.Map; @@ -38,7 +37,6 @@ public class TransportGetMappingsAction extends TransportClusterInfoAction> extends MasterNodeReadRequest +public abstract class ClusterInfoRequest> extends LocalClusterStateRequest implements IndicesRequest.Replaceable { @@ -37,18 +37,11 @@ public ClusterInfoRequest(TimeValue masterTimeout, IndicesOptions indicesOptions this.indicesOptions = indicesOptions; } - @Deprecated(forRemoval = true) - public ClusterInfoRequest() { - super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT); - } - - // So subclasses can override the default indices options, if needed - @Deprecated(forRemoval = true) - protected ClusterInfoRequest(IndicesOptions indicesOptions) { - super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT); - this.indicesOptions = indicesOptions; - } - + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to read these requests until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) public ClusterInfoRequest(StreamInput in) throws IOException { super(in); indices = in.readStringArray(); @@ -58,16 +51,6 @@ public ClusterInfoRequest(StreamInput in) throws IOException { indicesOptions = IndicesOptions.readIndicesOptions(in); } - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeStringArray(indices); - if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) { - out.writeStringArray(Strings.EMPTY_ARRAY); - } - indicesOptions.writeIndicesOptions(out); - } - @Override @SuppressWarnings("unchecked") public Request indices(String... indices) { diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java index 94db1c1dd6977..3c39874a0f4cc 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java @@ -8,20 +8,17 @@ */ package org.elasticsearch.action.support.master.info; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.client.internal.ElasticsearchClient; import org.elasticsearch.common.util.ArrayUtils; public abstract class ClusterInfoRequestBuilder< Request extends ClusterInfoRequest, Response extends ActionResponse, - Builder extends ClusterInfoRequestBuilder> extends MasterNodeReadOperationRequestBuilder< - Request, - Response, - Builder> { + Builder extends ClusterInfoRequestBuilder> extends ActionRequestBuilder { protected ClusterInfoRequestBuilder(ElasticsearchClient client, ActionType action, Request request) { super(client, action, request); diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java b/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java index d521cf9e23b61..edb5bad95f674 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java @@ -11,40 +11,48 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; +import org.elasticsearch.action.support.ChannelActionListener; +import org.elasticsearch.action.support.local.TransportLocalClusterStateAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.util.concurrent.EsExecutors; +import org.elasticsearch.core.UpdateForV10; import org.elasticsearch.tasks.Task; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; public abstract class TransportClusterInfoAction, Response extends ActionResponse> extends - TransportMasterNodeReadAction { + TransportLocalClusterStateAction { + protected final IndexNameExpressionResolver indexNameExpressionResolver; + + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC it must be registered with the TransportService until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) + @SuppressWarnings("this-escape") public TransportClusterInfoAction( String actionName, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, Writeable.Reader request, - IndexNameExpressionResolver indexNameExpressionResolver, - Writeable.Reader response + IndexNameExpressionResolver indexNameExpressionResolver ) { - super( + super(actionName, actionFilters, transportService.getTaskManager(), clusterService, EsExecutors.DIRECT_EXECUTOR_SERVICE); + this.indexNameExpressionResolver = indexNameExpressionResolver; + + transportService.registerRequestHandler( actionName, - transportService, - clusterService, - threadPool, - actionFilters, + executor, + false, + true, request, - indexNameExpressionResolver, - response, - threadPool.executor(ThreadPool.Names.MANAGEMENT) + (r, channel, task) -> executeDirect(task, r, new ChannelActionListener<>(channel)) ); } @@ -55,7 +63,7 @@ protected ClusterBlockException checkBlock(Request request, ClusterState state) } @Override - protected final void masterOperation( + protected final void localClusterStateOperation( Task task, final Request request, final ClusterState state, diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java index e49efc80250ac..c7d0a1d713806 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestUtils; import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.ServerlessScope; import org.elasticsearch.rest.action.RestCancellableNodeClient; @@ -27,7 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; -import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; /** * The REST handler for get index and head index APIs. @@ -48,10 +48,10 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String[] indices = Strings.splitStringByCommaToArray(request.param("index")); - final GetIndexRequest getIndexRequest = new GetIndexRequest(getMasterNodeTimeout(request)); + final GetIndexRequest getIndexRequest = new GetIndexRequest(RestUtils.getMasterNodeTimeout(request)); getIndexRequest.indices(indices); getIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, getIndexRequest.indicesOptions())); - getIndexRequest.local(request.paramAsBoolean("local", getIndexRequest.local())); + RestUtils.consumeDeprecatedLocalParameter(request); getIndexRequest.humanReadable(request.paramAsBoolean("human", false)); getIndexRequest.includeDefaults(request.paramAsBoolean("include_defaults", false)); getIndexRequest.features(GetIndexRequest.Feature.fromRequest(request)); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java index f9e02646041a6..a87e0d77e9bd3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java @@ -16,6 +16,7 @@ import org.elasticsearch.http.HttpChannel; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestUtils; import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.ServerlessScope; import org.elasticsearch.rest.action.RestCancellableNodeClient; @@ -25,7 +26,6 @@ import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; @ServerlessScope(Scope.PUBLIC) public class RestGetMappingAction extends BaseRestHandler { @@ -50,10 +50,10 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); - final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(getMasterNodeTimeout(request)); + final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(RestUtils.getMasterNodeTimeout(request)); getMappingsRequest.indices(indices); getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions())); - getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local())); + RestUtils.consumeDeprecatedLocalParameter(request); final HttpChannel httpChannel = request.getHttpChannel(); return channel -> new RestCancellableNodeClient(client, httpChannel).admin() .indices() diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java index e36cbd4fe93a3..c29fb434490b4 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java @@ -115,7 +115,6 @@ class TestTransportGetIndexAction extends TransportGetIndexAction { super( GetIndexActionTests.this.transportService, GetIndexActionTests.this.clusterService, - GetIndexActionTests.this.threadPool, settingsFilter, new ActionFilters(emptySet()), new GetIndexActionTests.Resolver(), diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java deleted file mode 100644 index db63a86ffd0b4..0000000000000 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java +++ /dev/null @@ -1,113 +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 - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.action.admin.indices.mapping.get; - -import org.elasticsearch.cluster.metadata.MappingMetadata; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.test.AbstractChunkedSerializingTestCase; -import org.elasticsearch.test.AbstractWireSerializingTestCase; -import org.elasticsearch.test.EqualsHashCodeTestUtils; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -public class GetMappingsResponseTests extends AbstractWireSerializingTestCase { - - public void testCheckEqualsAndHashCode() { - GetMappingsResponse resp = createTestInstance(); - EqualsHashCodeTestUtils.checkEqualsAndHashCode(resp, r -> new GetMappingsResponse(r.mappings()), GetMappingsResponseTests::mutate); - } - - @Override - protected Writeable.Reader instanceReader() { - return GetMappingsResponse::new; - } - - private static GetMappingsResponse mutate(GetMappingsResponse original) { - Map builder = new HashMap<>(original.mappings()); - String indexKey = original.mappings().keySet().iterator().next(); - builder.put(indexKey + "1", createMappingsForIndex()); - return new GetMappingsResponse(builder); - } - - @Override - protected GetMappingsResponse mutateInstance(GetMappingsResponse instance) { - return mutate(instance); - } - - public static MappingMetadata createMappingsForIndex() { - Map mappings = new HashMap<>(); - if (rarely() == false) { // rarely have no fields - mappings.put("field", randomFieldMapping()); - if (randomBoolean()) { - mappings.put("field2", randomFieldMapping()); - } - String typeName = MapperService.SINGLE_MAPPING_NAME; - return new MappingMetadata(typeName, mappings); - } - return new MappingMetadata(MapperService.SINGLE_MAPPING_NAME, mappings); - } - - @Override - protected GetMappingsResponse createTestInstance() { - GetMappingsResponse resp = new GetMappingsResponse(Map.of("index-" + randomAlphaOfLength(5), createMappingsForIndex())); - logger.debug("--> created: {}", resp); - return resp; - } - - public void testChunking() { - AbstractChunkedSerializingTestCase.assertChunkCount( - new GetMappingsResponse( - IntStream.range(0, randomIntBetween(1, 10)) - .mapToObj(i -> "index-" + i) - .collect(Collectors.toUnmodifiableMap(Function.identity(), k -> createMappingsForIndex())) - ), - response -> response.mappings().size() + 2 - ); - } - - // Not meant to be exhaustive - private static Map randomFieldMapping() { - Map mappings = new HashMap<>(); - if (randomBoolean()) { - mappings.put("type", randomBoolean() ? "text" : "keyword"); - mappings.put("index", "analyzed"); - mappings.put("analyzer", "english"); - } else if (randomBoolean()) { - mappings.put("type", randomFrom("integer", "float", "long", "double")); - mappings.put("index", Objects.toString(randomBoolean())); - } else if (randomBoolean()) { - mappings.put("type", "object"); - mappings.put("dynamic", "strict"); - Map properties = new HashMap<>(); - Map props1 = new HashMap<>(); - props1.put("type", randomFrom("text", "keyword")); - props1.put("analyzer", "keyword"); - properties.put("subtext", props1); - Map props2 = new HashMap<>(); - props2.put("type", "object"); - Map prop2properties = new HashMap<>(); - Map props3 = new HashMap<>(); - props3.put("type", "integer"); - props3.put("index", "false"); - prop2properties.put("subsubfield", props3); - props2.put("properties", prop2properties); - mappings.put("properties", properties); - } else { - mappings.put("type", "keyword"); - } - return mappings; - } -} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequest.java index beff1e6ab39de..0a04d6358420d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequest.java @@ -10,8 +10,8 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.info.ClusterInfoRequest; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.core.UpdateForV10; import java.io.IOException; import java.util.Arrays; @@ -32,19 +32,17 @@ public ExplainLifecycleRequest(TimeValue masterTimeout) { super(masterTimeout); } + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to read these requests until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) public ExplainLifecycleRequest(StreamInput in) throws IOException { super(in); onlyErrors = in.readBoolean(); onlyManaged = in.readBoolean(); } - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeBoolean(onlyErrors); - out.writeBoolean(onlyManaged); - } - public boolean onlyErrors() { return onlyErrors; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponse.java index 914a025e35c21..1f17539037023 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponse.java @@ -9,9 +9,8 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.util.Maps; +import org.elasticsearch.core.UpdateForV10; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xcontent.XContentBuilder; @@ -32,17 +31,6 @@ public class ExplainLifecycleResponse extends ActionResponse implements ToXConte private final Map indexResponses; - public ExplainLifecycleResponse(StreamInput in) throws IOException { - super(in); - int size = in.readVInt(); - Map indexResponses = Maps.newMapWithExpectedSize(size); - for (int i = 0; i < size; i++) { - IndexLifecycleExplainResponse indexResponse = new IndexLifecycleExplainResponse(in); - indexResponses.put(indexResponse.getIndex(), indexResponse); - } - this.indexResponses = indexResponses; - } - public ExplainLifecycleResponse(Map indexResponses) { this.indexResponses = indexResponses; } @@ -69,6 +57,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } + /** + * NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to write these responses until + * we no longer need to support calling this action remotely. + */ + @UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) @Override public void writeTo(StreamOutput out) throws IOException { out.writeCollection(indexResponses.values()); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequestTests.java deleted file mode 100644 index 6cea7100a9da9..0000000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleRequestTests.java +++ /dev/null @@ -1,87 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.core.ilm; - -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.common.io.stream.Writeable.Reader; -import org.elasticsearch.test.AbstractWireSerializingTestCase; - -import java.util.Arrays; - -public class ExplainLifecycleRequestTests extends AbstractWireSerializingTestCase { - - @Override - protected ExplainLifecycleRequest createTestInstance() { - ExplainLifecycleRequest request = new ExplainLifecycleRequest(TEST_REQUEST_TIMEOUT); - if (randomBoolean()) { - request.indices(generateRandomStringArray(20, 20, false, false)); - } - if (randomBoolean()) { - IndicesOptions indicesOptions = IndicesOptions.fromOptions( - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean() - ); - request.indicesOptions(indicesOptions); - } - if (randomBoolean()) { - request.onlyErrors(randomBoolean()); - } - if (randomBoolean()) { - request.onlyManaged(randomBoolean()); - } - return request; - } - - @Override - protected ExplainLifecycleRequest mutateInstance(ExplainLifecycleRequest instance) { - String[] indices = instance.indices(); - IndicesOptions indicesOptions = instance.indicesOptions(); - boolean onlyErrors = instance.onlyErrors(); - boolean onlyManaged = instance.onlyManaged(); - switch (between(0, 3)) { - case 0 -> indices = randomValueOtherThanMany( - i -> Arrays.equals(i, instance.indices()), - () -> generateRandomStringArray(20, 10, false, false) - ); - case 1 -> indicesOptions = randomValueOtherThan( - indicesOptions, - () -> IndicesOptions.fromOptions( - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean(), - randomBoolean() - ) - ); - case 2 -> onlyErrors = onlyErrors == false; - case 3 -> onlyManaged = onlyManaged == false; - default -> throw new AssertionError("Illegal randomisation branch"); - } - ExplainLifecycleRequest newRequest = new ExplainLifecycleRequest(TEST_REQUEST_TIMEOUT); - newRequest.indices(indices); - newRequest.indicesOptions(indicesOptions); - newRequest.onlyErrors(onlyErrors); - newRequest.onlyManaged(onlyManaged); - return newRequest; - } - - @Override - protected Reader instanceReader() { - return ExplainLifecycleRequest::new; - } - -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponseTests.java deleted file mode 100644 index c4138d228719e..0000000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ExplainLifecycleResponseTests.java +++ /dev/null @@ -1,96 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.core.ilm; - -import org.elasticsearch.cluster.ClusterModule; -import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.util.CollectionUtils; -import org.elasticsearch.test.AbstractXContentSerializingTestCase; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.NamedXContentRegistry; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class ExplainLifecycleResponseTests extends AbstractXContentSerializingTestCase { - - @SuppressWarnings("unchecked") - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "explain_lifecycle_response", - a -> new ExplainLifecycleResponse( - ((List) a[0]).stream() - .collect(Collectors.toMap(IndexLifecycleExplainResponse::getIndex, Function.identity())) - ) - ); - static { - PARSER.declareNamedObjects( - ConstructingObjectParser.constructorArg(), - (p, c, n) -> IndexLifecycleExplainResponse.PARSER.apply(p, c), - ExplainLifecycleResponse.INDICES_FIELD - ); - } - - @Override - protected ExplainLifecycleResponse createTestInstance() { - Map indexResponses = new HashMap<>(); - long now = System.currentTimeMillis(); - for (int i = 0; i < randomIntBetween(0, 2); i++) { - IndexLifecycleExplainResponse indexResponse = IndexLifecycleExplainResponseTests.randomIndexExplainResponse(); - // Since the age is calculated from now, we make now constant so that we don't get changes in age during the run of the test: - indexResponse.nowSupplier = () -> now; - indexResponses.put(indexResponse.getIndex(), indexResponse); - } - return new ExplainLifecycleResponse(indexResponses); - } - - @Override - protected Writeable.Reader instanceReader() { - return ExplainLifecycleResponse::new; - } - - @Override - protected ExplainLifecycleResponse mutateInstance(ExplainLifecycleResponse response) { - Map indexResponses = new HashMap<>(response.getIndexResponses()); - IndexLifecycleExplainResponse indexResponse = IndexLifecycleExplainResponseTests.randomIndexExplainResponse(); - indexResponses.put(indexResponse.getIndex(), indexResponse); - return new ExplainLifecycleResponse(indexResponses); - } - - @Override - protected ExplainLifecycleResponse doParseInstance(XContentParser parser) throws IOException { - return PARSER.apply(parser, null); - } - - @Override - protected boolean assertToXContentEquivalence() { - return false; - } - - protected NamedWriteableRegistry getNamedWriteableRegistry() { - return new NamedWriteableRegistry( - List.of(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new)) - ); - } - - @Override - protected NamedXContentRegistry xContentRegistry() { - return new NamedXContentRegistry( - CollectionUtils.appendToCopy( - ClusterModule.getNamedXWriteables(), - new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(MockAction.NAME), MockAction::parse) - ) - ); - } -} diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java index 85acc3fa8da6f..cc75775fbdfc4 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.tasks.Task; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.XContentParser; @@ -55,7 +54,6 @@ public class TransportExplainLifecycleAction extends TransportClusterInfoAction< public TransportExplainLifecycleAction( TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, NamedXContentRegistry xContentRegistry, @@ -65,11 +63,9 @@ public TransportExplainLifecycleAction( ExplainLifecycleAction.NAME, transportService, clusterService, - threadPool, actionFilters, ExplainLifecycleRequest::new, - indexNameExpressionResolver, - ExplainLifecycleResponse::new + indexNameExpressionResolver ); this.xContentRegistry = xContentRegistry; this.indexLifecycleService = indexLifecycleService; diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java index e910945830836..1136dde863749 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java @@ -263,8 +263,7 @@ private void resolveIndices( ) { if (retrieveIndices || retrieveFrozenIndices) { if (clusterIsLocal(clusterWildcard)) { // resolve local indices - GetIndexRequest indexRequest = new GetIndexRequest(MasterNodeRequest.INFINITE_MASTER_NODE_TIMEOUT).local(true) - .indices(indexWildcards) + GetIndexRequest indexRequest = new GetIndexRequest(MasterNodeRequest.INFINITE_MASTER_NODE_TIMEOUT).indices(indexWildcards) .features(Feature.SETTINGS) .includeDefaults(false) .indicesOptions(INDICES_ONLY_OPTIONS);