@@ -42,6 +42,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.model.action.Rollover
4242import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification
4343import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestRetryFailedManagedIndexAction
4444import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings
45+ import org.opensearch.indexmanagement.indexstatemanagement.step.Step
4546import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep
4647import org.opensearch.indexmanagement.makeRequest
4748import org.opensearch.indexmanagement.waitFor
@@ -496,4 +497,46 @@ class RolloverActionIT : IndexStateManagementRestTestCase() {
496497 val secondIndexName = DataStream .getDefaultBackingIndexName(dataStreamName, 2L )
497498 Assert .assertTrue(" New rollover index does not exist." , indexExists(secondIndexName))
498499 }
500+
501+ @Suppress(" UNCHECKED_CAST" )
502+ fun `test rollover from outside ISM doesn't fail ISM job` () {
503+ val aliasName = " ${testIndexName} _alias"
504+ val indexNameBase = " ${testIndexName} _index"
505+ val firstIndex = " $indexNameBase -1"
506+ val policyID = " ${testIndexName} _testPolicyName_1"
507+ val actionConfig = RolloverActionConfig (null , null , null , 0 )
508+ val states = listOf (State (name = " RolloverAction" , actions = listOf (actionConfig), transitions = listOf ()))
509+ val policy = Policy (
510+ id = policyID,
511+ description = " $testIndexName description" ,
512+ schemaVersion = 1L ,
513+ lastUpdatedTime = Instant .now().truncatedTo(ChronoUnit .MILLIS ),
514+ errorNotification = randomErrorNotification(),
515+ defaultState = states[0 ].name,
516+ states = states
517+ )
518+
519+ createPolicy(policy, policyID)
520+ // create index defaults
521+ createIndex(firstIndex, policyID, aliasName)
522+
523+ val managedIndexConfig = getExistingManagedIndexConfig(firstIndex)
524+
525+ // Change the start time so the job will trigger in 2 seconds, this will trigger the first initialization of the policy
526+ updateManagedIndexConfigStartTime(managedIndexConfig)
527+ waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(firstIndex).policyID) }
528+
529+ // Rollover the alias manually before ISM tries to roll it over
530+ rolloverIndex(aliasName)
531+
532+ // Need to speed up to second execution where it will trigger the first execution of the action
533+ updateManagedIndexConfigStartTime(managedIndexConfig)
534+ waitFor {
535+ val info = getExplainManagedIndexMetaData(firstIndex).info as Map <String , Any ?>
536+ val stepMetadata = getExplainManagedIndexMetaData(firstIndex).stepMetaData
537+ assertEquals(" Index should succeed if already rolled over." , AttemptRolloverStep .getAlreadyRolledOverMessage(firstIndex, aliasName), info[" message" ])
538+ assertEquals(" Index should succeed if already rolled over." , Step .StepStatus .COMPLETED , stepMetadata?.stepStatus)
539+ }
540+ assertTrue(" New rollover index does not exist." , indexExists(" $indexNameBase -000002" ))
541+ }
499542}
0 commit comments