Skip to content

Multi-project for TransportExlainLifecycleAction #126414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.ChannelActionListener;
import org.elasticsearch.action.support.local.TransportLocalClusterStateAction;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.action.support.local.TransportLocalProjectMetadataAction;
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -52,7 +52,9 @@
import static org.elasticsearch.index.IndexSettings.LIFECYCLE_ORIGINATION_DATE;
import static org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep.applyDefaultConditions;

public class TransportExplainLifecycleAction extends TransportLocalClusterStateAction<ExplainLifecycleRequest, ExplainLifecycleResponse> {
public class TransportExplainLifecycleAction extends TransportLocalProjectMetadataAction<
ExplainLifecycleRequest,
ExplainLifecycleResponse> {

private final NamedXContentRegistry xContentRegistry;
private final IndexNameExpressionResolver indexNameExpressionResolver;
Expand All @@ -78,7 +80,8 @@ public TransportExplainLifecycleAction(
actionFilters,
transportService.getTaskManager(),
clusterService,
threadPool.executor(ThreadPool.Names.MANAGEMENT)
threadPool.executor(ThreadPool.Names.MANAGEMENT),
projectResolver
);
this.xContentRegistry = xContentRegistry;
this.indexNameExpressionResolver = indexNameExpressionResolver;
Expand All @@ -95,29 +98,33 @@ public TransportExplainLifecycleAction(
}

@Override
protected ClusterBlockException checkBlock(ExplainLifecycleRequest request, ClusterState state) {
return state.blocks()
.indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
protected ClusterBlockException checkBlock(ExplainLifecycleRequest request, ProjectState project) {
return project.blocks()
.indicesBlockedException(
project.projectId(),
ClusterBlockLevel.METADATA_READ,
indexNameExpressionResolver.concreteIndexNames(project.metadata(), request)
);
}

@Override
protected void localClusterStateOperation(
Task task,
ExplainLifecycleRequest request,
final ClusterState state,
ProjectState project,
ActionListener<ExplainLifecycleResponse> listener
) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(project.metadata(), request);
boolean rolloverOnlyIfHasDocuments = LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING.get(
state.metadata().settings()
project.cluster().metadata().settings()
);
Map<String, IndexLifecycleExplainResponse> indexResponses = new TreeMap<>();
for (String index : concreteIndices) {
final IndexLifecycleExplainResponse indexResponse;
try {
indexResponse = getIndexLifecycleExplainResponse(
index,
state.metadata(),
project.metadata(),
request.onlyErrors(),
request.onlyManaged(),
xContentRegistry,
Expand All @@ -140,13 +147,12 @@ protected void localClusterStateOperation(
@Nullable
static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse(
String indexName,
Metadata metadata,
ProjectMetadata project,
boolean onlyErrors,
boolean onlyManaged,
NamedXContentRegistry xContentRegistry,
boolean rolloverOnlyIfHasDocuments
) throws IOException {
final var project = metadata.getProject();
IndexMetadata indexMetadata = project.index(indexName);
Settings idxSettings = indexMetadata.getSettings();
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
Expand Down
Loading