Skip to content

Commit

Permalink
Implements RolloverAction with new interface, fixes default action re…
Browse files Browse the repository at this point in the history
…try commit (#231)

* Implements rollover action with new interface, fixes default action retry

Signed-off-by: Clay Downs <[email protected]>
  • Loading branch information
downsrob authored Dec 21, 2021
1 parent e9b4212 commit f8fc089
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 52 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ integTest {
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/IndexStateManagementHistoryIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/ReplicaCountActionIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/RolloverActionIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/RollupActionIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/TransitionActionIT.class'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class Action(
) : ToXContentObject, Writeable {

var configTimeout: ActionTimeout? = null
var configRetry: ActionRetry? = null
var configRetry: ActionRetry? = ActionRetry(DEFAULT_RETRIES)

final override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder.startObject()
Expand Down Expand Up @@ -67,4 +67,8 @@ abstract class Action(
final fun isLastStep(stepName: String): Boolean = getSteps().last().name == stepName

final fun isFirstStep(stepName: String): Boolean = getSteps().first().name == stepName

companion object {
const val DEFAULT_RETRIES = 3L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.DeleteActionPa
import org.opensearch.indexmanagement.indexstatemanagement.action.OpenActionParser
import org.opensearch.indexmanagement.indexstatemanagement.action.ReadOnlyActionParser
import org.opensearch.indexmanagement.indexstatemanagement.action.ReadWriteActionParser
import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverActionParser
import org.opensearch.indexmanagement.spi.indexstatemanagement.Action
import org.opensearch.indexmanagement.spi.indexstatemanagement.ActionParser
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionRetry
Expand All @@ -30,7 +31,8 @@ class ISMActionsParser private constructor() {
DeleteActionParser(),
OpenActionParser(),
ReadOnlyActionParser(),
ReadWriteActionParser()
ReadWriteActionParser(),
RolloverActionParser()
)

fun addParser(parser: ActionParser) {
Expand All @@ -53,7 +55,7 @@ class ISMActionsParser private constructor() {
fun parse(xcp: XContentParser, totalActions: Int): Action {
var action: Action? = null
var timeout: ActionTimeout? = null
var retry: ActionRetry? = null
var retry: ActionRetry? = ActionRetry(Action.DEFAULT_RETRIES)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
val type = xcp.currentName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

package org.opensearch.indexmanagement.indexstatemanagement.action

import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.common.unit.ByteSizeValue
import org.opensearch.common.unit.TimeValue
import org.opensearch.common.xcontent.ToXContent
import org.opensearch.common.xcontent.XContentBuilder
import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep
import org.opensearch.indexmanagement.spi.indexstatemanagement.Action
import org.opensearch.indexmanagement.spi.indexstatemanagement.Step
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext
Expand All @@ -18,12 +22,34 @@ class RolloverAction(
index: Int
) : Action(name, index) {

init {
if (minSize != null) require(minSize.bytes > 0) { "RolloverAction minSize value must be greater than 0" }

if (minDocs != null) require(minDocs > 0) { "RolloverAction minDocs value must be greater than 0" }
}

private val attemptRolloverStep = AttemptRolloverStep(this)
private val steps = listOf(attemptRolloverStep)

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

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

override fun populateAction(builder: XContentBuilder, params: ToXContent.Params) {
builder.startObject(type)
if (minSize != null) builder.field(MIN_SIZE_FIELD, minSize.stringRep)
if (minDocs != null) builder.field(MIN_DOC_COUNT_FIELD, minDocs)
if (minAge != null) builder.field(MIN_INDEX_AGE_FIELD, minAge.stringRep)
builder.endObject()
}

override fun getSteps(): List<Step> {
TODO("Not yet implemented")
override fun populateAction(out: StreamOutput) {
out.writeOptionalWriteable(minSize)
out.writeOptionalLong(minDocs)
out.writeOptionalTimeValue(minAge)
out.writeInt(actionIndex)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,45 @@
package org.opensearch.indexmanagement.indexstatemanagement.action

import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.unit.ByteSizeValue
import org.opensearch.common.unit.TimeValue
import org.opensearch.common.xcontent.XContentParser
import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken
import org.opensearch.indexmanagement.spi.indexstatemanagement.Action
import org.opensearch.indexmanagement.spi.indexstatemanagement.ActionParser

class RolloverActionParser : ActionParser() {
override fun fromStreamInput(sin: StreamInput): Action {
TODO("Not yet implemented")
val minSize = sin.readOptionalWriteable(::ByteSizeValue)
val minDocs = sin.readOptionalLong()
val minAge = sin.readOptionalTimeValue()
val index = sin.readInt()

return RolloverAction(minSize, minDocs, minAge, index)
}

override fun fromXContent(xcp: XContentParser, index: Int): Action {
TODO("Not yet implemented")
var minSize: ByteSizeValue? = null
var minDocs: Long? = null
var minAge: TimeValue? = null

ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
val fieldName = xcp.currentName()
xcp.nextToken()

when (fieldName) {
RolloverAction.MIN_SIZE_FIELD -> minSize = ByteSizeValue.parseBytesSizeValue(xcp.text(), RolloverAction.MIN_SIZE_FIELD)
RolloverAction.MIN_DOC_COUNT_FIELD -> minDocs = xcp.longValue()
RolloverAction.MIN_INDEX_AGE_FIELD -> minAge = TimeValue.parseTimeValue(xcp.text(), RolloverAction.MIN_INDEX_AGE_FIELD)
else -> throw IllegalArgumentException("Invalid field: [$fieldName] found in RolloverAction.")
}
}

return RolloverAction(minSize, minDocs, minAge, index)
}

override fun getActionType(): String {
TODO("Not yet implemented")
return RolloverAction.name
}
}
Loading

0 comments on commit f8fc089

Please sign in to comment.