diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionConfig.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionConfig.kt index 6095d1383..f9329f58b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionConfig.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionConfig.kt @@ -28,9 +28,7 @@ abstract class ActionConfig( ) : ToXContentFragment, Writeable { var configTimeout: ActionTimeout? = null - private set var configRetry: ActionRetry? = null - private set override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { configTimeout?.toXContent(builder, params) @@ -76,6 +74,8 @@ abstract class ActionConfig( } companion object { + private const val DEFAULT_RETRIES = 3L + // TODO clean up for actionIndex @JvmStatic @Throws(IOException::class) @@ -115,7 +115,7 @@ abstract class ActionConfig( fun parse(xcp: XContentParser, index: Int): ActionConfig { var actionConfig: ActionConfig? = null var timeout: ActionTimeout? = null - var retry: ActionRetry? = null + var retry: ActionRetry? = ActionRetry(DEFAULT_RETRIES) ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionRetry.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionRetry.kt index 115ab41ef..be73d5483 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionRetry.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/action/ActionRetry.kt @@ -28,7 +28,7 @@ data class ActionRetry( val delay: TimeValue = TimeValue.timeValueMinutes(1) ) : ToXContentFragment, Writeable { - init { require(count > 0) { "Count for ActionRetry must be greater than 0" } } + init { require(count >= 0) { "Count for ActionRetry must be a non-negative number" } } override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { builder diff --git a/src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt index 55701dffb..aa4b1c28f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt @@ -98,6 +98,10 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() { @Throws(IOException::class) open fun wipeAllODFEIndices() { + // Delete all data stream indices + client().performRequest(Request("DELETE", "/_data_stream/*")) + + // Delete all indices val response = client().performRequest(Request("GET", "/_cat/indices?format=json&expand_wildcards=all")) val xContentType = XContentType.fromMediaTypeOrFormat(response.entity.contentType.value) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt index b5185685b..417295232 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.kt @@ -17,6 +17,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementR import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.model.State +import org.opensearch.indexmanagement.indexstatemanagement.model.action.ActionRetry import org.opensearch.indexmanagement.indexstatemanagement.model.action.RolloverActionConfig import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestRetryFailedManagedIndexAction @@ -277,6 +278,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { val alias1 = "x" val policyID = "${testIndexName}_precheck" val actionConfig = RolloverActionConfig(null, 3, TimeValue.timeValueDays(2), 0) + actionConfig.configRetry = ActionRetry(0) val states = listOf(State(name = "RolloverAction", actions = listOf(actionConfig), transitions = listOf())) val policy = Policy( id = policyID, diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionConfigTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionConfigTests.kt index 793603b5f..a7654405b 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionConfigTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ActionConfigTests.kt @@ -38,9 +38,9 @@ class ActionConfigTests : OpenSearchTestCase() { } } - fun `test action retry count of zero fails`() { + fun `test action retry count of -1 fails`() { assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for retry count less than 1") { - ActionRetry(count = 0) + ActionRetry(count = -1) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt index 2e1d5551b..fcc99c039 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/RestRetryFailedManagedIndexActionIT.kt @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler import org.opensearch.client.ResponseException import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData +import org.opensearch.indexmanagement.indexstatemanagement.model.action.ActionRetry import org.opensearch.indexmanagement.indexstatemanagement.model.action.AllocationActionConfig import org.opensearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.ActionMetaData import org.opensearch.indexmanagement.indexstatemanagement.randomForceMergeActionConfig @@ -208,10 +209,12 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { fun `test index failed`() { val indexName = "${testIndexName}_blueberry" + val config = AllocationActionConfig(require = mapOf("..//" to "value"), exclude = emptyMap(), include = emptyMap(), index = 0) + config.configRetry = ActionRetry(0) val states = listOf( randomState().copy( transitions = listOf(), - actions = listOf(AllocationActionConfig(require = mapOf("..//" to "value"), exclude = emptyMap(), include = emptyMap(), index = 0)) + actions = listOf(config) ) ) val invalidPolicy = randomPolicy().copy( @@ -251,7 +254,9 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() { fun `test reset action start time`() { val indexName = "${testIndexName}_drewberry" val policyID = "${testIndexName}_policy_1" - val policy = randomPolicy(states = listOf(randomState(actions = listOf(randomForceMergeActionConfig(maxNumSegments = 1))))) + val config = randomForceMergeActionConfig(maxNumSegments = 1) + config.configRetry = ActionRetry(0) + val policy = randomPolicy(states = listOf(randomState(actions = listOf(config)))) createPolicy(policy, policyId = policyID) createIndex(indexName, policyID)