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

Implements RolloverAction with new interface, fixes default action retry commit #231

Merged
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
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ integTest {
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.class'
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/OpenActionIT.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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, what does 3L stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The L suffix there designates that the number is a long, so it would be equivalent to do const val DEFAULT_RETRIES: Long = 3. There are similar suffixes such as d for double or f for float, and they just let you designate a type when writing out a numeric literal.

}
}
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 @@ -12,6 +12,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.CloseActionPar
import org.opensearch.indexmanagement.indexstatemanagement.action.DeleteActionParser
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 @@ -28,7 +29,8 @@ class ISMActionsParser private constructor() {
CloseActionParser(),
DeleteActionParser(),
ReadOnlyActionParser(),
ReadWriteActionParser()
ReadWriteActionParser(),
RolloverActionParser()
)

fun addParser(parser: ActionParser) {
Expand All @@ -51,7 +53,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