Skip to content

Commit

Permalink
Unify NO_ID usage
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed May 16, 2022
1 parent 92cee58 commit 356ee98
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.opensearch.index.seqno.SequenceNumbers
import org.opensearch.indexmanagement.indexstatemanagement.util.XCONTENT_WITHOUT_TYPE
import org.opensearch.indexmanagement.opensearchapi.instant
import org.opensearch.indexmanagement.opensearchapi.optionalTimeField
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.jobscheduler.spi.ScheduledJobParameter
import org.opensearch.jobscheduler.spi.schedule.Schedule
import org.opensearch.jobscheduler.spi.schedule.ScheduleParser
Expand Down Expand Up @@ -86,7 +87,6 @@ data class ManagedIndexConfig(

companion object {
const val MANAGED_INDEX_TYPE = "managed_index"
const val NO_ID = ""
const val NAME_FIELD = "name"
const val ENABLED_FIELD = "enabled"
const val SCHEDULE_FIELD = "schedule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.opensearch.indexmanagement.opensearchapi.optionalTimeField
import org.opensearch.indexmanagement.opensearchapi.optionalUserField
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData
import org.opensearch.indexmanagement.util.IndexUtils
import org.opensearch.indexmanagement.util.NO_ID
import java.io.IOException
import java.time.Instant

Expand Down Expand Up @@ -147,7 +148,6 @@ data class Policy(
const val POLICY_TYPE = "policy"
const val POLICY_ID_FIELD = "policy_id"
const val DESCRIPTION_FIELD = "description"
const val NO_ID = ""
const val LAST_UPDATED_TIME_FIELD = "last_updated_time"
const val SCHEMA_VERSION_FIELD = "schema_version"
const val ERROR_NOTIFICATION_FIELD = "error_notification"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.transport.action.inde
import org.opensearch.indexmanagement.opensearchapi.parseWithType
import org.opensearch.indexmanagement.util.IF_PRIMARY_TERM
import org.opensearch.indexmanagement.util.IF_SEQ_NO
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.indexmanagement.util.REFRESH
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
Expand Down Expand Up @@ -69,8 +70,8 @@ class RestIndexPolicyAction(

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("policyID", Policy.NO_ID)
if (Policy.NO_ID == id) {
val id = request.param("policyID", NO_ID)
if (NO_ID == id) {
throw IllegalArgumentException("Missing policy ID")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.opensearch.action.support.WriteRequest
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.indexmanagement.indexstatemanagement.model.Policy
import org.opensearch.indexmanagement.util.NO_ID
import java.io.IOException

class IndexPolicyRequest : ActionRequest {
Expand Down Expand Up @@ -47,7 +48,7 @@ class IndexPolicyRequest : ActionRequest {

override fun validate(): ActionRequestValidationException? {
var validationException: ActionRequestValidationException? = null
if (Policy.NO_ID == policyID) {
if (NO_ID == policyID) {
validationException = ValidateActions.addValidationError("Missing policyID", validationException)
}
return validationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import org.opensearch.indexmanagement.opensearchapi.suspendUntil
import org.opensearch.indexmanagement.rollup.model.ContinuousMetadata
import org.opensearch.indexmanagement.rollup.model.Rollup
import org.opensearch.indexmanagement.rollup.model.RollupMetadata
import org.opensearch.indexmanagement.rollup.model.RollupMetadata.Companion.NO_ID
import org.opensearch.indexmanagement.rollup.model.RollupStats
import org.opensearch.indexmanagement.rollup.util.DATE_FIELD_EPOCH_MILLIS_FORMAT
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.search.aggregations.bucket.composite.InternalComposite
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder
import org.opensearch.search.builder.SearchSourceBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.opensearch.indexmanagement.opensearchapi.instant
import org.opensearch.indexmanagement.opensearchapi.optionalTimeField
import org.opensearch.indexmanagement.opensearchapi.optionalUserField
import org.opensearch.indexmanagement.util.IndexUtils
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.indexmanagement.util._ID
import org.opensearch.jobscheduler.spi.ScheduledJobParameter
import org.opensearch.jobscheduler.spi.schedule.CronSchedule
Expand Down Expand Up @@ -220,7 +221,6 @@ data class Rollup(
const val ROLLUP_LOCK_DURATION_SECONDS = 1800L // 30 minutes
const val ROLLUP_TYPE = "rollup"
const val ROLLUP_ID_FIELD = "rollup_id"
const val NO_ID = ""
const val ENABLED_FIELD = "enabled"
const val SCHEMA_VERSION_FIELD = "schema_version"
const val SCHEDULE_FIELD = "schedule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken
import org.opensearch.index.seqno.SequenceNumbers
import org.opensearch.indexmanagement.indexstatemanagement.util.WITH_TYPE
import org.opensearch.indexmanagement.opensearchapi.instant
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.search.aggregations.bucket.composite.InternalComposite
import java.io.IOException
import java.time.Instant
Expand Down Expand Up @@ -228,7 +229,6 @@ data class RollupMetadata(

companion object {
const val ROLLUP_METADATA_TYPE = "rollup_metadata"
const val NO_ID = ""
const val ROLLUP_ID_FIELD = "rollup_id"
const val AFTER_KEY_FIELD = "after_key"
const val LAST_UPDATED_FIELD = "last_updated_time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.opensearch.indexmanagement.rollup.action.index.IndexRollupResponse
import org.opensearch.indexmanagement.rollup.model.Rollup
import org.opensearch.indexmanagement.util.IF_PRIMARY_TERM
import org.opensearch.indexmanagement.util.IF_SEQ_NO
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.indexmanagement.util.REFRESH
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
Expand Down Expand Up @@ -58,8 +59,8 @@ class RestIndexRollupAction : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("rollupID", Rollup.NO_ID)
if (Rollup.NO_ID == id) {
val id = request.param("rollupID", NO_ID)
if (NO_ID == id) {
throw IllegalArgumentException("Missing rollup ID")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROL
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI
import org.opensearch.indexmanagement.rollup.action.start.StartRollupAction
import org.opensearch.indexmanagement.rollup.action.start.StartRollupRequest
import org.opensearch.indexmanagement.rollup.model.Rollup
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
import org.opensearch.rest.RestHandler.ReplacedRoute
Expand Down Expand Up @@ -41,7 +41,7 @@ class RestStartRollupAction : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("rollupID", Rollup.NO_ID)
val id = request.param("rollupID", NO_ID)
val startRequest = StartRollupRequest(id)
return RestChannelConsumer { channel ->
client.execute(StartRollupAction.INSTANCE, startRequest, RestToXContentListener(channel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.LEGACY_ROL
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI
import org.opensearch.indexmanagement.rollup.action.stop.StopRollupAction
import org.opensearch.indexmanagement.rollup.action.stop.StopRollupRequest
import org.opensearch.indexmanagement.rollup.model.Rollup
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
import org.opensearch.rest.RestHandler.ReplacedRoute
Expand Down Expand Up @@ -41,8 +41,8 @@ class RestStopRollupAction : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("rollupID", Rollup.NO_ID)
if (Rollup.NO_ID == id) {
val id = request.param("rollupID", NO_ID)
if (NO_ID == id) {
throw IllegalArgumentException("Missing rollup ID")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.opensearch.indexmanagement.opensearchapi.nullValueHandler
import org.opensearch.indexmanagement.opensearchapi.optionalField
import org.opensearch.indexmanagement.opensearchapi.optionalTimeField
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionTimeout
import org.opensearch.indexmanagement.util.IndexUtils.Companion.NO_ID
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.jobscheduler.spi.ScheduledJobParameter
import org.opensearch.jobscheduler.spi.schedule.CronSchedule
import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.opensearch.indexmanagement.opensearchapi.optionalUserField
import org.opensearch.indexmanagement.opensearchapi.suspendUntil
import org.opensearch.indexmanagement.transform.TransformSearchService
import org.opensearch.indexmanagement.util.IndexUtils
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.jobscheduler.spi.ScheduledJobParameter
import org.opensearch.jobscheduler.spi.schedule.CronSchedule
import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule
Expand Down Expand Up @@ -264,7 +265,6 @@ data class Transform(

val supportedAggregations = listOf("sum", "max", "min", "value_count", "avg", "scripted_metric", "percentiles")
const val LOCK_DURATION_SECONDS = 1800L
const val NO_ID = ""
const val TRANSFORM_TYPE = "transform"
const val TRANSFORM_ID_FIELD = "transform_id"
const val ENABLED_FIELD = "enabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.opensearch.indexmanagement.transform.action.index.IndexTransformRespo
import org.opensearch.indexmanagement.transform.model.Transform
import org.opensearch.indexmanagement.util.IF_PRIMARY_TERM
import org.opensearch.indexmanagement.util.IF_SEQ_NO
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.indexmanagement.util.REFRESH
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
Expand Down Expand Up @@ -46,8 +47,8 @@ class RestIndexTransformAction : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("transformID", Transform.NO_ID)
if (Transform.NO_ID == id) {
val id = request.param("transformID", NO_ID)
if (NO_ID == id) {
throw IllegalArgumentException("Missing transform ID")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.opensearch.client.node.NodeClient
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI
import org.opensearch.indexmanagement.transform.action.start.StartTransformAction
import org.opensearch.indexmanagement.transform.action.start.StartTransformRequest
import org.opensearch.indexmanagement.transform.model.Transform
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
import org.opensearch.rest.RestHandler.Route
Expand All @@ -32,7 +32,7 @@ class RestStartTransformAction : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("transformID", Transform.NO_ID)
val id = request.param("transformID", NO_ID)
val startRequest = StartTransformRequest(id)
return RestChannelConsumer { channel ->
client.execute(StartTransformAction.INSTANCE, startRequest, RestToXContentListener(channel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.opensearch.client.node.NodeClient
import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.TRANSFORM_BASE_URI
import org.opensearch.indexmanagement.transform.action.stop.StopTransformAction
import org.opensearch.indexmanagement.transform.action.stop.StopTransformRequest
import org.opensearch.indexmanagement.transform.model.Transform
import org.opensearch.indexmanagement.util.NO_ID
import org.opensearch.rest.BaseRestHandler
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
import org.opensearch.rest.RestHandler.Route
Expand All @@ -32,8 +32,8 @@ class RestStopTransformAction : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("transformID", Transform.NO_ID)
if (Transform.NO_ID == id) {
val id = request.param("transformID", NO_ID)
if (NO_ID == id) {
throw IllegalArgumentException("Missing transform ID")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class IndexUtils {
private const val BYTE_ARRAY_SIZE = 16
private const val DOCUMENT_ID_SEED = 72390L

const val NO_ID = ""

val logger = LogManager.getLogger(IndexUtils::class.java)

var indexManagementConfigSchemaVersion: Long
Expand Down

0 comments on commit 356ee98

Please sign in to comment.