From cfd50d253b603a139aff4cf5dbb7e0bb86135b3c Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Thu, 12 Jun 2025 20:03:16 -0300 Subject: [PATCH] Make ILM `AsyncWaitStep` project-aware We pass a `ProjectState` to the `AsyncAwaitStep` classes and use the project client to make the steps run on a specific project. --- .../xpack/core/ilm/AsyncWaitStep.java | 12 ++- .../xpack/core/ilm/SegmentCountStep.java | 68 ++++++------- .../core/ilm/WaitForFollowShardTasksStep.java | 8 +- .../core/ilm/WaitForNoFollowersStep.java | 13 +-- .../core/ilm/WaitForRolloverReadyStep.java | 16 +-- .../xpack/core/ilm/WaitForSnapshotStep.java | 10 +- .../WaitUntilReplicateForTimePassesStep.java | 8 +- .../WaitUntilTimeSeriesEndTimePassesStep.java | 6 +- .../xpack/core/ilm/AbstractStepTestCase.java | 1 + .../xpack/core/ilm/SegmentCountStepTests.java | 14 ++- .../ilm/WaitForFollowShardTasksStepTests.java | 92 ++++++++--------- .../core/ilm/WaitForNoFollowersStepTests.java | 17 ++-- .../ilm/WaitForRolloverReadyStepTests.java | 98 +++++++++++-------- .../core/ilm/WaitForSnapshotStepTests.java | 57 ++++++----- ...tUntilReplicateForTimePassesStepTests.java | 12 +-- ...UntilTimeSeriesEndTimePassesStepTests.java | 19 ++-- .../xpack/ilm/IndexLifecycleRunner.java | 6 +- .../xpack/ilm/IndexLifecycleService.java | 4 +- .../elasticsearch/xpack/ilm/package-info.java | 2 +- .../xpack/ilm/IndexLifecycleRunnerTests.java | 29 +++--- 20 files changed, 267 insertions(+), 225 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java index fc5e8d473b763..061522190754e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java @@ -7,7 +7,8 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.client.internal.Client; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.ProjectState; +import org.elasticsearch.cluster.metadata.ProjectId; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; @@ -29,12 +30,17 @@ public AsyncWaitStep(StepKey key, StepKey nextStepKey, Client client) { this.client = client; } + // For testing only @Nullable - protected Client getClient() { + Client getClient() { return client; } - public abstract void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout); + protected Client getClient(ProjectId projectId) { + return client.projectClient(projectId); + } + + public abstract void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout); public interface Listener { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java index 95ca049740c73..ac8ab00286fde 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java @@ -14,7 +14,7 @@ import org.elasticsearch.action.admin.indices.segments.ShardSegments; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.client.internal.Client; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; @@ -56,42 +56,44 @@ public int getMaxNumSegments() { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { - getClient().admin().indices().segments(new IndicesSegmentsRequest(index.getName()), ActionListener.wrap(response -> { - IndexSegments idxSegments = response.getIndices().get(index.getName()); - if (idxSegments == null || (response.getShardFailures() != null && response.getShardFailures().length > 0)) { - final DefaultShardOperationFailedException[] failures = response.getShardFailures(); - logger.info( - "[{}] retrieval of segment counts after force merge did not succeed, there were {} shard failures. failures: {}", - index.getName(), - response.getFailedShards(), - failures == null - ? "n/a" - : Strings.collectionToDelimitedString(Arrays.stream(failures).map(Strings::toString).toList(), ",") - ); - listener.onResponse(true, new Info(-1)); - } else { - List unmergedShards = idxSegments.getShards() - .values() - .stream() - .flatMap(iss -> Arrays.stream(iss.shards())) - .filter(shardSegments -> shardSegments.getSegments().size() > maxNumSegments) - .toList(); - if (unmergedShards.size() > 0) { - Map unmergedShardCounts = unmergedShards.stream() - .collect(Collectors.toMap(ShardSegments::getShardRouting, ss -> ss.getSegments().size())); + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + getClient(state.projectId()).admin() + .indices() + .segments(new IndicesSegmentsRequest(index.getName()), ActionListener.wrap(response -> { + IndexSegments idxSegments = response.getIndices().get(index.getName()); + if (idxSegments == null || (response.getShardFailures() != null && response.getShardFailures().length > 0)) { + final DefaultShardOperationFailedException[] failures = response.getShardFailures(); logger.info( - "[{}] best effort force merge to [{}] segments did not succeed for {} shards: {}", + "[{}] retrieval of segment counts after force merge did not succeed, there were {} shard failures. failures: {}", index.getName(), - maxNumSegments, - unmergedShards.size(), - unmergedShardCounts + response.getFailedShards(), + failures == null + ? "n/a" + : Strings.collectionToDelimitedString(Arrays.stream(failures).map(Strings::toString).toList(), ",") ); + listener.onResponse(true, new Info(-1)); + } else { + List unmergedShards = idxSegments.getShards() + .values() + .stream() + .flatMap(iss -> Arrays.stream(iss.shards())) + .filter(shardSegments -> shardSegments.getSegments().size() > maxNumSegments) + .toList(); + if (unmergedShards.size() > 0) { + Map unmergedShardCounts = unmergedShards.stream() + .collect(Collectors.toMap(ShardSegments::getShardRouting, ss -> ss.getSegments().size())); + logger.info( + "[{}] best effort force merge to [{}] segments did not succeed for {} shards: {}", + index.getName(), + maxNumSegments, + unmergedShards.size(), + unmergedShardCounts + ); + } + // Force merging is best effort, so always return true that the condition has been met. + listener.onResponse(true, new Info(unmergedShards.size())); } - // Force merging is best effort, so always return true that the condition has been met. - listener.onResponse(true, new Info(unmergedShards.size())); - } - }, listener::onFailure)); + }, listener::onFailure)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStep.java index 90f36ef33121d..5e0cefeebf2a8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStep.java @@ -8,8 +8,8 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.internal.Client; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; @@ -39,8 +39,8 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { - IndexMetadata indexMetadata = metadata.getProject().index(index); + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + IndexMetadata indexMetadata = state.metadata().index(index); Map customIndexMetadata = indexMetadata.getCustomData(CCR_METADATA_KEY); if (customIndexMetadata == null) { listener.onResponse(true, null); @@ -49,7 +49,7 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest(); request.setIndices(new String[] { index.getName() }); - getClient().execute( + getClient(state.projectId()).execute( FollowStatsAction.INSTANCE, request, ActionListener.wrap(r -> handleResponse(r, listener), listener::onFailure) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStep.java index 42175b25c28f0..a83410275a349 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStep.java @@ -14,7 +14,8 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; import org.elasticsearch.action.admin.indices.stats.ShardStats; import org.elasticsearch.client.internal.Client; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.ProjectState; +import org.elasticsearch.cluster.metadata.ProjectId; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; import org.elasticsearch.protocol.xpack.XPackInfoRequest; @@ -52,26 +53,26 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { XPackInfoRequest xPackInfoRequest = new XPackInfoRequest(); xPackInfoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES)); - getClient().execute(XPackInfoFeatureAction.CCR, xPackInfoRequest, ActionListener.wrap((xPackInfoResponse) -> { + getClient(state.projectId()).execute(XPackInfoFeatureAction.CCR, xPackInfoRequest, ActionListener.wrap((xPackInfoResponse) -> { XPackInfoResponse.FeatureSetsInfo.FeatureSet featureSet = xPackInfoResponse.getInfo(); if (featureSet != null && featureSet.enabled() == false) { listener.onResponse(true, null); return; } - leaderIndexCheck(metadata, index, listener, masterTimeout); + leaderIndexCheck(state.projectId(), index, listener); }, listener::onFailure)); } - private void leaderIndexCheck(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { + private void leaderIndexCheck(ProjectId projectId, Index index, Listener listener) { IndicesStatsRequest request = new IndicesStatsRequest(); request.clear(); String indexName = index.getName(); request.indices(indexName); - getClient().admin().indices().stats(request, ActionListener.wrap((response) -> { + getClient(projectId).admin().indices().stats(request, ActionListener.wrap((response) -> { IndexStats indexStats = response.getIndex(indexName); if (indexStats == null) { // Index was probably deleted diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java index 767308f2dd723..a387db9c6d3f6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java @@ -14,11 +14,11 @@ import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; import org.elasticsearch.action.support.IndexComponentSelector; import org.elasticsearch.client.internal.Client; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; @@ -80,8 +80,8 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { - IndexAbstraction indexAbstraction = metadata.getProject().getIndicesLookup().get(index.getName()); + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + IndexAbstraction indexAbstraction = state.metadata().getIndicesLookup().get(index.getName()); assert indexAbstraction != null : "invalid cluster metadata. index [" + index.getName() + "] was not found"; final String rolloverTarget; final boolean targetFailureStore; @@ -95,14 +95,14 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, index.getName(), targetFailureStore ? "failure store " : "", dataStream.getName(), - metadata.getProject().index(index).getLifecyclePolicyName() + state.metadata().index(index).getLifecyclePolicyName() ); listener.onResponse(true, EmptyInfo.INSTANCE); return; } rolloverTarget = dataStream.getName(); } else { - IndexMetadata indexMetadata = metadata.getProject().index(index); + IndexMetadata indexMetadata = state.metadata().index(index); String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetadata.getSettings()); if (Strings.isNullOrEmpty(rolloverAlias)) { @@ -200,7 +200,9 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, // if we should only rollover if not empty, *and* if neither an explicit min_docs nor an explicit min_primary_shard_docs // has been specified on this policy, then inject a default min_docs: 1 condition so that we do not rollover empty indices - boolean rolloverOnlyIfHasDocuments = LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING.get(metadata.settings()); + boolean rolloverOnlyIfHasDocuments = LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING.get( + state.cluster().metadata().settings() + ); RolloverRequest rolloverRequest = createRolloverRequest( rolloverTarget, masterTimeout, @@ -208,7 +210,7 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, targetFailureStore ); - getClient().admin().indices().rolloverIndex(rolloverRequest, ActionListener.wrap(response -> { + getClient(state.projectId()).admin().indices().rolloverIndex(rolloverRequest, ActionListener.wrap(response -> { final var conditionStatus = response.getConditionStatus(); final var conditionsMet = rolloverRequest.getConditions().areConditionsMet(conditionStatus); if (conditionsMet) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java index 3f1fc1d2283e5..5e294a1e504c7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java @@ -11,8 +11,8 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; import org.elasticsearch.client.internal.Client; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; @@ -54,8 +54,8 @@ public class WaitForSnapshotStep extends AsyncWaitStep { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { - IndexMetadata indexMetadata = metadata.getProject().index(index); + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + IndexMetadata indexMetadata = state.metadata().index(index); if (indexMetadata == null) { listener.onFailure(error(NO_INDEX_METADATA_MESSAGE, index.getName())); return; @@ -68,7 +68,7 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, return; } - SnapshotLifecycleMetadata snapMeta = metadata.getProject().custom(SnapshotLifecycleMetadata.TYPE); + SnapshotLifecycleMetadata snapMeta = state.metadata().custom(SnapshotLifecycleMetadata.TYPE); if (snapMeta == null || snapMeta.getSnapshotConfigurations().containsKey(policy) == false) { listener.onFailure(error(POLICY_NOT_FOUND_MESSAGE, policy)); return; @@ -108,7 +108,7 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, .snapshots(new String[] { snapshotName }) .includeIndexNames(true) .verbose(false); - getClient().admin().cluster().getSnapshots(request, ActionListener.wrap(response -> { + getClient(state.projectId()).admin().cluster().getSnapshots(request, ActionListener.wrap(response -> { if (response.getSnapshots().size() != 1) { listener.onFailure(error(UNEXPECTED_SNAPSHOT_STATE_MESSAGE, repositoryName, snapshotName, response.getSnapshots().size())); } else { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStep.java index fdc854a5619df..6a6637bd61c7d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStep.java @@ -7,9 +7,9 @@ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; @@ -66,12 +66,12 @@ public boolean equals(Object obj) { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { - IndexMetadata indexMetadata = metadata.getProject().index(index); + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + IndexMetadata indexMetadata = state.metadata().index(index); assert indexMetadata != null : "the index metadata for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]"; - final LifecycleExecutionState executionState = metadata.getProject().index(index.getName()).getLifecycleExecutionState(); + final LifecycleExecutionState executionState = state.metadata().index(index.getName()).getLifecycleExecutionState(); assert executionState != null : "the lifecycle execution state for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStep.java index 82ffce5f38839..800744d74c1e6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStep.java @@ -6,8 +6,8 @@ */ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; @@ -43,8 +43,8 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { - IndexMetadata indexMetadata = metadata.getProject().index(index); + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + IndexMetadata indexMetadata = state.metadata().index(index); assert indexMetadata != null : "the index metadata for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]"; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java index cb020c1dcce20..74e9202eae873 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java @@ -40,6 +40,7 @@ public void setupClient() { adminClient = Mockito.mock(AdminClient.class); indicesClient = Mockito.mock(IndicesAdminClient.class); + Mockito.when(client.projectClient(Mockito.any())).thenReturn(client); Mockito.when(client.admin()).thenReturn(adminClient); Mockito.when(adminClient.indices()).thenReturn(indicesClient); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java index 9f04e202022c9..3625a007c3a04 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.action.admin.indices.segments.ShardSegments; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.Segment; @@ -103,7 +103,8 @@ public void testIsConditionMet() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { conditionMetResult.set(conditionMet); @@ -155,7 +156,8 @@ public void testIsConditionIsTrueEvenWhenMoreSegments() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { conditionMetResult.set(conditionMet); @@ -212,7 +214,8 @@ public void testFailedToRetrieveSomeSegments() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { conditionMetResult.set(conditionMet); @@ -249,7 +252,8 @@ public void testThrowsException() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { throw new AssertionError("unexpected method call"); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java index ba94508667776..22ee5db4001f8 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.index.IndexVersion; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus; @@ -70,23 +70,19 @@ public void testConditionMet() { final boolean[] conditionMetHolder = new boolean[1]; final ToXContentObject[] informationContextHolder = new ToXContentObject[1]; final Exception[] exceptionHolder = new Exception[1]; - createRandomInstance().evaluateCondition( - Metadata.builder().put(indexMetadata, true).build(), - indexMetadata.getIndex(), - new AsyncWaitStep.Listener() { - @Override - public void onResponse(boolean conditionMet, ToXContentObject informationContext) { - conditionMetHolder[0] = conditionMet; - informationContextHolder[0] = informationContext; - } - - @Override - public void onFailure(Exception e) { - exceptionHolder[0] = e; - } - }, - MASTER_TIMEOUT - ); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + @Override + public void onResponse(boolean conditionMet, ToXContentObject informationContext) { + conditionMetHolder[0] = conditionMet; + informationContextHolder[0] = informationContext; + } + + @Override + public void onFailure(Exception e) { + exceptionHolder[0] = e; + } + }, MASTER_TIMEOUT); assertThat(conditionMetHolder[0], is(true)); assertThat(informationContextHolder[0], nullValue()); @@ -109,23 +105,19 @@ public void testConditionNotMetShardsNotInSync() { final boolean[] conditionMetHolder = new boolean[1]; final ToXContentObject[] informationContextHolder = new ToXContentObject[1]; final Exception[] exceptionHolder = new Exception[1]; - createRandomInstance().evaluateCondition( - Metadata.builder().put(indexMetadata, true).build(), - indexMetadata.getIndex(), - new AsyncWaitStep.Listener() { - @Override - public void onResponse(boolean conditionMet, ToXContentObject informationContext) { - conditionMetHolder[0] = conditionMet; - informationContextHolder[0] = informationContext; - } - - @Override - public void onFailure(Exception e) { - exceptionHolder[0] = e; - } - }, - MASTER_TIMEOUT - ); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + @Override + public void onResponse(boolean conditionMet, ToXContentObject informationContext) { + conditionMetHolder[0] = conditionMet; + informationContextHolder[0] = informationContext; + } + + @Override + public void onFailure(Exception e) { + exceptionHolder[0] = e; + } + }, MASTER_TIMEOUT); assertThat(conditionMetHolder[0], is(false)); assertThat(informationContextHolder[0], notNullValue()); @@ -147,23 +139,19 @@ public void testConditionNotMetNotAFollowerIndex() { final boolean[] conditionMetHolder = new boolean[1]; final ToXContentObject[] informationContextHolder = new ToXContentObject[1]; final Exception[] exceptionHolder = new Exception[1]; - createRandomInstance().evaluateCondition( - Metadata.builder().put(indexMetadata, true).build(), - indexMetadata.getIndex(), - new AsyncWaitStep.Listener() { - @Override - public void onResponse(boolean conditionMet, ToXContentObject informationContext) { - conditionMetHolder[0] = conditionMet; - informationContextHolder[0] = informationContext; - } - - @Override - public void onFailure(Exception e) { - exceptionHolder[0] = e; - } - }, - MASTER_TIMEOUT - ); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + @Override + public void onResponse(boolean conditionMet, ToXContentObject informationContext) { + conditionMetHolder[0] = conditionMet; + informationContextHolder[0] = informationContext; + } + + @Override + public void onFailure(Exception e) { + exceptionHolder[0] = e; + } + }, MASTER_TIMEOUT); assertThat(conditionMetHolder[0], is(true)); assertThat(informationContextHolder[0], nullValue()); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java index b67404956deb2..888a66b62b871 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.action.admin.indices.stats.ShardStats; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.seqno.RetentionLease; @@ -84,7 +84,8 @@ public void testConditionMetWhenCCREnabled() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -118,7 +119,8 @@ public void testConditionMetWhenCCRDisabled() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -152,7 +154,8 @@ public void testConditionNotMet() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -193,7 +196,8 @@ public void testNoShardStats() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -233,7 +237,8 @@ public void testFailure() { }).when(indicesClient).stats(any(), any()); final SetOnce exceptionHolder = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { fail( diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java index 8ad841664b87a..ffb26d6620104 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java @@ -29,7 +29,7 @@ import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.DataStreamTestHelper; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; @@ -234,7 +234,8 @@ public void testEvaluateCondition() { mockRolloverIndexCall(alias, step, true); SetOnce conditionsMet = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -249,7 +250,9 @@ public void onFailure(Exception e) { assertEquals(true, conditionsMet.get()); - verify(client, Mockito.only()).admin(); + verify(client).projectClient(state.projectId()); + verify(client).admin(); + verifyNoMoreInteractions(client); verify(adminClient, Mockito.only()).indices(); verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any()); } @@ -278,19 +281,20 @@ public void testEvaluateConditionOnDataStreamTarget() { ); SetOnce conditionsMet = new SetOnce<>(); - Metadata metadata = Metadata.builder() - .put(indexMetadata, true) - .put(failureStoreMetadata, true) - .put( - DataStreamTestHelper.newInstance( - dataStreamName, - List.of(indexMetadata.getIndex()), - List.of(failureStoreMetadata.getIndex()) + var state = projectStateFromProject( + ProjectMetadata.builder(randomProjectIdOrDefault()) + .put(indexMetadata, true) + .put(failureStoreMetadata, true) + .put( + DataStreamTestHelper.newInstance( + dataStreamName, + List.of(indexMetadata.getIndex()), + List.of(failureStoreMetadata.getIndex()) + ) ) - ) - .build(); + ); IndexMetadata indexToOperateOn = failureStoreIndex ? failureStoreMetadata : indexMetadata; - step.evaluateCondition(metadata, indexToOperateOn.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexToOperateOn.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -305,7 +309,9 @@ public void onFailure(Exception e) { assertEquals(true, conditionsMet.get()); - verify(client, Mockito.only()).admin(); + verify(client).projectClient(state.projectId()); + verify(client).admin(); + verifyNoMoreInteractions(client); verify(adminClient, Mockito.only()).indices(); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(RolloverRequest.class); @@ -352,21 +358,22 @@ public void testSkipRolloverIfDataStreamIsAlreadyRolledOver() { WaitForRolloverReadyStep step = createRandomInstance(); SetOnce conditionsMet = new SetOnce<>(); - Metadata metadata = Metadata.builder() - .put(firstGenerationIndex, true) - .put(writeIndex, true) - .put(firstGenerationFailureIndex, true) - .put(writeFailureIndex, true) - .put( - DataStreamTestHelper.newInstance( - dataStreamName, - List.of(firstGenerationIndex.getIndex(), writeIndex.getIndex()), - List.of(firstGenerationFailureIndex.getIndex(), writeFailureIndex.getIndex()) + var state = projectStateFromProject( + ProjectMetadata.builder(randomProjectIdOrDefault()) + .put(firstGenerationIndex, true) + .put(writeIndex, true) + .put(firstGenerationFailureIndex, true) + .put(writeFailureIndex, true) + .put( + DataStreamTestHelper.newInstance( + dataStreamName, + List.of(firstGenerationIndex.getIndex(), writeIndex.getIndex()), + List.of(firstGenerationFailureIndex.getIndex(), writeFailureIndex.getIndex()) + ) ) - ) - .build(); + ); IndexMetadata indexToOperateOn = failureStoreIndex ? firstGenerationFailureIndex : firstGenerationIndex; - step.evaluateCondition(metadata, indexToOperateOn.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexToOperateOn.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -414,7 +421,8 @@ public void testEvaluateDoesntTriggerRolloverForIndexManuallyRolledOnLifecycleRo WaitForRolloverReadyStep step = createRandomInstance(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -448,7 +456,8 @@ public void testEvaluateTriggersRolloverForIndexManuallyRolledOnDifferentAlias() WaitForRolloverReadyStep step = createRandomInstance(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -474,7 +483,8 @@ public void testPerformActionWriteIndexIsFalse() { .build(); WaitForRolloverReadyStep step = createRandomInstance(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -515,7 +525,8 @@ public void testPerformActionWithIndexingComplete() { WaitForRolloverReadyStep step = createRandomInstance(); SetOnce conditionsMet = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -546,7 +557,8 @@ public void testPerformActionWithIndexingCompleteStillWriteIndex() { WaitForRolloverReadyStep step = createRandomInstance(); SetOnce correctFailureCalled = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -576,7 +588,8 @@ public void testPerformActionNotComplete() { mockRolloverIndexCall(alias, step, false); SetOnce actionCompleted = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -591,7 +604,9 @@ public void onFailure(Exception e) { assertEquals(false, actionCompleted.get()); - verify(client, Mockito.only()).admin(); + verify(client).projectClient(state.projectId()); + verify(client).admin(); + verifyNoMoreInteractions(client); verify(adminClient, Mockito.only()).indices(); verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any()); } @@ -618,7 +633,8 @@ public void testPerformActionFailure() { }).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any()); SetOnce exceptionThrown = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -634,7 +650,9 @@ public void onFailure(Exception e) { assertEquals(true, exceptionThrown.get()); - verify(client, Mockito.only()).admin(); + verify(client).projectClient(state.projectId()); + verify(client).admin(); + verifyNoMoreInteractions(client); verify(adminClient, Mockito.only()).indices(); verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any()); } @@ -649,7 +667,8 @@ public void testPerformActionInvalidNullOrEmptyAlias() { WaitForRolloverReadyStep step = createRandomInstance(); SetOnce exceptionThrown = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { throw new AssertionError("Unexpected method call"); @@ -684,7 +703,8 @@ public void testPerformActionAliasDoesNotPointToIndex() { WaitForRolloverReadyStep step = createRandomInstance(); SetOnce exceptionThrown = new SetOnce<>(); - step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { throw new AssertionError("Unexpected method call"); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java index 6e31759fd6c29..d43677a412aa3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java @@ -11,11 +11,10 @@ import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; import org.elasticsearch.client.internal.ClusterAdminClient; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectId; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.index.IndexVersion; import org.elasticsearch.snapshots.Snapshot; @@ -83,12 +82,10 @@ public void testNoSlmPolicies() { .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - Map indices = Map.of(indexMetadata.getIndex().getName(), indexMetadata); - Metadata.Builder meta = Metadata.builder().indices(indices); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(meta).build(); WaitForSnapshotStep instance = createRandomInstance(); SetOnce error = new SetOnce<>(); - instance.evaluateCondition(clusterState.metadata(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { logger.warn("expected an error got unexpected response {}", conditionMet); @@ -122,12 +119,14 @@ public void testSlmPolicyNotExecuted() { .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - Map indices = Map.of(indexMetadata.getIndex().getName(), indexMetadata); - Metadata.Builder meta = Metadata.builder().indices(indices).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(meta).build(); SetOnce isConditionMet = new SetOnce<>(); SetOnce informationContext = new SetOnce<>(); - instance.evaluateCondition(clusterState.metadata(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject( + ProjectMetadata.builder(randomProjectIdOrDefault()) + .put(indexMetadata, true) + .putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) + ); + instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { isConditionMet.set(conditionMet); @@ -150,6 +149,7 @@ public void testSlmPolicyExecutedBeforeStep() throws IOException { } public void testSlmPolicyExecutedAfterStep() { + final var projectId = randomProjectIdOrDefault(); String repoName = randomAlphaOfLength(10); String snapshotName = randomAlphaOfLength(10); String indexName = randomAlphaOfLength(10); @@ -157,7 +157,7 @@ public void testSlmPolicyExecutedAfterStep() { GetSnapshotsResponse response = new GetSnapshotsResponse( List.of( new SnapshotInfo( - new Snapshot(randomAlphaOfLength(10), new SnapshotId(snapshotName, randomAlphaOfLength(10))), + new Snapshot(projectId, randomAlphaOfLength(10), new SnapshotId(snapshotName, randomAlphaOfLength(10))), List.of(indexName), List.of(), List.of(), @@ -177,7 +177,7 @@ public void testSlmPolicyExecutedAfterStep() { return null; }).when(clusterAdminClient).getSnapshots(any(), any()); - assertSlmPolicyExecuted(repoName, snapshotName, indexName, true, true); + assertSlmPolicyExecuted(projectId, repoName, snapshotName, indexName, true, true); } public void testSlmPolicyNotExecutedWhenStartIsBeforePhaseTime() throws IOException { @@ -186,6 +186,7 @@ public void testSlmPolicyNotExecutedWhenStartIsBeforePhaseTime() throws IOExcept } public void testIndexNotBackedUpYet() { + final var projectId = randomProjectIdOrDefault(); String repoName = randomAlphaOfLength(10); String snapshotName = randomAlphaOfLength(10); String indexName = randomAlphaOfLength(10); @@ -194,7 +195,7 @@ public void testIndexNotBackedUpYet() { GetSnapshotsResponse response = new GetSnapshotsResponse( List.of( new SnapshotInfo( - new Snapshot(randomAlphaOfLength(10), new SnapshotId(snapshotName, randomAlphaOfLength(10))), + new Snapshot(projectId, randomAlphaOfLength(10), new SnapshotId(snapshotName, randomAlphaOfLength(10))), List.of(), List.of(), List.of(), @@ -234,11 +235,11 @@ public void testIndexNotBackedUpYet() { .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - Map indices = Map.of(indexMetadata.getIndex().getName(), indexMetadata); - Metadata.Builder meta = Metadata.builder().indices(indices).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(meta).build(); SetOnce error = new SetOnce<>(); - instance.evaluateCondition(clusterState.metadata(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject( + ProjectMetadata.builder(projectId).put(indexMetadata, true).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) + ); + instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { logger.warn("expected an error got unexpected response {}", conditionMet); @@ -256,6 +257,7 @@ public void onFailure(Exception e) { private void assertSlmPolicyExecuted(boolean startTimeAfterPhaseTime, boolean finishTimeAfterPhaseTime) { assertSlmPolicyExecuted( + randomProjectIdOrDefault(), randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10), @@ -265,6 +267,7 @@ private void assertSlmPolicyExecuted(boolean startTimeAfterPhaseTime, boolean fi } private void assertSlmPolicyExecuted( + ProjectId projectId, String repoName, String snapshotName, String indexName, @@ -298,12 +301,12 @@ private void assertSlmPolicyExecuted( .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - Map indices = Map.of(indexMetadata.getIndex().getName(), indexMetadata); - Metadata.Builder meta = Metadata.builder().indices(indices).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(meta).build(); SetOnce isConditionMet = new SetOnce<>(); SetOnce informationContext = new SetOnce<>(); - instance.evaluateCondition(clusterState.metadata(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject( + ProjectMetadata.builder(projectId).put(indexMetadata, true).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) + ); + instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { isConditionMet.set(conditionMet); @@ -355,11 +358,13 @@ public void testNullStartTime() { .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - Map indices = Map.of(indexMetadata.getIndex().getName(), indexMetadata); - Metadata.Builder meta = Metadata.builder().indices(indices).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(meta).build(); SetOnce error = new SetOnce<>(); - instance.evaluateCondition(clusterState.metadata(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + final var state = projectStateFromProject( + ProjectMetadata.builder(randomProjectIdOrDefault()) + .put(indexMetadata, true) + .putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) + ); + instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { logger.warn("expected an error got unexpected response {}", conditionMet); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStepTests.java index f6d45f8a1cc4e..8e6615b936001 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilReplicateForTimePassesStepTests.java @@ -9,9 +9,8 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexVersion; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xcontent.ToXContentObject; @@ -76,12 +75,11 @@ public void testEvaluateCondition() { final Instant t2 = now.plus(2, ChronoUnit.HOURS); final IndexMetadata indexMeta = getIndexMetadata(randomAlphaOfLengthBetween(10, 30), randomAlphaOfLengthBetween(10, 30), step); - final Metadata metadata = Metadata.builder().put(indexMeta, true).build(); - final Index index = indexMeta.getIndex(); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMeta, true)); // if we evaluate the condition now, it hasn't been met, because it hasn't been an hour returnVal.set(now); - step.evaluateCondition(metadata, index, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMeta.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { assertThat(complete, is(false)); @@ -94,7 +92,7 @@ public void onFailure(Exception e) { }, MASTER_TIMEOUT); returnVal.set(t1); // similarly, if we were in the past, enough time also wouldn't have passed - step.evaluateCondition(metadata, index, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMeta.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { assertThat(complete, is(false)); @@ -107,7 +105,7 @@ public void onFailure(Exception e) { }, MASTER_TIMEOUT); returnVal.set(t2); // but two hours from now in the future, an hour will have passed - step.evaluateCondition(metadata, index, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMeta.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { assertThat(complete, is(true)); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStepTests.java index 3a50a5b1cbd33..1316513594310 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitUntilTimeSeriesEndTimePassesStepTests.java @@ -7,10 +7,13 @@ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.DataStreamTestHelper; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.Tuple; import org.elasticsearch.index.Index; @@ -59,11 +62,13 @@ public void testEvaluateCondition() { Instant end2 = currentTime.plus(2, ChronoUnit.HOURS); String dataStreamName = "logs_my-app_prod"; - var clusterState = DataStreamTestHelper.getClusterStateWithDataStream( + final var project = DataStreamTestHelper.getProjectWithDataStream( + randomProjectIdOrDefault(), dataStreamName, List.of(Tuple.tuple(start1, end1), Tuple.tuple(start2, end2)) ); - DataStream dataStream = clusterState.getMetadata().getProject().dataStreams().get(dataStreamName); + var state = ClusterState.builder(ClusterName.DEFAULT).putProjectMetadata(project).build().projectState(project.id()); + DataStream dataStream = project.dataStreams().get(dataStreamName); WaitUntilTimeSeriesEndTimePassesStep step = new WaitUntilTimeSeriesEndTimePassesStep( randomStepKey(), @@ -74,7 +79,7 @@ public void testEvaluateCondition() { // end_time has lapsed already so condition must be met Index previousGeneration = dataStream.getIndices().get(0); - step.evaluateCondition(clusterState.metadata(), previousGeneration, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, previousGeneration, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -92,7 +97,7 @@ public void onFailure(Exception e) { // end_time is in the future Index writeIndex = dataStream.getIndices().get(1); - step.evaluateCondition(clusterState.metadata(), writeIndex, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, writeIndex, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -125,8 +130,8 @@ public void onFailure(Exception e) { .settings(indexSettings(1, 1).put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), IndexVersion.current()).build()) .build(); - Metadata newMetadata = Metadata.builder(clusterState.metadata()).put(indexMeta, true).build(); - step.evaluateCondition(newMetadata, indexMeta.getIndex(), new AsyncWaitStep.Listener() { + ProjectState newState = state.updateProject(ProjectMetadata.builder(project).put(indexMeta, true).build()); + step.evaluateCondition(newState, indexMeta.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java index 0721f1e1d5574..5b4e407d05274 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java @@ -12,9 +12,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.ClusterStateTaskExecutor; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.MasterServiceTaskQueue; import org.elasticsearch.common.Priority; @@ -175,7 +175,7 @@ boolean isReadyToTransitionToThisPhase(final String policy, final IndexMetadata * Run the current step, only if it is an asynchronous wait step. These * wait criteria are checked periodically from the ILM scheduler */ - void runPeriodicStep(String policy, Metadata metadata, IndexMetadata indexMetadata) { + void runPeriodicStep(String policy, ProjectState state, IndexMetadata indexMetadata) { String index = indexMetadata.getIndex().getName(); if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) { logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP); @@ -237,7 +237,7 @@ void runPeriodicStep(String policy, Metadata metadata, IndexMetadata indexMetada } } else if (currentStep instanceof AsyncWaitStep) { logger.debug("[{}] running periodic policy with current-step [{}]", index, currentStep.getKey()); - ((AsyncWaitStep) currentStep).evaluateCondition(metadata, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + ((AsyncWaitStep) currentStep).evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject stepInfo) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java index 7742eb70ca918..5d539ebd8cbe9 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java @@ -501,7 +501,7 @@ void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) if (fromClusterStateChange) { lifecycleRunner.runPolicyAfterStateChange(policyName, idxMeta); } else { - lifecycleRunner.runPeriodicStep(policyName, clusterState.metadata(), idxMeta); + lifecycleRunner.runPeriodicStep(policyName, clusterState.projectState(), idxMeta); } // ILM is trying to stop, but this index is in a Shrink step (or other dangerous step) so we can't stop safeToStop = false; @@ -517,7 +517,7 @@ void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) if (fromClusterStateChange) { lifecycleRunner.runPolicyAfterStateChange(policyName, idxMeta); } else { - lifecycleRunner.runPeriodicStep(policyName, clusterState.metadata(), idxMeta); + lifecycleRunner.runPeriodicStep(policyName, clusterState.projectState(), idxMeta); } } } catch (Exception e) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java index caad8a325c50c..1c61744a4bc65 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java @@ -62,7 +62,7 @@ *
  • * {@link org.elasticsearch.xpack.ilm.IndexLifecycleRunner#runPeriodicStep( * java.lang.String, - * org.elasticsearch.cluster.metadata.Metadata, + * org.elasticsearch.cluster.ProjectState, * org.elasticsearch.cluster.metadata.IndexMetadata * )} * handles the execution of async {@link org.elasticsearch.xpack.core.ilm.AsyncWaitStep} diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java index ac4738fb787b2..70a4b157bf873 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java @@ -17,7 +17,9 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.MasterServiceTaskQueue; @@ -155,7 +157,8 @@ public void testRunPolicyPhaseCompletePolicyStep() { IndexMetadata indexMetadata = createIndex("my_index"); runner.runPolicyAfterStateChange(policyName, indexMetadata); - runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + runner.runPeriodicStep(policyName, state, indexMetadata); Mockito.verify(clusterService, times(1)).createTaskQueue(anyString(), any(), any()); Mockito.verifyNoMoreInteractions(clusterService); @@ -181,7 +184,8 @@ public void testRunPolicyPhaseCompleteWithMoreStepsPolicyStep() { IndexMetadata indexMetadata = createIndex("my_index"); runner.runPolicyAfterStateChange(policyName, indexMetadata); - runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + runner.runPeriodicStep(policyName, state, indexMetadata); Mockito.verify(taskQueue, times(1)).submitTask(anyString(), any(), any()); } @@ -296,7 +300,8 @@ public void testRunPolicyErrorStepOnRetryableFailedStep() { .putCustom(ILM_CUSTOM_METADATA_KEY, newState.build().asMap()) .build(); - runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata); + final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); + runner.runPeriodicStep(policyName, state, indexMetadata); Mockito.verify(taskQueue, times(1)).submitTask(anyString(), any(), any()); } @@ -465,7 +470,7 @@ public void doTestRunPolicyWithFailureToReadPolicy(boolean asyncAction, boolean if (asyncAction) { runner.maybeRunAsyncAction(before, indexMetadata, policyName, stepKey); } else if (periodicAction) { - runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata); + runner.runPeriodicStep(policyName, state.projectState(), indexMetadata); } else { runner.runPolicyAfterStateChange(policyName, indexMetadata); } @@ -627,13 +632,13 @@ public void testRunPeriodicStep() throws Exception { .settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap()) .build(); - ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); - DiscoveryNode node = clusterService.localNode(); + DiscoveryNode node = DiscoveryNodeUtils.create("node", "node"); + ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool, node); IndexLifecycleMetadata ilm = new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING); - ClusterState state = ClusterState.builder(new ClusterName("cluster")) - .metadata(Metadata.builder().put(indexMetadata, true).putCustom(IndexLifecycleMetadata.TYPE, ilm)) - .nodes(DiscoveryNodes.builder().add(node).masterNodeId(node.getId()).localNodeId(node.getId())) - .build(); + final var project = ProjectMetadata.builder(randomProjectIdOrDefault()) + .put(indexMetadata, true) + .putCustom(IndexLifecycleMetadata.TYPE, ilm); + ClusterState state = ClusterState.builder(clusterService.state()).putProjectMetadata(project).build(); logger.info("--> state: {}", state); ClusterServiceUtils.setState(clusterService, state); IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L); @@ -641,7 +646,7 @@ public void testRunPeriodicStep() throws Exception { ClusterState before = clusterService.state(); CountDownLatch latch = new CountDownLatch(1); step.setLatch(latch); - runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata); + runner.runPeriodicStep(policyName, state.projectState(project.getId()), indexMetadata); awaitLatch(latch, 5, TimeUnit.SECONDS); ClusterState after = clusterService.state(); @@ -1007,7 +1012,7 @@ public void setLatch(CountDownLatch latch) { } @Override - public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { + public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { executeCount++; if (latch != null) { latch.countDown();