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 2b8991f commit 5f8891b
Show file tree
Hide file tree
Showing 515 changed files with 14,166 additions and 12,333 deletions.
13 changes: 10 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
root = true

[*.{kt,kts}]
ktlint_code_style = intellij_idea
# 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
ktlint_standard_max-line-length = disabled
ktlint_ignore_back_ticked_identifier = true

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

disabled_rules=import-ordering
3 changes: 2 additions & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ style:
ForbiddenComment:
active: false
MaxLineLength:
maxLineLength: 150
maxLineLength: 160
excludes: ['**/test/**']
FunctionOnlyReturningConstant:
active: false
Expand All @@ -20,6 +20,7 @@ complexity:
LargeClass:
excludes: ['**/test/**']
LongMethod:
threshold: 80
excludes: ['**/test/**']
LongParameterList:
excludes: ['**/test/**']
Expand Down
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
Loading

0 comments on commit 5f8891b

Please sign in to comment.