Skip to content

Commit

Permalink
Adding base logic to transition step to enable policy execution (#223)
Browse files Browse the repository at this point in the history
Signed-off-by: Ravi Thaluru <[email protected]>
  • Loading branch information
thalurur authored Dec 14, 2021
1 parent bca8b41 commit 9aa8bde
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.opensearch.index.engine.VersionConflictEngineException
import org.opensearch.index.seqno.SequenceNumbers
import org.opensearch.indexmanagement.IndexManagementIndices
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX
import org.opensearch.indexmanagement.indexstatemanagement.action.TransitionsAction
import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig
import org.opensearch.indexmanagement.indexstatemanagement.model.Policy
import org.opensearch.indexmanagement.indexstatemanagement.opensearchapi.getManagedIndexMetadata
Expand Down Expand Up @@ -324,7 +325,7 @@ object ManagedIndexRunner :

// If this action is not allowed and the step to be executed is the first step in the action then we will fail
// as this action has been removed from the AllowList, but if its not the first step we will let it finish as it's already inflight
if (action?.isAllowed(allowList) == false && action.isFirstStep(step?.name)) {
if (!action?.isAllowed(allowList) && action.isFirstStep(step?.name) && action.type != TransitionsAction.name) {
val info = mapOf("message" to "Attempted to execute action=${action.type} which is not allowed.")
val updated = updateManagedIndexMetaData(
managedIndexMetaData.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.indexmanagement.indexstatemanagement.action

import org.opensearch.indexmanagement.indexstatemanagement.model.Transition
import org.opensearch.indexmanagement.indexstatemanagement.step.transition.AttemptTransitionStep
import org.opensearch.indexmanagement.spi.indexstatemanagement.Action
import org.opensearch.indexmanagement.spi.indexstatemanagement.Step
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext
Expand All @@ -14,15 +15,16 @@ class TransitionsAction(
transitions: List<Transition>,
) : Action(name, -1) {

companion object {
const val name = "transition"
}
private val attemptTransitionStep = AttemptTransitionStep()
private val steps = listOf(attemptTransitionStep)

override fun getSteps(): List<Step> = steps

override fun getStepToExecute(context: StepContext): Step {
TODO("Not yet implemented")
return attemptTransitionStep
}

override fun getSteps(): List<Step> {
TODO("Not yet implemented")
companion object {
const val name = "transition"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,36 @@

package org.opensearch.indexmanagement.indexstatemanagement.step.transition

import org.apache.logging.log4j.LogManager
import org.opensearch.indexmanagement.spi.indexstatemanagement.Step
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData

class AttemptTransitionStep : Step(name) {

private val logger = LogManager.getLogger(javaClass)
private var stateName: String? = null
private var stepStatus = StepStatus.STARTING
private var policyCompleted: Boolean = false
private var info: Map<String, Any>? = null

override suspend fun execute(): Step {
TODO("Not yet implemented")
// TODO: Fix this to actually evaluate the conditions
stepStatus = StepStatus.COMPLETED
policyCompleted = true
return this
}

override fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData {
TODO("Not yet implemented")
return currentMetadata.copy(
policyCompleted = policyCompleted,
transitionTo = stateName,
stepMetaData = StepMetaData(name, getStepStartTime(currentMetadata).toEpochMilli(), stepStatus),
info = info
)
}

override fun isIdempotent(): Boolean {
TODO("Not yet implemented")
}
override fun isIdempotent() = true

companion object {
const val name = "attempt_transition_step"
Expand Down

0 comments on commit 9aa8bde

Please sign in to comment.