Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

actionify change policy API #303

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -33,6 +33,8 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.addpolicy.AddPolicyAction
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.addpolicy.TransportAddPolicyAction
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.changepolicy.ChangePolicyAction
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.changepolicy.TransportChangePolicyAction
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.removepolicy.RemovePolicyAction
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.removepolicy.TransportRemovePolicyAction
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.retryfailedmanagedindex.RetryFailedManagedIndexAction
Expand Down Expand Up @@ -134,7 +136,7 @@ internal class IndexManagementPlugin : JobSchedulerExtension, ActionPlugin, Plug
RestRetryFailedManagedIndexAction(),
RestAddPolicyAction(),
RestRemovePolicyAction(),
RestChangePolicyAction(clusterService)
RestChangePolicyAction()
)
}

Expand Down Expand Up @@ -201,7 +203,8 @@ internal class IndexManagementPlugin : JobSchedulerExtension, ActionPlugin, Plug
ActionPlugin.ActionHandler(RemovePolicyAction.INSTANCE, TransportRemovePolicyAction::class.java),
ActionPlugin.ActionHandler(RefreshSearchAnalyzerAction.INSTANCE, TransportRefreshSearchAnalyzerAction::class.java),
ActionPlugin.ActionHandler(AddPolicyAction.INSTANCE, TransportAddPolicyAction::class.java),
ActionPlugin.ActionHandler(RetryFailedManagedIndexAction.INSTANCE, TransportRetryFailedManagedIndexAction::class.java)
ActionPlugin.ActionHandler(RetryFailedManagedIndexAction.INSTANCE, TransportRetryFailedManagedIndexAction::class.java),
ActionPlugin.ActionHandler(ChangePolicyAction.INSTANCE, TransportChangePolicyAction::class.java)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model

import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StateMetaData
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.io.stream.Writeable
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand All @@ -39,7 +42,7 @@ data class ChangePolicy(
val state: String?,
val include: List<StateFilter>,
val isSafe: Boolean
) : ToXContentObject {
) : Writeable, ToXContentObject {

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder
Expand All @@ -51,12 +54,33 @@ data class ChangePolicy(
return builder
}

override fun writeTo(out: StreamOutput) {
out.writeString(policyID)
out.writeOptionalString(state)
out.writeBoolean(isSafe)
out.writeCollection(include)
}

companion object {
const val POLICY_ID_FIELD = "policy_id"
const val STATE_FIELD = "state"
const val INCLUDE_FIELD = "include"
const val IS_SAFE_FIELD = "is_safe"

fun fromStreamInput(sin: StreamInput): ChangePolicy {
bowenlan-amzn marked this conversation as resolved.
Show resolved Hide resolved
bowenlan-amzn marked this conversation as resolved.
Show resolved Hide resolved
val policyID: String? = sin.readString()
val state: String? = sin.readOptionalString()
val isSafe: Boolean = sin.readBoolean()
val include: MutableList<StateFilter> = sin.readList { StateFilter.fromStreamInput(it) }

return ChangePolicy(
requireNotNull(policyID) { "ChangePolicy policy id is null" },
state,
include.toList(),
isSafe
)
}

@JvmStatic
@Throws(IOException::class)
fun parse(xcp: XContentParser): ChangePolicy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@

package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model

import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.io.stream.Writeable
import org.elasticsearch.common.xcontent.XContentParser
import org.elasticsearch.common.xcontent.XContentParser.Token
import org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken
import java.io.IOException

data class StateFilter(val state: String) {
data class StateFilter(val state: String) : Writeable {

override fun writeTo(out: StreamOutput) {
out.writeString(state)
}

companion object {
const val STATE_FIELD = "state"

Expand All @@ -41,5 +49,11 @@ data class StateFilter(val state: String) {

return StateFilter(requireNotNull(state) { "Must include a state when using include filter" })
}

fun fromStreamInput(sin: StreamInput): StateFilter {
bowenlan-amzn marked this conversation as resolved.
Show resolved Hide resolved
val state: String? = sin.readString()

return StateFilter(requireNotNull(state) { "Must include a state when using include filter" })
}
}
}
Loading