Skip to content

Commit bbdb160

Browse files
Multi-project for TransportExlainLifecycleAction
This converts this class to support multi-project.
1 parent 549fddb commit bbdb160

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.elasticsearch.cluster.metadata.IndexMetadata;
1919
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
2020
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
21-
import org.elasticsearch.cluster.metadata.Metadata;
21+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
2222
import org.elasticsearch.cluster.project.ProjectResolver;
2323
import org.elasticsearch.cluster.service.ClusterService;
2424
import org.elasticsearch.common.Strings;
@@ -56,6 +56,7 @@ public class TransportExplainLifecycleAction extends TransportLocalClusterStateA
5656

5757
private final NamedXContentRegistry xContentRegistry;
5858
private final IndexNameExpressionResolver indexNameExpressionResolver;
59+
private final ProjectResolver projectResolver;
5960

6061
/**
6162
* NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC it must be registered with the TransportService until
@@ -82,6 +83,7 @@ public TransportExplainLifecycleAction(
8283
);
8384
this.xContentRegistry = xContentRegistry;
8485
this.indexNameExpressionResolver = indexNameExpressionResolver;
86+
this.projectResolver = projectResolver;
8587

8688
transportService.registerRequestHandler(
8789
actionName,
@@ -97,7 +99,11 @@ public TransportExplainLifecycleAction(
9799
@Override
98100
protected ClusterBlockException checkBlock(ExplainLifecycleRequest request, ClusterState state) {
99101
return state.blocks()
100-
.indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
102+
.indicesBlockedException(
103+
projectResolver.getProjectId(),
104+
ClusterBlockLevel.METADATA_READ,
105+
indexNameExpressionResolver.concreteIndexNames(state, request)
106+
);
101107
}
102108

103109
@Override
@@ -117,7 +123,7 @@ protected void localClusterStateOperation(
117123
try {
118124
indexResponse = getIndexLifecycleExplainResponse(
119125
index,
120-
state.metadata(),
126+
projectResolver.getProjectMetadata(state.metadata()),
121127
request.onlyErrors(),
122128
request.onlyManaged(),
123129
xContentRegistry,
@@ -140,13 +146,12 @@ protected void localClusterStateOperation(
140146
@Nullable
141147
static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse(
142148
String indexName,
143-
Metadata metadata,
149+
ProjectMetadata project,
144150
boolean onlyErrors,
145151
boolean onlyManaged,
146152
NamedXContentRegistry xContentRegistry,
147153
boolean rolloverOnlyIfHasDocuments
148154
) throws IOException {
149-
final var project = metadata.getProject();
150155
IndexMetadata indexMetadata = project.index(indexName);
151156
Settings idxSettings = indexMetadata.getSettings();
152157
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleActionTests.java

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

1010
import org.elasticsearch.cluster.metadata.IndexMetadata;
1111
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
12-
import org.elasticsearch.cluster.metadata.Metadata;
12+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1313
import org.elasticsearch.index.IndexVersion;
1414
import org.elasticsearch.test.ESTestCase;
1515
import org.elasticsearch.xcontent.NamedXContentRegistry;
@@ -78,14 +78,14 @@ public void testGetIndexLifecycleExplainResponse() throws IOException {
7878
.numberOfReplicas(randomIntBetween(0, 5))
7979
.putCustom(ILM_CUSTOM_METADATA_KEY, errorStepState.build().asMap())
8080
.build();
81-
Metadata metadata = Metadata.builder()
81+
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
8282
.put(indexMetadata, true)
8383
.putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
8484
.build();
8585

8686
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
8787
indexInErrorStep,
88-
metadata,
88+
project,
8989
true,
9090
true,
9191
REGISTRY,
@@ -111,14 +111,14 @@ public void testGetIndexLifecycleExplainResponse() throws IOException {
111111
.numberOfReplicas(randomIntBetween(0, 5))
112112
.putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap())
113113
.build();
114-
Metadata metadata = Metadata.builder()
114+
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
115115
.put(indexMetadata, true)
116116
.putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
117117
.build();
118118

119119
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
120120
indexInCheckRolloverStep,
121-
metadata,
121+
project,
122122
true,
123123
true,
124124
REGISTRY,
@@ -128,7 +128,7 @@ public void testGetIndexLifecycleExplainResponse() throws IOException {
128128

129129
IndexLifecycleExplainResponse allManagedResponse = getIndexLifecycleExplainResponse(
130130
indexInCheckRolloverStep,
131-
metadata,
131+
project,
132132
false,
133133
true,
134134
REGISTRY,
@@ -150,14 +150,14 @@ public void testGetIndexLifecycleExplainResponse() throws IOException {
150150
.numberOfShards(randomIntBetween(1, 5))
151151
.numberOfReplicas(randomIntBetween(0, 5))
152152
.build();
153-
Metadata metadata = Metadata.builder()
153+
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
154154
.put(indexMetadata, true)
155155
.putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
156156
.build();
157157

158158
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
159159
indexWithMissingPolicy,
160-
metadata,
160+
project,
161161
true,
162162
true,
163163
REGISTRY,
@@ -175,14 +175,14 @@ public void testGetIndexLifecycleExplainResponse() throws IOException {
175175
.numberOfShards(randomIntBetween(1, 5))
176176
.numberOfReplicas(randomIntBetween(0, 5))
177177
.build();
178-
Metadata metadata = Metadata.builder()
178+
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
179179
.put(indexMetadata, true)
180180
.putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
181181
.build();
182182

183183
IndexLifecycleExplainResponse onlyManaged = getIndexLifecycleExplainResponse(
184184
"index",
185-
metadata,
185+
project,
186186
false,
187187
true,
188188
REGISTRY,
@@ -205,14 +205,14 @@ public void testGetIndexLifecycleExplainResponse() throws IOException {
205205
.numberOfReplicas(randomIntBetween(0, 5))
206206
.putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap())
207207
.build();
208-
Metadata metadata = Metadata.builder()
208+
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
209209
.put(indexMetadata, true)
210210
.putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
211211
.build();
212212

213213
IndexLifecycleExplainResponse response = getIndexLifecycleExplainResponse(
214214
indexInCheckRolloverStep,
215-
metadata,
215+
project,
216216
false,
217217
true,
218218
REGISTRY,

0 commit comments

Comments
 (0)