Skip to content

Commit d2d03a0

Browse files
committed
Clean up TransportRemoteClusterStatsAction (#117119)
No need to have an `ActionType<>` here since we never register this as an action the `Client` can invoke. Also no need to use a dummy constructor parameter just to trick the injector into instantiating it, we can instantiate it ourselves like we do with all other subsidiary transport-only actions. Also fixes the parent task so the remote action is a child of the local action rather than a sibling.
1 parent e45a7b1 commit d2d03a0

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
4848
return new CancellableTask(id, type, action, "", parentTaskId, headers);
4949
}
5050

51-
public ClusterStatsRequest asRemoteStats() {
52-
this.remoteStats = true;
53-
return this;
51+
public static ClusterStatsRequest newRemoteClusterStatsRequest() {
52+
final var request = new ClusterStatsRequest();
53+
request.remoteStats = true;
54+
return request;
5455
}
5556

5657
/**

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.action.support.RefCountingListener;
2929
import org.elasticsearch.action.support.SubscribableListener;
3030
import org.elasticsearch.action.support.nodes.TransportNodesAction;
31+
import org.elasticsearch.client.internal.Client;
3132
import org.elasticsearch.cluster.ClusterSnapshotStats;
3233
import org.elasticsearch.cluster.ClusterState;
3334
import org.elasticsearch.cluster.health.ClusterHealthStatus;
@@ -111,20 +112,19 @@ public class TransportClusterStatsAction extends TransportNodesAction<
111112
private final MetadataStatsCache<MappingStats> mappingStatsCache;
112113
private final MetadataStatsCache<AnalysisStats> analysisStatsCache;
113114
private final RemoteClusterService remoteClusterService;
114-
private final TransportRemoteClusterStatsAction remoteClusterStatsAction;
115115

116116
@Inject
117117
public TransportClusterStatsAction(
118118
ThreadPool threadPool,
119119
ClusterService clusterService,
120120
TransportService transportService,
121+
Client client,
121122
NodeService nodeService,
122123
IndicesService indicesService,
123124
RepositoriesService repositoriesService,
124125
UsageService usageService,
125126
ActionFilters actionFilters,
126-
Settings settings,
127-
TransportRemoteClusterStatsAction remoteClusterStatsAction
127+
Settings settings
128128
) {
129129
super(
130130
TYPE.name(),
@@ -144,7 +144,9 @@ public TransportClusterStatsAction(
144144
this.analysisStatsCache = new MetadataStatsCache<>(threadPool.getThreadContext(), AnalysisStats::of);
145145
this.remoteClusterService = transportService.getRemoteClusterService();
146146
this.settings = settings;
147-
this.remoteClusterStatsAction = remoteClusterStatsAction;
147+
148+
// register remote-cluster action with transport service only and not as a local-node Action that the Client can invoke
149+
new TransportRemoteClusterStatsAction(client, transportService, actionFilters);
148150
}
149151

150152
@Override

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportRemoteClusterStatsAction.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
package org.elasticsearch.action.admin.cluster.stats;
1111

1212
import org.elasticsearch.action.ActionListener;
13-
import org.elasticsearch.action.ActionType;
1413
import org.elasticsearch.action.RemoteClusterActionType;
1514
import org.elasticsearch.action.support.ActionFilters;
1615
import org.elasticsearch.action.support.HandledTransportAction;
17-
import org.elasticsearch.client.internal.node.NodeClient;
16+
import org.elasticsearch.client.internal.Client;
17+
import org.elasticsearch.client.internal.ParentTaskAssigningClient;
1818
import org.elasticsearch.common.util.concurrent.EsExecutors;
1919
import org.elasticsearch.injection.guice.Inject;
2020
import org.elasticsearch.tasks.Task;
@@ -27,26 +27,26 @@
2727
public class TransportRemoteClusterStatsAction extends HandledTransportAction<RemoteClusterStatsRequest, RemoteClusterStatsResponse> {
2828

2929
public static final String NAME = "cluster:monitor/stats/remote";
30-
public static final ActionType<RemoteClusterStatsResponse> TYPE = new ActionType<>(NAME);
3130
public static final RemoteClusterActionType<RemoteClusterStatsResponse> REMOTE_TYPE = new RemoteClusterActionType<>(
3231
NAME,
3332
RemoteClusterStatsResponse::new
3433
);
35-
private final NodeClient client;
34+
35+
private final Client client;
36+
private final TransportService transportService;
3637

3738
@Inject
38-
public TransportRemoteClusterStatsAction(NodeClient client, TransportService transportService, ActionFilters actionFilters) {
39+
public TransportRemoteClusterStatsAction(Client client, TransportService transportService, ActionFilters actionFilters) {
3940
super(NAME, transportService, actionFilters, RemoteClusterStatsRequest::new, EsExecutors.DIRECT_EXECUTOR_SERVICE);
4041
this.client = client;
42+
this.transportService = transportService;
4143
}
4244

4345
@Override
4446
protected void doExecute(Task task, RemoteClusterStatsRequest request, ActionListener<RemoteClusterStatsResponse> listener) {
45-
ClusterStatsRequest subRequest = new ClusterStatsRequest().asRemoteStats();
46-
subRequest.setParentTask(request.getParentTask());
47-
client.execute(
47+
new ParentTaskAssigningClient(client, transportService.getLocalNode(), task).execute(
4848
TransportClusterStatsAction.TYPE,
49-
subRequest,
49+
ClusterStatsRequest.newRemoteClusterStatsRequest(),
5050
listener.map(
5151
clusterStatsResponse -> new RemoteClusterStatsResponse(
5252
clusterStatsResponse.getClusterUUID(),

0 commit comments

Comments
 (0)