Skip to content

Commit f9b29ef

Browse files
Multi-project for TransportExlainLifecycleAction (#126414)
This converts this class to support multi-project. There is a drive-by refactoring to split multiple independent tests in one method into separate methods. (Look at this change with whitespace changes hidden to see the 'real' change.)
1 parent 6e4cb81 commit f9b29ef

File tree

3 files changed

+169
-171
lines changed

3 files changed

+169
-171
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import org.elasticsearch.action.ActionListener;
1212
import org.elasticsearch.action.support.ActionFilters;
1313
import org.elasticsearch.action.support.ChannelActionListener;
14-
import org.elasticsearch.action.support.local.TransportLocalClusterStateAction;
15-
import org.elasticsearch.cluster.ClusterState;
14+
import org.elasticsearch.action.support.local.TransportLocalProjectMetadataAction;
15+
import org.elasticsearch.cluster.ProjectState;
1616
import org.elasticsearch.cluster.block.ClusterBlockException;
1717
import org.elasticsearch.cluster.block.ClusterBlockLevel;
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;
@@ -52,7 +52,9 @@
5252
import static org.elasticsearch.index.IndexSettings.LIFECYCLE_ORIGINATION_DATE;
5353
import static org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep.applyDefaultConditions;
5454

55-
public class TransportExplainLifecycleAction extends TransportLocalClusterStateAction<ExplainLifecycleRequest, ExplainLifecycleResponse> {
55+
public class TransportExplainLifecycleAction extends TransportLocalProjectMetadataAction<
56+
ExplainLifecycleRequest,
57+
ExplainLifecycleResponse> {
5658

5759
private final NamedXContentRegistry xContentRegistry;
5860
private final IndexNameExpressionResolver indexNameExpressionResolver;
@@ -78,7 +80,8 @@ public TransportExplainLifecycleAction(
7880
actionFilters,
7981
transportService.getTaskManager(),
8082
clusterService,
81-
threadPool.executor(ThreadPool.Names.MANAGEMENT)
83+
threadPool.executor(ThreadPool.Names.MANAGEMENT),
84+
projectResolver
8285
);
8386
this.xContentRegistry = xContentRegistry;
8487
this.indexNameExpressionResolver = indexNameExpressionResolver;
@@ -95,29 +98,33 @@ public TransportExplainLifecycleAction(
9598
}
9699

97100
@Override
98-
protected ClusterBlockException checkBlock(ExplainLifecycleRequest request, ClusterState state) {
99-
return state.blocks()
100-
.indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
101+
protected ClusterBlockException checkBlock(ExplainLifecycleRequest request, ProjectState project) {
102+
return project.blocks()
103+
.indicesBlockedException(
104+
project.projectId(),
105+
ClusterBlockLevel.METADATA_READ,
106+
indexNameExpressionResolver.concreteIndexNames(project.metadata(), request)
107+
);
101108
}
102109

103110
@Override
104111
protected void localClusterStateOperation(
105112
Task task,
106113
ExplainLifecycleRequest request,
107-
final ClusterState state,
114+
ProjectState project,
108115
ActionListener<ExplainLifecycleResponse> listener
109116
) {
110-
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
117+
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(project.metadata(), request);
111118
boolean rolloverOnlyIfHasDocuments = LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING.get(
112-
state.metadata().settings()
119+
project.cluster().metadata().settings()
113120
);
114121
Map<String, IndexLifecycleExplainResponse> indexResponses = new TreeMap<>();
115122
for (String index : concreteIndices) {
116123
final IndexLifecycleExplainResponse indexResponse;
117124
try {
118125
indexResponse = getIndexLifecycleExplainResponse(
119126
index,
120-
state.metadata(),
127+
project.metadata(),
121128
request.onlyErrors(),
122129
request.onlyManaged(),
123130
xContentRegistry,
@@ -140,13 +147,12 @@ protected void localClusterStateOperation(
140147
@Nullable
141148
static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse(
142149
String indexName,
143-
Metadata metadata,
150+
ProjectMetadata project,
144151
boolean onlyErrors,
145152
boolean onlyManaged,
146153
NamedXContentRegistry xContentRegistry,
147154
boolean rolloverOnlyIfHasDocuments
148155
) throws IOException {
149-
final var project = metadata.getProject();
150156
IndexMetadata indexMetadata = project.index(indexName);
151157
Settings idxSettings = indexMetadata.getSettings();
152158
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();

0 commit comments

Comments
 (0)