Skip to content

Commit 7ee8bc9

Browse files
committed
Make TransportGetSnapshotLifecycleStatsAction project aware
1 parent a78737d commit 7ee8bc9

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

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

10+
import org.elasticsearch.action.ActionRequestValidationException;
1011
import org.elasticsearch.action.ActionResponse;
1112
import org.elasticsearch.action.ActionType;
13+
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
1214
import org.elasticsearch.common.Strings;
1315
import org.elasticsearch.common.io.stream.StreamInput;
1416
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -32,6 +34,18 @@ protected GetSnapshotLifecycleStatsAction() {
3234
super(NAME);
3335
}
3436

37+
public static class Request extends MasterNodeReadRequest<Request> {
38+
39+
public Request(StreamInput input) throws IOException {
40+
super(input);
41+
}
42+
43+
@Override
44+
public ActionRequestValidationException validate() {
45+
return null;
46+
}
47+
}
48+
3549
public static class Response extends ActionResponse implements ToXContentObject {
3650

3751
private SnapshotLifecycleStats slmStats;

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
import org.elasticsearch.action.ActionListener;
1111
import org.elasticsearch.action.support.ActionFilters;
12-
import org.elasticsearch.action.support.master.AcknowledgedRequest;
13-
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
14-
import org.elasticsearch.cluster.ClusterState;
12+
import org.elasticsearch.action.support.master.TransportMasterNodeReadProjectAction;
13+
import org.elasticsearch.cluster.ProjectState;
1514
import org.elasticsearch.cluster.block.ClusterBlockException;
1615
import org.elasticsearch.cluster.block.ClusterBlockLevel;
16+
import org.elasticsearch.cluster.project.ProjectResolver;
1717
import org.elasticsearch.cluster.service.ClusterService;
1818
import org.elasticsearch.common.util.concurrent.EsExecutors;
1919
import org.elasticsearch.injection.guice.Inject;
@@ -24,24 +24,26 @@
2424
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats;
2525
import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleStatsAction;
2626

27-
public class TransportGetSnapshotLifecycleStatsAction extends TransportMasterNodeAction<
28-
AcknowledgedRequest.Plain,
27+
public class TransportGetSnapshotLifecycleStatsAction extends TransportMasterNodeReadProjectAction<
28+
GetSnapshotLifecycleStatsAction.Request,
2929
GetSnapshotLifecycleStatsAction.Response> {
3030

3131
@Inject
3232
public TransportGetSnapshotLifecycleStatsAction(
3333
TransportService transportService,
3434
ClusterService clusterService,
3535
ThreadPool threadPool,
36-
ActionFilters actionFilters
36+
ActionFilters actionFilters,
37+
ProjectResolver projectResolver
3738
) {
3839
super(
3940
GetSnapshotLifecycleStatsAction.NAME,
4041
transportService,
4142
clusterService,
4243
threadPool,
4344
actionFilters,
44-
AcknowledgedRequest.Plain::new,
45+
GetSnapshotLifecycleStatsAction.Request::new,
46+
projectResolver,
4547
GetSnapshotLifecycleStatsAction.Response::new,
4648
EsExecutors.DIRECT_EXECUTOR_SERVICE
4749
);
@@ -50,11 +52,11 @@ public TransportGetSnapshotLifecycleStatsAction(
5052
@Override
5153
protected void masterOperation(
5254
Task task,
53-
AcknowledgedRequest.Plain request,
54-
ClusterState state,
55+
GetSnapshotLifecycleStatsAction.Request request,
56+
ProjectState projectState,
5557
ActionListener<GetSnapshotLifecycleStatsAction.Response> listener
5658
) {
57-
SnapshotLifecycleMetadata slmMeta = state.metadata().getProject().custom(SnapshotLifecycleMetadata.TYPE);
59+
SnapshotLifecycleMetadata slmMeta = projectState.metadata().custom(SnapshotLifecycleMetadata.TYPE);
5860
if (slmMeta == null) {
5961
listener.onResponse(new GetSnapshotLifecycleStatsAction.Response(new SnapshotLifecycleStats()));
6062
} else {
@@ -63,7 +65,7 @@ protected void masterOperation(
6365
}
6466

6567
@Override
66-
protected ClusterBlockException checkBlock(AcknowledgedRequest.Plain request, ClusterState state) {
67-
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
68+
protected ClusterBlockException checkBlock(GetSnapshotLifecycleStatsAction.Request request, ProjectState state) {
69+
return state.blocks().globalBlockedException(state.projectId(), ClusterBlockLevel.METADATA_READ);
6870
}
6971
}

0 commit comments

Comments
 (0)