Skip to content

Commit

Permalink
changes based on comments
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Downs <[email protected]>
  • Loading branch information
downsrob committed Mar 4, 2022
1 parent cbe8c07 commit ade5565
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ abstract class Action(
final fun isFirstStep(stepName: String): Boolean = getSteps().first().name == stepName

/*
* Gets if the managedIndexMetaData reflects a state in which this action has completed successfully
* Gets if the managedIndexMetaData reflects a state in which this action has completed successfully. Used in the
* runner when determining if the index metadata should be deleted. If the action isFinishedSuccessfully and
* deleteIndexMetadataAfterFinish is set to true, then we issue a request to delete the managedIndexConfig and its
* managedIndexMetadata.
*/
final fun isFinishedSuccessfully(managedIndexMetaData: ManagedIndexMetaData): Boolean {
val policyRetryInfo = managedIndexMetaData.policyRetryInfo
if (policyRetryInfo == null || policyRetryInfo.failed) return false
if (policyRetryInfo?.failed == true) return false
val actionMetaData = managedIndexMetaData.actionMetaData
if (actionMetaData == null || actionMetaData.failed || actionMetaData.name != this.type) return false
val stepMetaData = managedIndexMetaData.stepMetaData
Expand All @@ -105,7 +108,8 @@ abstract class Action(

/*
* Denotes if the index metadata in the config index should be deleted for the index this action has just
* successfully finished running on.
* successfully finished running on. This may be used by custom actions which delete some off-cluster index,
* and following the action's success, the managed index config and metadata need to be deleted.
*/
open fun deleteIndexMetadataAfterFinish(): Boolean = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ object ManagedIndexRunner :
return
}

// If a custom action deletes some off-cluster index and has deleteIndexMetadataAfterFinish set to true,
// then when the action successfully finishes, we will delete the managed index config and metadata. We do not
// need to do this for the standard delete action as the coordinator picks up the index deletion and removes the config
if (action.isFinishedSuccessfully(executedManagedIndexMetaData)) {
// Custom actions added by extensions may require a manual deletion of the managed index metadata after a successful execution
if (action.deleteIndexMetadataAfterFinish()) {
deleteFromManagedIndex(managedIndexConfig, action.type)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ data class State(
init {
require(name.isNotBlank()) { "State must contain a valid name" }
var hasDelete = false
actions.forEach { actionConfig ->
actions.forEach { action ->
// dont allow actions after delete as they will never happen
require(!hasDelete) { "State=$name must not contain an action after a delete action" }
hasDelete = actionConfig.type == DeleteAction.name
hasDelete = action.type == DeleteAction.name || action.deleteIndexMetadataAfterFinish()
}

// dont allow transitions if state contains delete
Expand Down

0 comments on commit ade5565

Please sign in to comment.