Skip to content

Commit

Permalink
lint: add rules and apply formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Ashiwal <[email protected]>
  • Loading branch information
r1walz committed Feb 8, 2024
1 parent 9dbc8b3 commit eaadbb6
Show file tree
Hide file tree
Showing 515 changed files with 17,667 additions and 15,835 deletions.
11 changes: 9 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ root = true
# we have detekt also checking for max line length. Disable the linter and use only one tool to check for max line length.

# See https://github.com/arturbosch/detekt
max_line_length=off
max_line_length = off

disabled_rules=import-ordering
# ktlint config

ktlint_standard_function-naming = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_value-argument-comment = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_value-parameter-comment = disabled
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.StatusChecker
* SPI for IndexManagement
*/
interface IndexManagementExtension {

/**
* List of action parsers that are supported by the extension, each of the action parser will parse the policy action into the defined action.
* The ActionParser provides the ability to parse the action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import java.time.Instant

abstract class Action(
val type: String,
val actionIndex: Int
val actionIndex: Int,
) : ToXContentObject, Writeable {

var configTimeout: ActionTimeout? = null
var configRetry: ActionRetry? = ActionRetry(DEFAULT_RETRIES)
var customAction: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.xcontent.XContentParser

abstract class ActionParser(var customAction: Boolean = false) {

/**
* The action type parser will parse
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ISMIndexMet
* else uses the default i.e cluster state
*/
interface IndexMetadataService {

/**
* Returns the index metadata needed for ISM
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement
import org.opensearch.cluster.ClusterState

interface StatusChecker {

/**
* checks and returns the status of the extension
*/
Expand All @@ -19,7 +18,8 @@ interface StatusChecker {

enum class Status(private val value: String) {
ENABLED("enabled"),
DISABLED("disabled");
DISABLED("disabled"),
;

override fun toString(): String {
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import java.time.Instant
import java.util.Locale

abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) {

var context: StepContext? = null
private set

Expand Down Expand Up @@ -56,7 +55,8 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) {
STARTING("starting"),
CONDITION_NOT_MET("condition_not_met"),
FAILED("failed"),
COMPLETED("completed");
COMPLETED("completed"),
;

override fun toString(): String {
return status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
package org.opensearch.indexmanagement.spi.indexstatemanagement

import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.settings.Settings
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.common.io.stream.Writeable
import org.opensearch.common.settings.Settings
import org.opensearch.monitor.jvm.JvmService
import java.util.Locale

abstract class Validate(
val settings: Settings,
val clusterService: ClusterService,
val jvmService: JvmService
val jvmService: JvmService,
) {

var validationStatus = ValidationStatus.PASSED
var validationMessage: String? = "Starting Validation"

Expand All @@ -27,7 +26,8 @@ abstract class Validate(
enum class ValidationStatus(val status: String) : Writeable {
PASSED("passed"),
RE_VALIDATING("re_validating"),
FAILED("failed");
FAILED("failed"),
;

override fun toString(): String {
return status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

package org.opensearch.indexmanagement.spi.indexstatemanagement.model

import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.XContentType
import org.opensearch.core.common.Strings
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.common.io.stream.Writeable
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.ToXContentFragment
import org.opensearch.core.xcontent.XContentBuilder
import org.opensearch.core.xcontent.XContentParser
import org.opensearch.common.xcontent.XContentType
import org.opensearch.core.xcontent.XContentParserUtils
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.NAME
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData.Companion.START_TIME
Expand All @@ -29,9 +29,8 @@ data class ActionMetaData(
val failed: Boolean,
val consumedRetries: Int,
val lastRetryTime: Long?,
val actionProperties: ActionProperties?
val actionProperties: ActionProperties?,
) : Writeable, ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeString(name)
out.writeOptionalLong(startTime)
Expand Down Expand Up @@ -89,7 +88,7 @@ data class ActionMetaData(
requireNotNull(failed) { "$FAILED is null" },
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" },
lastRetryTime,
actionProperties
actionProperties,
)
}

Expand Down Expand Up @@ -139,7 +138,7 @@ data class ActionMetaData(
requireNotNull(failed) { "$FAILED is null" },
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" },
lastRetryTime,
actionProperties
actionProperties,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import org.opensearch.core.xcontent.XContentParser.Token
import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken
import org.opensearch.indexmanagement.spi.indexstatemanagement.addObject

/** Properties that will persist across steps of a single Action. Will be stored in the [ActionMetaData]. */
// TODO: Create namespaces to group properties together

/** Properties that will persist across steps of a single Action. Will be stored in the [ActionMetaData]. */
data class ActionProperties(
val maxNumSegments: Int? = null,
val snapshotName: String? = null,
val rollupId: String? = null,
val hasRollupFailed: Boolean? = null,
val shrinkActionProperties: ShrinkActionProperties? = null,
val transformActionProperties: TransformActionProperties? = null
val transformActionProperties: TransformActionProperties? = null,
) : Writeable, ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeOptionalInt(maxNumSegments)
out.writeOptionalString(snapshotName)
Expand Down Expand Up @@ -94,6 +94,6 @@ data class ActionProperties(
MAX_NUM_SEGMENTS("max_num_segments"),
SNAPSHOT_NAME("snapshot_name"),
ROLLUP_ID("rollup_id"),
HAS_ROLLUP_FAILED("has_rollup_failed")
HAS_ROLLUP_FAILED("has_rollup_failed"),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package org.opensearch.indexmanagement.spi.indexstatemanagement.model

import org.apache.logging.log4j.LogManager
import org.opensearch.common.unit.TimeValue
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.common.io.stream.Writeable
import org.opensearch.common.unit.TimeValue
import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.ToXContentFragment
import org.opensearch.core.xcontent.XContentBuilder
Expand All @@ -23,10 +23,11 @@ import kotlin.math.pow
data class ActionRetry(
val count: Long,
val backoff: Backoff = Backoff.EXPONENTIAL,
val delay: TimeValue = TimeValue.timeValueMinutes(1)
val delay: TimeValue = TimeValue.timeValueMinutes(1),
) : ToXContentFragment, Writeable {

init { require(count >= 0) { "Count for ActionRetry must be a non-negative number" } }
init {
require(count >= 0) { "Count for ActionRetry must be a non-negative number" }
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder
Expand All @@ -42,7 +43,7 @@ data class ActionRetry(
constructor(sin: StreamInput) : this(
count = sin.readLong(),
backoff = sin.readEnum(Backoff::class.java),
delay = sin.readTimeValue()
delay = sin.readTimeValue(),
)

@Throws(IOException::class)
Expand Down Expand Up @@ -80,7 +81,7 @@ data class ActionRetry(
return ActionRetry(
count = requireNotNull(count) { "ActionRetry count is null" },
backoff = backoff,
delay = delay
delay = delay,
)
}
}
Expand All @@ -90,20 +91,21 @@ data class ActionRetry(
"exponential",
{ consumedRetries, timeValue ->
(2.0.pow(consumedRetries - 1)).toLong() * timeValue.millis
}
},
),
CONSTANT(
"constant",
{ _, timeValue ->
timeValue.millis
}
},
),
LINEAR(
"linear",
{ consumedRetries, timeValue ->
consumedRetries * timeValue.millis
}
);
},
),
;

private val logger = LogManager.getLogger(javaClass)

Expand All @@ -120,8 +122,9 @@ data class ActionRetry(

if (actionMetaData.consumedRetries > 0) {
if (actionMetaData.lastRetryTime != null) {
val remainingTime = getNextRetryTime(actionMetaData.consumedRetries, actionRetry.delay) -
(Instant.now().toEpochMilli() - actionMetaData.lastRetryTime)
val remainingTime =
getNextRetryTime(actionMetaData.consumedRetries, actionRetry.delay) -
(Instant.now().toEpochMilli() - actionMetaData.lastRetryTime)

return Pair(remainingTime > 0, remainingTime)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@

package org.opensearch.indexmanagement.spi.indexstatemanagement.model

import org.opensearch.common.unit.TimeValue
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.common.io.stream.Writeable
import org.opensearch.common.unit.TimeValue
import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.ToXContentFragment
import org.opensearch.core.xcontent.XContentBuilder
import org.opensearch.core.xcontent.XContentParser
import java.io.IOException

data class ActionTimeout(val timeout: TimeValue) : ToXContentFragment, Writeable {

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.field(TIMEOUT_FIELD, timeout.stringRep)
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
timeout = sin.readTimeValue()
timeout = sin.readTimeValue(),
)

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

package org.opensearch.indexmanagement.spi.indexstatemanagement.model

import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentHelper
import org.opensearch.common.xcontent.json.JsonXContent
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.common.io.stream.Writeable
import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.ToXContentFragment
import org.opensearch.core.xcontent.XContentBuilder
import org.opensearch.common.xcontent.XContentFactory
import org.opensearch.common.xcontent.XContentHelper
import org.opensearch.core.xcontent.XContentParser
import org.opensearch.core.xcontent.XContentParserUtils
import org.opensearch.common.xcontent.json.JsonXContent
import org.opensearch.index.seqno.SequenceNumbers
import org.opensearch.indexmanagement.spi.indexstatemanagement.addObject
import java.io.IOException
Expand All @@ -40,10 +40,9 @@ data class ManagedIndexMetaData(
val primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM,
val rolledOverIndexName: String? = null,
) : Writeable, ToXContentFragment {

@Suppress("ComplexMethod")
fun toMap(): Map<String, String> {
val resultMap = mutableMapOf<String, String> ()
val resultMap = mutableMapOf<String, String>()
resultMap[INDEX] = index
resultMap[INDEX_UUID] = indexUuid
resultMap[POLICY_ID] = policyID
Expand Down Expand Up @@ -199,11 +198,12 @@ data class ManagedIndexMetaData(
val step: StepMetaData? = si.readOptionalWriteable { StepMetaData.fromStreamInput(it) }
val retryInfo: PolicyRetryInfoMetaData? = si.readOptionalWriteable { PolicyRetryInfoMetaData.fromStreamInput(it) }

val info = if (si.readBoolean()) {
si.readMap()
} else {
null
}
val info =
if (si.readBoolean()) {
si.readMap()
} else {
null
}

return ManagedIndexMetaData(
index = requireNotNull(index) { "$INDEX is null" },
Expand All @@ -220,7 +220,7 @@ data class ManagedIndexMetaData(
actionMetaData = action,
stepMetaData = step,
policyRetryInfo = retryInfo,
info = info
info = info,
)
}

Expand All @@ -232,7 +232,7 @@ data class ManagedIndexMetaData(
xcp: XContentParser,
id: String = NO_ID,
seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO,
primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM
primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM,
): ManagedIndexMetaData {
var index: String? = null
var indexUuid: String? = null
Expand Down Expand Up @@ -314,7 +314,7 @@ data class ManagedIndexMetaData(
xcp: XContentParser,
id: String = NO_ID,
seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO,
primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM
primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM,
): ManagedIndexMetaData {
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp)
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp)
Expand All @@ -340,7 +340,7 @@ data class ManagedIndexMetaData(
actionMetaData = ActionMetaData.fromManagedIndexMetaDataMap(map),
stepMetaData = StepMetaData.fromManagedIndexMetaDataMap(map),
policyRetryInfo = PolicyRetryInfoMetaData.fromManagedIndexMetaDataMap(map),
info = map[INFO]?.let { XContentHelper.convertToMap(JsonXContent.jsonXContent, it, false) }
info = map[INFO]?.let { XContentHelper.convertToMap(JsonXContent.jsonXContent, it, false) },
)
}
}
Expand Down
Loading

0 comments on commit eaadbb6

Please sign in to comment.