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 9, 2024
1 parent a5193a7 commit b967abc
Show file tree
Hide file tree
Showing 465 changed files with 3,778 additions and 3,525 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 @@ -19,7 +19,7 @@ import java.time.Instant

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

var configTimeout: ActionTimeout? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 @@ -56,7 +56,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,17 +6,17 @@
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
Expand All @@ -27,7 +27,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,7 +29,7 @@ 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) {
Expand Down Expand Up @@ -89,7 +89,7 @@ data class ActionMetaData(
requireNotNull(failed) { "$FAILED is null" },
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" },
lastRetryTime,
actionProperties
actionProperties,
)
}

Expand Down Expand Up @@ -139,7 +139,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 @@ -24,7 +24,7 @@ data class ActionProperties(
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) {
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,12 @@ 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 +44,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 +82,7 @@ data class ActionRetry(
return ActionRetry(
count = requireNotNull(count) { "ActionRetry count is null" },
backoff = backoff,
delay = delay
delay = delay,
)
}
}
Expand All @@ -90,20 +92,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

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
Expand All @@ -23,7 +23,7 @@ data class ActionTimeout(val timeout: TimeValue) : ToXContentFragment, Writeable

@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 Down Expand Up @@ -43,7 +43,7 @@ data class ManagedIndexMetaData(

@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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@

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.core.xcontent.XContentParserUtils
import org.opensearch.common.xcontent.XContentType
import java.io.ByteArrayInputStream
import java.nio.charset.StandardCharsets

data class PolicyRetryInfoMetaData(
val failed: Boolean,
val consumedRetries: Int
val consumedRetries: Int,
) : Writeable, ToXContentFragment {

override fun writeTo(out: StreamOutput) {
Expand All @@ -49,7 +49,7 @@ data class PolicyRetryInfoMetaData(

return PolicyRetryInfoMetaData(
requireNotNull(failed) { "$FAILED is null" },
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" }
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" },
)
}

Expand Down Expand Up @@ -82,7 +82,7 @@ data class PolicyRetryInfoMetaData(

return PolicyRetryInfoMetaData(
requireNotNull(failed) { "$FAILED is null" },
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" }
requireNotNull(consumedRetries) { "$CONSUMED_RETRIES is null" },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class ShrinkActionProperties(
val lockEpochSecond: Long,
val lockDurationSecond: Long,
// Used to store the original index allocation and write block setting to reapply after shrink
val originalIndexSettings: Map<String, String>
val originalIndexSettings: Map<String, String>,
) : Writeable, ToXContentFragment {

override fun writeTo(out: StreamOutput) {
Expand Down Expand Up @@ -63,7 +63,7 @@ data class ShrinkActionProperties(
val originalIndexSettings: Map<String, String> = si.readMap({ it.readString() }, { it.readString() })

return ShrinkActionProperties(
nodeName, targetIndexName, targetNumShards, lockPrimaryTerm, lockSeqNo, lockEpochSecond, lockDurationSecond, originalIndexSettings
nodeName, targetIndexName, targetNumShards, lockPrimaryTerm, lockSeqNo, lockEpochSecond, lockDurationSecond, originalIndexSettings,
)
}

Expand Down Expand Up @@ -102,7 +102,7 @@ data class ShrinkActionProperties(
requireNotNull(lockSeqNo),
requireNotNull(lockEpochSecond),
requireNotNull(lockDurationSecond),
requireNotNull(originalIndexSettings)
requireNotNull(originalIndexSettings),
)
}
}
Expand All @@ -115,6 +115,6 @@ data class ShrinkActionProperties(
LOCK_PRIMARY_TERM("lock_primary_term"),
LOCK_EPOCH_SECOND("lock_epoch_second"),
LOCK_DURATION_SECOND("lock_duration_second"),
ORIGINAL_INDEX_SETTINGS("original_index_settings")
ORIGINAL_INDEX_SETTINGS("original_index_settings"),
}
}
Loading

0 comments on commit b967abc

Please sign in to comment.