Skip to content

Run TransportExplainLifecycleAction on local node #122885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/122885.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 122885
summary: Run `TransportExplainLifecycleAction` on local node
area: ILM+SLM
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@

package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.info.ClusterInfoRequest;
import org.elasticsearch.action.support.local.LocalClusterStateRequest;
import org.elasticsearch.common.Strings;
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 org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -24,26 +31,58 @@
* Multiple indices may be queried in the same request using the
* {@link #indices(String...)} method
*/
public class ExplainLifecycleRequest extends ClusterInfoRequest<ExplainLifecycleRequest> {
public class ExplainLifecycleRequest extends LocalClusterStateRequest implements IndicesRequest.Replaceable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ClusterInfo classes feel a bit off; the only value they add are specifying indices and indicesOptions, but loads of other actions specify those manually. Therefore, we might as well get rid of the ClusterInfo abstraction and let every class define by themselves what fields they have.


private String[] indices = Strings.EMPTY_ARRAY;
private IndicesOptions indicesOptions;
private boolean onlyErrors = false;
private boolean onlyManaged = false;

public ExplainLifecycleRequest(TimeValue masterTimeout) {
super(masterTimeout, IndicesOptions.strictExpandOpen());
super(masterTimeout);
indicesOptions = IndicesOptions.strictExpandOpen();
}

/**
* 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);
indices = in.readStringArray();
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
in.readStringArray();
}
indicesOptions = IndicesOptions.readIndicesOptions(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 ExplainLifecycleRequest indices(String... indices) {
this.indices = indices;
return this;
}

public ExplainLifecycleRequest indicesOptions(IndicesOptions indicesOptions) {
this.indicesOptions = indicesOptions;
return this;
}

@Override
public String[] indices() {
return indices;
}

@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}

@Override
public boolean includeDataStreams() {
return true;
}

public boolean onlyErrors() {
Expand All @@ -69,6 +108,11 @@ public ActionRequestValidationException validate() {
return null;
}

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, "", parentTaskId, headers);
}

@Override
public int hashCode() {
return Objects.hash(Arrays.hashCode(indices()), indicesOptions(), onlyErrors, onlyManaged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,17 +31,6 @@ public class ExplainLifecycleResponse extends ActionResponse implements ToXConte

private final Map<String, IndexLifecycleExplainResponse> indexResponses;

public ExplainLifecycleResponse(StreamInput in) throws IOException {
super(in);
int size = in.readVInt();
Map<String, IndexLifecycleExplainResponse> 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<String, IndexLifecycleExplainResponse> indexResponses) {
this.indexResponses = indexResponses;
}
Expand All @@ -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());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestCancellableNodeClient;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest;
import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction;
Expand Down Expand Up @@ -41,6 +42,10 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
explainLifecycleRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, IndicesOptions.strictExpandOpen()));
explainLifecycleRequest.onlyManaged(restRequest.paramAsBoolean("only_managed", false));
explainLifecycleRequest.onlyErrors(restRequest.paramAsBoolean("only_errors", false));
return channel -> client.execute(ExplainLifecycleAction.INSTANCE, explainLifecycleRequest, new RestToXContentListener<>(channel));
return channel -> new RestCancellableNodeClient(client, restRequest.getHttpChannel()).execute(
ExplainLifecycleAction.INSTANCE,
explainLifecycleRequest,
new RestToXContentListener<>(channel)
);
}
}
Loading