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 061522190754e..2f9284f0fc451 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 @@ -8,10 +8,10 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ProjectState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.ProjectId; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.xcontent.ToXContentObject; /** @@ -40,7 +40,7 @@ protected Client getClient(ProjectId projectId) { return client.projectClient(projectId); } - public abstract void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout); + public abstract void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, 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 ac8ab00286fde..5ad7c12cd6e33 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 @@ -15,6 +15,7 @@ import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ProjectState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; @@ -56,7 +57,8 @@ public int getMaxNumSegments() { } @Override - public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { + Index index = indexMetadata.getIndex(); getClient(state.projectId()).admin() .indices() .segments(new IndicesSegmentsRequest(index.getName()), ActionListener.wrap(response -> { 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 5e0cefeebf2a8..8d3b7eaae4375 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 @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xcontent.XContentBuilder; @@ -39,8 +38,7 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { - IndexMetadata indexMetadata = state.metadata().index(index); + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { Map customIndexMetadata = indexMetadata.getCustomData(CCR_METADATA_KEY); if (customIndexMetadata == null) { listener.onResponse(true, null); @@ -48,7 +46,7 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener } FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest(); - request.setIndices(new String[] { index.getName() }); + request.setIndices(new String[] { indexMetadata.getIndex().getName() }); getClient(state.projectId()).execute( FollowStatsAction.INSTANCE, request, 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 a83410275a349..15e67a360efce 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 @@ -15,9 +15,9 @@ import org.elasticsearch.action.admin.indices.stats.ShardStats; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ProjectState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.ProjectId; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.protocol.xpack.XPackInfoRequest; import org.elasticsearch.protocol.xpack.XPackInfoResponse; import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; @@ -53,7 +53,7 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { XPackInfoRequest xPackInfoRequest = new XPackInfoRequest(); xPackInfoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES)); getClient(state.projectId()).execute(XPackInfoFeatureAction.CCR, xPackInfoRequest, ActionListener.wrap((xPackInfoResponse) -> { @@ -62,14 +62,13 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener listener.onResponse(true, null); return; } - leaderIndexCheck(state.projectId(), index, listener); + leaderIndexCheck(state.projectId(), indexMetadata.getIndex().getName(), listener); }, listener::onFailure)); } - private void leaderIndexCheck(ProjectId projectId, Index index, Listener listener) { + private void leaderIndexCheck(ProjectId projectId, String indexName, Listener listener) { IndicesStatsRequest request = new IndicesStatsRequest(); request.clear(); - String indexName = index.getName(); request.indices(indexName); getClient(projectId).admin().indices().stats(request, ActionListener.wrap((response) -> { 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 a387db9c6d3f6..7524c38ce8906 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 @@ -80,7 +80,8 @@ public boolean isRetryable() { } @Override - public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { + Index index = indexMetadata.getIndex(); IndexAbstraction indexAbstraction = state.metadata().getIndicesLookup().get(index.getName()); assert indexAbstraction != null : "invalid cluster metadata. index [" + index.getName() + "] was not found"; final String rolloverTarget; @@ -95,14 +96,13 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener index.getName(), targetFailureStore ? "failure store " : "", dataStream.getName(), - state.metadata().index(index).getLifecyclePolicyName() + indexMetadata.getLifecyclePolicyName() ); listener.onResponse(true, EmptyInfo.INSTANCE); return; } rolloverTarget = dataStream.getName(); } else { - IndexMetadata indexMetadata = state.metadata().index(index); String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetadata.getSettings()); if (Strings.isNullOrEmpty(rolloverAlias)) { 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 5e294a1e504c7..63d9b5507cdb1 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 @@ -15,7 +15,6 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xpack.core.ilm.step.info.EmptyInfo; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; @@ -43,7 +42,6 @@ public class WaitForSnapshotStep extends AsyncWaitStep { private static final String UNEXPECTED_SNAPSHOT_STATE_MESSAGE = "unexpected number of snapshots retrieved for repository '%s' and snapshot '%s' (expected 1, found %d)"; - private static final String NO_INDEX_METADATA_MESSAGE = "no index metadata found for index '%s'"; private static final String NO_ACTION_TIME_MESSAGE = "no information about ILM action start in index metadata for index '%s'"; private final String policy; @@ -54,17 +52,12 @@ public class WaitForSnapshotStep extends AsyncWaitStep { } @Override - 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; - } - + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { + String indexName = indexMetadata.getIndex().getName(); Long actionTime = indexMetadata.getLifecycleExecutionState().actionTime(); if (actionTime == null) { - listener.onFailure(error(NO_ACTION_TIME_MESSAGE, index.getName())); + listener.onFailure(error(NO_ACTION_TIME_MESSAGE, indexName)); return; } @@ -112,10 +105,10 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener if (response.getSnapshots().size() != 1) { listener.onFailure(error(UNEXPECTED_SNAPSHOT_STATE_MESSAGE, repositoryName, snapshotName, response.getSnapshots().size())); } else { - if (response.getSnapshots().get(0).indices().contains(index.getName())) { + if (response.getSnapshots().get(0).indices().contains(indexName)) { listener.onResponse(true, EmptyInfo.INSTANCE); } else { - listener.onFailure(error(INDEX_NOT_INCLUDED_IN_SNAPSHOT_MESSAGE, policy, index.getName())); + listener.onFailure(error(INDEX_NOT_INCLUDED_IN_SNAPSHOT_MESSAGE, policy, indexName)); } } }, listener::onFailure)); 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 6a6637bd61c7d..cee1cd5259142 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 @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.metadata.LifecycleExecutionState; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.xpack.core.ilm.step.info.EmptyInfo; import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo; @@ -66,18 +65,15 @@ public boolean equals(Object obj) { } @Override - 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 = state.metadata().index(index.getName()).getLifecycleExecutionState(); + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { + String indexName = indexMetadata.getIndex().getName(); + final LifecycleExecutionState executionState = indexMetadata.getLifecycleExecutionState(); assert executionState != null - : "the lifecycle execution state for index [" + index.getName() + "] must exist in the cluster state for step [" + NAME + "]"; + : "the lifecycle execution state for index [" + indexName + "] must exist in the cluster state for step [" + NAME + "]"; if (replicateFor == null) { // assert at dev-time, but treat this as a no-op at runtime if somehow this should happen (which it shouldn't) - assert false : "the replicate_for time value for index [" + index.getName() + "] must not be null for step [" + NAME + "]"; + assert false : "the replicate_for time value for index [" + indexName + "] must not be null for step [" + NAME + "]"; listener.onResponse(true, EmptyInfo.INSTANCE); return; } @@ -97,7 +93,7 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener // balance between precision and efficiency. approximateTimeRemaining(remaining), this.replicateFor, - index.getName() + indexName ) ) ); 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 800744d74c1e6..e50964773bf6a 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 @@ -10,7 +10,6 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.xpack.core.ilm.step.info.EmptyInfo; @@ -43,18 +42,15 @@ public boolean isRetryable() { } @Override - 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 + "]"; - + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { + String indexName = indexMetadata.getIndex().getName(); if (IndexSettings.MODE.get(indexMetadata.getSettings()) != IndexMode.TIME_SERIES) { // this index is not a time series index so no need to wait listener.onResponse(true, EmptyInfo.INSTANCE); return; } Instant configuredEndTime = IndexSettings.TIME_SERIES_END_TIME.get(indexMetadata.getSettings()); - assert configuredEndTime != null : "a time series index must have an end time configured but [" + index.getName() + "] does not"; + assert configuredEndTime != null : "a time series index must have an end time configured but [" + indexName + "] does not"; if (nowSupplier.get().isBefore(configuredEndTime)) { listener.onResponse( false, @@ -63,7 +59,7 @@ public void evaluateCondition(ProjectState state, Index index, Listener listener "The [%s] setting for index [%s] is [%s]. Waiting until the index's time series end time lapses before" + " proceeding with action [%s] as the index can still accept writes.", IndexSettings.TIME_SERIES_END_TIME.getKey(), - index.getName(), + indexName, configuredEndTime.toEpochMilli(), getKey().action() ) 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 3625a007c3a04..c5bfbb3f5794c 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 @@ -104,7 +104,7 @@ public void testIsConditionMet() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { conditionMetResult.set(conditionMet); @@ -157,7 +157,7 @@ public void testIsConditionIsTrueEvenWhenMoreSegments() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { conditionMetResult.set(conditionMet); @@ -215,7 +215,7 @@ public void testFailedToRetrieveSomeSegments() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { conditionMetResult.set(conditionMet); @@ -253,7 +253,7 @@ public void testThrowsException() { SegmentCountStep step = new SegmentCountStep(stepKey, nextStepKey, client, maxNumSegments); IndexMetadata indexMetadata = makeMeta(index); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, 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 457e46aa5acae..e029947a28a41 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 @@ -71,7 +71,7 @@ public void testConditionMet() { final ToXContentObject[] informationContextHolder = new ToXContentObject[1]; final Exception[] exceptionHolder = new Exception[1]; final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + createRandomInstance().evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder[0] = conditionMet; @@ -106,7 +106,7 @@ public void testConditionNotMetShardsNotInSync() { final ToXContentObject[] informationContextHolder = new ToXContentObject[1]; final Exception[] exceptionHolder = new Exception[1]; final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + createRandomInstance().evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder[0] = conditionMet; @@ -140,7 +140,7 @@ public void testConditionNotMetNotAFollowerIndex() { final ToXContentObject[] informationContextHolder = new ToXContentObject[1]; final Exception[] exceptionHolder = new Exception[1]; final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - createRandomInstance().evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + createRandomInstance().evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder[0] = conditionMet; 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 554b48c1340bf..c08228347566b 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 @@ -85,7 +85,7 @@ public void testConditionMetWhenCCREnabled() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -120,7 +120,7 @@ public void testConditionMetWhenCCRDisabled() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -155,7 +155,7 @@ public void testConditionNotMet() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -197,7 +197,7 @@ public void testNoShardStats() { final SetOnce conditionMetHolder = new SetOnce<>(); final SetOnce stepInfoHolder = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject informationContext) { conditionMetHolder.set(conditionMet); @@ -238,7 +238,7 @@ public void testFailure() { final SetOnce exceptionHolder = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, 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 0787e5728e0bd..f99b5e51f8ff0 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 @@ -235,7 +235,7 @@ public void testEvaluateCondition() { SetOnce conditionsMet = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -294,7 +294,7 @@ public void testEvaluateConditionOnDataStreamTarget() { ) ); IndexMetadata indexToOperateOn = failureStoreIndex ? failureStoreMetadata : indexMetadata; - step.evaluateCondition(state, indexToOperateOn.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexToOperateOn, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -373,7 +373,7 @@ public void testSkipRolloverIfDataStreamIsAlreadyRolledOver() { ) ); IndexMetadata indexToOperateOn = failureStoreIndex ? firstGenerationFailureIndex : firstGenerationIndex; - step.evaluateCondition(state, indexToOperateOn.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexToOperateOn, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -422,7 +422,7 @@ public void testEvaluateDoesntTriggerRolloverForIndexManuallyRolledOnLifecycleRo WaitForRolloverReadyStep step = createRandomInstance(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -457,7 +457,7 @@ public void testEvaluateTriggersRolloverForIndexManuallyRolledOnDifferentAlias() WaitForRolloverReadyStep step = createRandomInstance(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -484,7 +484,7 @@ public void testPerformActionWriteIndexIsFalse() { WaitForRolloverReadyStep step = createRandomInstance(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -526,7 +526,7 @@ public void testPerformActionWithIndexingComplete() { SetOnce conditionsMet = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -558,7 +558,7 @@ public void testPerformActionWithIndexingCompleteStillWriteIndex() { SetOnce correctFailureCalled = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -589,7 +589,7 @@ public void testPerformActionNotComplete() { SetOnce actionCompleted = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -634,7 +634,7 @@ public void testPerformActionFailure() { SetOnce exceptionThrown = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -668,7 +668,7 @@ public void testPerformActionInvalidNullOrEmptyAlias() { SetOnce exceptionThrown = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { throw new AssertionError("Unexpected method call"); @@ -704,7 +704,7 @@ public void testPerformActionAliasDoesNotPointToIndex() { SetOnce exceptionThrown = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - step.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMetadata, 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 d43677a412aa3..33f03e24f01c5 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 @@ -85,7 +85,7 @@ public void testNoSlmPolicies() { WaitForSnapshotStep instance = createRandomInstance(); SetOnce error = new SetOnce<>(); final var state = projectStateFromProject(ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true)); - instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + instance.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { logger.warn("expected an error got unexpected response {}", conditionMet); @@ -126,7 +126,7 @@ public void testSlmPolicyNotExecuted() { .put(indexMetadata, true) .putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) ); - instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + instance.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { isConditionMet.set(conditionMet); @@ -239,7 +239,7 @@ public void testIndexNotBackedUpYet() { final var state = projectStateFromProject( ProjectMetadata.builder(projectId).put(indexMetadata, true).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) ); - instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + instance.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { logger.warn("expected an error got unexpected response {}", conditionMet); @@ -306,7 +306,7 @@ private void assertSlmPolicyExecuted( final var state = projectStateFromProject( ProjectMetadata.builder(projectId).put(indexMetadata, true).putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) ); - instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + instance.evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject info) { isConditionMet.set(conditionMet); @@ -364,7 +364,7 @@ public void testNullStartTime() { .put(indexMetadata, true) .putCustom(SnapshotLifecycleMetadata.TYPE, smlMetadata) ); - instance.evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + instance.evaluateCondition(state, indexMetadata, 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 8e6615b936001..c5e70393d2c55 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 @@ -79,7 +79,7 @@ public void testEvaluateCondition() { // if we evaluate the condition now, it hasn't been met, because it hasn't been an hour returnVal.set(now); - step.evaluateCondition(state, indexMeta.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMeta, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { assertThat(complete, is(false)); @@ -92,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(state, indexMeta.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMeta, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { assertThat(complete, is(false)); @@ -105,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(state, indexMeta.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(state, indexMeta, 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 1316513594310..db30c56f1d556 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 @@ -79,7 +79,7 @@ public void testEvaluateCondition() { // end_time has lapsed already so condition must be met Index previousGeneration = dataStream.getIndices().get(0); - step.evaluateCondition(state, previousGeneration, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, project.index(previousGeneration), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -97,7 +97,7 @@ public void onFailure(Exception e) { // end_time is in the future Index writeIndex = dataStream.getIndices().get(1); - step.evaluateCondition(state, writeIndex, new AsyncWaitStep.Listener() { + step.evaluateCondition(state, project.index(writeIndex), new AsyncWaitStep.Listener() { @Override public void onResponse(boolean complete, ToXContentObject informationContext) { @@ -131,7 +131,7 @@ public void onFailure(Exception e) { .build(); ProjectState newState = state.updateProject(ProjectMetadata.builder(project).put(indexMeta, true).build()); - step.evaluateCondition(newState, indexMeta.getIndex(), new AsyncWaitStep.Listener() { + step.evaluateCondition(newState, indexMeta, 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 d6669f9701ec7..79dc7cb25696e 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 @@ -236,7 +236,7 @@ void runPeriodicStep(ProjectState state, String policy, IndexMetadata indexMetad } } else if (currentStep instanceof AsyncWaitStep) { logger.debug("[{}] running periodic policy with current-step [{}]", index, currentStep.getKey()); - ((AsyncWaitStep) currentStep).evaluateCondition(state, indexMetadata.getIndex(), new AsyncWaitStep.Listener() { + ((AsyncWaitStep) currentStep).evaluateCondition(state, indexMetadata, new AsyncWaitStep.Listener() { @Override public void onResponse(boolean conditionMet, ToXContentObject stepInfo) { 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 41cda5ebf4913..8bb47dc9ed3da 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 @@ -1042,7 +1042,7 @@ public void setLatch(CountDownLatch latch) { } @Override - public void evaluateCondition(ProjectState state, Index index, Listener listener, TimeValue masterTimeout) { + public void evaluateCondition(ProjectState state, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout) { executeCount++; if (latch != null) { latch.countDown();