Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding base logic to transition step to enable policy execution #223

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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