Skip to content

Commit

Permalink
Successful deletes of an index still adds history document (opensearc…
Browse files Browse the repository at this point in the history
…h-project#160)

Signed-off-by: Drew Baugher <[email protected]>
  • Loading branch information
dbbaughe authored and downsrob committed Mar 9, 2022
1 parent 2a68512 commit 5074b72
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ object ManagedIndexRunner :
}

if (executedManagedIndexMetaData.isSuccessfulDelete) {
GlobalScope.launch(Dispatchers.IO + CoroutineName("ManagedIndexMetaData-AddHistory")) {
ismHistory.addManagedIndexMetaDataHistory(listOf(executedManagedIndexMetaData))
}
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.indexmanagement.indexstatemanagement.action

import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase
import org.opensearch.indexmanagement.indexstatemanagement.model.Policy
import org.opensearch.indexmanagement.indexstatemanagement.model.State
import org.opensearch.indexmanagement.indexstatemanagement.model.action.DeleteActionConfig
import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification
import org.opensearch.indexmanagement.waitFor
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.Locale

class DeleteActionIT : IndexStateManagementRestTestCase() {

private val testIndexName = javaClass.simpleName.toLowerCase(Locale.ROOT)

fun `test basic`() {
val indexName = "${testIndexName}_index_1"
val policyID = "${testIndexName}_testPolicyName_1"
val actionConfig = DeleteActionConfig(0)
val states = listOf(
State("DeleteState", listOf(actionConfig), listOf())
)

val policy = Policy(
id = policyID,
description = "$testIndexName description",
schemaVersion = 1L,
lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS),
errorNotification = randomErrorNotification(),
defaultState = states[0].name,
states = states
)
createPolicy(policy, policyID)
createIndex(indexName, policyID)

waitFor { assertIndexExists(indexName) }

val managedIndexConfig = getExistingManagedIndexConfig(indexName)
// Change the start time so the job will trigger in 2 seconds.
updateManagedIndexConfigStartTime(managedIndexConfig)

waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(indexName).policyID) }

// Need to wait two cycles.
// Change the start time so the job will trigger in 2 seconds.
updateManagedIndexConfigStartTime(managedIndexConfig)

// confirm index does not exist anymore
waitFor { assertIndexDoesNotExist(indexName) }

// confirm we added a history document that says we did a successful delete operation
waitFor {
val response = getHistorySearchResponse(indexName)
assertTrue(
response.hits.hits
.map { it.sourceAsMap }
.any {
val metadata = it["managed_index_meta_data"] as Map<*, *>
val index = metadata["index"] as String
val action = metadata["action"] as Map<*, *>
val actionName = action["name"] as String
val step = metadata["step"] as Map<*, *>
val stepName = step["name"] as String
val stepStatus = step["step_status"] as String
index == indexName && actionName == "delete" && stepName == "attempt_delete" && stepStatus == "completed"
}
)
}
}
}

0 comments on commit 5074b72

Please sign in to comment.