Skip to content

Commit 4dfe026

Browse files
committed
change to TransportLocalProjectMetadataAction
1 parent edb43e5 commit 4dfe026

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/action/GetSnapshotLifecycleStatsAction.java

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
package org.elasticsearch.xpack.core.slm.action;
99

10-
import org.elasticsearch.action.ActionRequestValidationException;
1110
import org.elasticsearch.action.ActionResponse;
1211
import org.elasticsearch.action.ActionType;
12+
import org.elasticsearch.action.support.local.LocalClusterStateRequest;
1313
import org.elasticsearch.action.support.master.AcknowledgedRequest;
14-
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
1514
import org.elasticsearch.common.Strings;
1615
import org.elasticsearch.common.io.stream.StreamInput;
1716
import org.elasticsearch.common.io.stream.StreamOutput;
1817
import org.elasticsearch.core.TimeValue;
18+
import org.elasticsearch.core.UpdateForV10;
1919
import org.elasticsearch.logging.LogManager;
2020
import org.elasticsearch.logging.Logger;
2121
import org.elasticsearch.xcontent.ToXContentObject;
@@ -40,55 +40,50 @@ protected GetSnapshotLifecycleStatsAction() {
4040
super(NAME);
4141
}
4242

43-
public static class Request extends MasterNodeReadRequest<Request> {
43+
public static class Request extends LocalClusterStateRequest {
44+
// TODO: remove
4445
private static final Logger logger = LogManager.getLogger(GetSnapshotLifecycleStatsAction.Request.class);
4546

46-
// for backwards compatibility, store the ack timeout to maintain compatibility with AcknowledgedRequest used in previous versions
47-
private final TimeValue ackTimeout;
47+
// // for backwards compatibility, store the ack timeout to maintain compatibility with AcknowledgedRequest used in previous
48+
// versions
49+
// private final TimeValue ackTimeout;
4850

49-
// private to avoid non-backwards compatible instantiation
50-
private Request(StreamInput input) throws IOException {
51-
super(input);
52-
this.ackTimeout = null;
53-
}
54-
55-
// private, should not be used directly
56-
private Request(TimeValue masterNodeTimeout, TimeValue ackTimeout) {
51+
public Request(TimeValue masterNodeTimeout) throws IOException {
5752
super(masterNodeTimeout);
58-
this.ackTimeout = ackTimeout;
53+
// this.ackTimeout = null;
5954
}
6055

61-
public Request(TimeValue masterNodeTimeout) throws IOException {
62-
super(masterNodeTimeout);
63-
this.ackTimeout = null;
56+
// private, to avoid non-backwards compatible use
57+
private Request(StreamInput input) throws IOException {
58+
super(input);
59+
// this.ackTimeout = null;
6460
}
6561

62+
// private, should not be used directly
63+
// private Request(TimeValue masterNodeTimeout, TimeValue ackTimeout) {
64+
// super(masterNodeTimeout);
65+
// this.ackTimeout = ackTimeout;
66+
// }
67+
68+
/**
69+
* Previously this request was an AcknowledgedRequest, which had an ack timeout, and the action was an MasterNodeAction.
70+
* This method only exists for backward compatibility to deserialize request from previous versions.
71+
*/
72+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
6673
public static Request read(StreamInput input) throws IOException {
74+
// TODO: remove logs
6775
logger.info("Reading GetSnapshotLifecycleStatsAction.Request from stream input");
6876
if (input.getTransportVersion().onOrAfter(SLM_GET_STATS_CHANGE_REQUEST_TYPE)) {
69-
logger.info("Reading old GetSnapshotLifecycleStatsAction.Request format");
77+
logger.info("Reading new GetSnapshotLifecycleStatsAction.Request format");
7078
return new Request(input);
7179
} else {
72-
logger.info("Reading new GetSnapshotLifecycleStatsAction.Request format");
80+
logger.info("Reading old GetSnapshotLifecycleStatsAction.Request format");
7381
var requestBwc = new AcknowledgedRequest.Plain(input);
74-
return new GetSnapshotLifecycleStatsAction.Request(requestBwc.masterNodeTimeout(), requestBwc.ackTimeout());
82+
// return new Request(requestBwc.masterNodeTimeout(), requestBwc.ackTimeout());
83+
return new Request(requestBwc.masterNodeTimeout());
7584
}
7685
}
7786

78-
@Override
79-
public void writeTo(StreamOutput out) throws IOException {
80-
if (out.getTransportVersion().onOrAfter(SLM_GET_STATS_CHANGE_REQUEST_TYPE)) {
81-
super.writeTo(out);
82-
} else {
83-
// For backwards compatibility, write the request as an AcknowledgedRequest
84-
new AcknowledgedRequest.Plain(this.masterNodeTimeout(), this.ackTimeout).writeTo(out);
85-
}
86-
}
87-
88-
@Override
89-
public ActionRequestValidationException validate() {
90-
return null;
91-
}
9287
}
9388

9489
public static class Response extends ActionResponse implements ToXContentObject {

x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/action/TransportGetSnapshotLifecycleStatsAction.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
import org.elasticsearch.action.ActionListener;
1111
import org.elasticsearch.action.support.ActionFilters;
12-
import org.elasticsearch.action.support.master.TransportMasterNodeReadProjectAction;
12+
import org.elasticsearch.action.support.ChannelActionListener;
13+
import org.elasticsearch.action.support.local.TransportLocalProjectMetadataAction;
1314
import org.elasticsearch.cluster.ProjectState;
1415
import org.elasticsearch.cluster.block.ClusterBlockException;
1516
import org.elasticsearch.cluster.block.ClusterBlockLevel;
@@ -18,47 +19,55 @@
1819
import org.elasticsearch.common.util.concurrent.EsExecutors;
1920
import org.elasticsearch.injection.guice.Inject;
2021
import org.elasticsearch.tasks.Task;
21-
import org.elasticsearch.threadpool.ThreadPool;
2222
import org.elasticsearch.transport.TransportService;
2323
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata;
2424
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats;
2525
import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleStatsAction;
2626

27-
public class TransportGetSnapshotLifecycleStatsAction extends TransportMasterNodeReadProjectAction<
27+
public class TransportGetSnapshotLifecycleStatsAction extends TransportLocalProjectMetadataAction<
2828
GetSnapshotLifecycleStatsAction.Request,
2929
GetSnapshotLifecycleStatsAction.Response> {
3030

3131
@Inject
3232
public TransportGetSnapshotLifecycleStatsAction(
3333
TransportService transportService,
3434
ClusterService clusterService,
35-
ThreadPool threadPool,
3635
ActionFilters actionFilters,
3736
ProjectResolver projectResolver
3837
) {
3938
super(
4039
GetSnapshotLifecycleStatsAction.NAME,
41-
transportService,
42-
clusterService,
43-
threadPool,
4440
actionFilters,
45-
// (input) -> {
46-
// if (input.getTransportVersion().onOrAfter(SLM_GET_STATS_READ_REQUEST)) {
47-
// return new GetSnapshotLifecycleStatsAction.Request(input);
48-
// } else {
49-
// var requestBwc = new AcknowledgedRequest.Plain(input);
50-
// return new GetSnapshotLifecycleStatsAction.Request(requestBwc.masterNodeTimeout());
51-
// }
52-
// },
41+
transportService.getTaskManager(),
42+
clusterService,
43+
EsExecutors.DIRECT_EXECUTOR_SERVICE,
44+
projectResolver
45+
// threadPool,
46+
// actionFilters,
47+
// (input) -> {
48+
// if (input.getTransportVersion().onOrAfter(SLM_GET_STATS_READ_REQUEST)) {
49+
// return new GetSnapshotLifecycleStatsAction.Request(input);
50+
// } else {
51+
// var requestBwc = new AcknowledgedRequest.Plain(input);
52+
// return new GetSnapshotLifecycleStatsAction.Request(requestBwc.masterNodeTimeout());
53+
// }
54+
// },
55+
// GetSnapshotLifecycleStatsAction.Request::read,
56+
// projectResolver,
57+
// GetSnapshotLifecycleStatsAction.Response::new,
58+
// EsExecutors.DIRECT_EXECUTOR_SERVICE
59+
);
60+
61+
transportService.registerRequestHandler(
62+
GetSnapshotLifecycleStatsAction.NAME,
63+
EsExecutors.DIRECT_EXECUTOR_SERVICE,
5364
GetSnapshotLifecycleStatsAction.Request::read,
54-
projectResolver,
55-
GetSnapshotLifecycleStatsAction.Response::new,
56-
EsExecutors.DIRECT_EXECUTOR_SERVICE
65+
(request, channel, task) -> executeDirect(task, request, new ChannelActionListener<>(channel))
5766
);
5867
}
5968

6069
@Override
61-
protected void masterOperation(
70+
protected void localClusterStateOperation(
6271
Task task,
6372
GetSnapshotLifecycleStatsAction.Request request,
6473
ProjectState projectState,

0 commit comments

Comments
 (0)