Skip to content

Commit

Permalink
[Backport 2.x] bump ktlint 1.1.0 to 1.5.0 (#1338)
Browse files Browse the repository at this point in the history
* bump ktlint from 1.1.0 to 1.5.0 (#1336)

Signed-off-by: Shivansh Arora <[email protected]>

* appease ktlint

Signed-off-by: Shivansh Arora <[email protected]>

.

Signed-off-by: Shivansh Arora <[email protected]>

---------

Signed-off-by: Shivansh Arora <[email protected]>
  • Loading branch information
shiv0408 authored Jan 19, 2025
1 parent a4a3188 commit 49da816
Show file tree
Hide file tree
Showing 237 changed files with 1,946 additions and 2,606 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ dependencies {
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "org.mockito:mockito-core:${versions.mockito}"

add("ktlint", "com.pinterest.ktlint:ktlint-cli:1.1.0") {
add("ktlint", "com.pinterest.ktlint:ktlint-cli:1.5.0") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ interface IndexManagementExtension {
* should represent if the extension is enabled or disabled, and should not represent extension health or the availability of some extension
* dependency.
*/
fun statusChecker(): StatusChecker {
return DefaultStatusChecker()
}
fun statusChecker(): StatusChecker = DefaultStatusChecker()

/**
* Name of the extension
Expand All @@ -41,17 +39,13 @@ interface IndexManagementExtension {
* indices provide the metadata service that can provide the index metadata for these indices. An extension need to label the metadata service
* with a type string which is used to distinguish indices in IndexManagement plugin
*/
fun getIndexMetadataService(): Map<String, IndexMetadataService> {
return mapOf()
}
fun getIndexMetadataService(): Map<String, IndexMetadataService> = mapOf()

/**
* Caution: Experimental and can be removed in future
*
* If extension wants IndexManagement to determine cluster state indices UUID based on custom index setting if
* present of cluster state override this method.
*/
fun overrideClusterStateIndexUuidSetting(): String? {
return null
}
fun overrideClusterStateIndexUuidSetting(): String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import java.time.Instant
abstract class Action(
val type: String,
val actionIndex: Int,
) : ToXContentObject, Writeable {
) : ToXContentObject,
Writeable {

var configTimeout: ActionTimeout? = null
var configRetry: ActionRetry? = ActionRetry(DEFAULT_RETRIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ interface StatusChecker {
/**
* checks and returns the status of the extension
*/
fun check(clusterState: ClusterState): Status {
return Status.ENABLED
}
fun check(clusterState: ClusterState): Status = Status.ENABLED
}

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

override fun toString(): String {
return value
}
override fun toString(): String = value
}

class DefaultStatusChecker : StatusChecker
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) {

abstract fun isIdempotent(): Boolean

final fun getStepStartTime(metadata: ManagedIndexMetaData): Instant {
return when {
metadata.stepMetaData == null -> Instant.now()
metadata.stepMetaData.name != this.name -> Instant.now()
// The managed index metadata is a historical snapshot of the metadata and refers to what has happened from the previous
// execution, so if we ever see it as COMPLETED it means we are always going to be in a new step, this specifically
// helps with the Transition -> Transition (empty state) sequence which the above do not capture
metadata.stepMetaData.stepStatus == StepStatus.COMPLETED -> Instant.now()
else -> Instant.ofEpochMilli(metadata.stepMetaData.startTime)
}
final fun getStepStartTime(metadata: ManagedIndexMetaData): Instant = when {
metadata.stepMetaData == null -> Instant.now()
metadata.stepMetaData.name != this.name -> Instant.now()
// The managed index metadata is a historical snapshot of the metadata and refers to what has happened from the previous
// execution, so if we ever see it as COMPLETED it means we are always going to be in a new step, this specifically
// helps with the Transition -> Transition (empty state) sequence which the above do not capture
metadata.stepMetaData.stepStatus == StepStatus.COMPLETED -> Instant.now()
else -> Instant.ofEpochMilli(metadata.stepMetaData.startTime)
}

final fun getStartingStepMetaData(metadata: ManagedIndexMetaData): StepMetaData = StepMetaData(name, getStepStartTime(metadata).toEpochMilli(), StepStatus.STARTING)
Expand All @@ -60,18 +58,14 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) {
TIMED_OUT("timed_out"),
;

override fun toString(): String {
return status
}
override fun toString(): String = status

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

companion object {
fun read(streamInput: StreamInput): StepStatus {
return valueOf(streamInput.readString().uppercase(Locale.ROOT))
}
fun read(streamInput: StreamInput): StepStatus = valueOf(streamInput.readString().uppercase(Locale.ROOT))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ abstract class Validate(
FAILED("failed"),
;

override fun toString(): String {
return status
}
override fun toString(): String = status

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

companion object {
fun read(streamInput: StreamInput): ValidationStatus {
return valueOf(streamInput.readString().uppercase(Locale.ROOT))
}
fun read(streamInput: StreamInput): ValidationStatus = valueOf(streamInput.readString().uppercase(Locale.ROOT))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ data class ActionMetaData(
val consumedRetries: Int,
val lastRetryTime: Long?,
val actionProperties: ActionProperties?,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeString(name)
Expand Down Expand Up @@ -61,9 +62,7 @@ data class ActionMetaData(
return builder
}

fun getMapValueString(): String {
return Strings.toString(XContentType.JSON, this)
}
fun getMapValueString(): String = Strings.toString(XContentType.JSON, this)

companion object {
const val ACTION = "action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ data class ActionProperties(
val hasRollupFailed: Boolean? = null,
val shrinkActionProperties: ShrinkActionProperties? = null,
val transformActionProperties: TransformActionProperties? = null,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeOptionalInt(maxNumSegments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ data class ActionRetry(
val count: Long,
val backoff: Backoff = Backoff.EXPONENTIAL,
val delay: TimeValue = TimeValue.timeValueMinutes(1),
) : ToXContentFragment, Writeable {
) : ToXContentFragment,
Writeable {

init {
require(count >= 0) { "Count for ActionRetry must be a non-negative number" }
Expand Down Expand Up @@ -110,9 +111,7 @@ data class ActionRetry(

private val logger = LogManager.getLogger(javaClass)

override fun toString(): String {
return type
}
override fun toString(): String = type

@Suppress("ReturnCount")
fun shouldBackoff(actionMetaData: ActionMetaData?, actionRetry: ActionRetry?): Pair<Boolean, Long?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import org.opensearch.core.xcontent.XContentBuilder
import org.opensearch.core.xcontent.XContentParser
import java.io.IOException

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

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

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ data class ManagedIndexMetaData(
val seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO,
val primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM,
val rolledOverIndexName: String? = null,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

@Suppress("ComplexMethod")
fun toMap(): Map<String, String> {
Expand Down Expand Up @@ -324,24 +325,22 @@ data class ManagedIndexMetaData(
return managedIndexMetaData
}

fun fromMap(map: Map<String, String?>): ManagedIndexMetaData {
return ManagedIndexMetaData(
index = requireNotNull(map[INDEX]) { "$INDEX is null" },
indexUuid = requireNotNull(map[INDEX_UUID]) { "$INDEX_UUID is null" },
policyID = requireNotNull(map[POLICY_ID]) { "$POLICY_ID is null" },
policySeqNo = map[POLICY_SEQ_NO]?.toLong(),
policyPrimaryTerm = map[POLICY_PRIMARY_TERM]?.toLong(),
policyCompleted = map[POLICY_COMPLETED]?.toBoolean(),
rolledOver = map[ROLLED_OVER]?.toBoolean(),
rolledOverIndexName = map[ROLLED_OVER_INDEX_NAME],
indexCreationDate = map[INDEX_CREATION_DATE]?.toLong(),
transitionTo = map[TRANSITION_TO],
stateMetaData = StateMetaData.fromManagedIndexMetaDataMap(map),
actionMetaData = ActionMetaData.fromManagedIndexMetaDataMap(map),
stepMetaData = StepMetaData.fromManagedIndexMetaDataMap(map),
policyRetryInfo = PolicyRetryInfoMetaData.fromManagedIndexMetaDataMap(map),
info = map[INFO]?.let { XContentHelper.convertToMap(JsonXContent.jsonXContent, it, false) },
)
}
fun fromMap(map: Map<String, String?>): ManagedIndexMetaData = ManagedIndexMetaData(
index = requireNotNull(map[INDEX]) { "$INDEX is null" },
indexUuid = requireNotNull(map[INDEX_UUID]) { "$INDEX_UUID is null" },
policyID = requireNotNull(map[POLICY_ID]) { "$POLICY_ID is null" },
policySeqNo = map[POLICY_SEQ_NO]?.toLong(),
policyPrimaryTerm = map[POLICY_PRIMARY_TERM]?.toLong(),
policyCompleted = map[POLICY_COMPLETED]?.toBoolean(),
rolledOver = map[ROLLED_OVER]?.toBoolean(),
rolledOverIndexName = map[ROLLED_OVER_INDEX_NAME],
indexCreationDate = map[INDEX_CREATION_DATE]?.toLong(),
transitionTo = map[TRANSITION_TO],
stateMetaData = StateMetaData.fromManagedIndexMetaDataMap(map),
actionMetaData = ActionMetaData.fromManagedIndexMetaDataMap(map),
stepMetaData = StepMetaData.fromManagedIndexMetaDataMap(map),
policyRetryInfo = PolicyRetryInfoMetaData.fromManagedIndexMetaDataMap(map),
info = map[INFO]?.let { XContentHelper.convertToMap(JsonXContent.jsonXContent, it, false) },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ import java.nio.charset.StandardCharsets
data class PolicyRetryInfoMetaData(
val failed: Boolean,
val consumedRetries: Int,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeBoolean(failed)
out.writeInt(consumedRetries)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder
.field(FAILED, failed)
.field(CONSUMED_RETRIES, consumedRetries)
}
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder = builder
.field(FAILED, failed)
.field(CONSUMED_RETRIES, consumedRetries)

fun getMapValueString(): String = Strings.toString(XContentType.JSON, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ data class ShrinkActionProperties(
val lockDurationSecond: Long,
// Used to store the original index allocation and write block setting to reapply after shrink
val originalIndexSettings: Map<String, String>,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeString(nodeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ import java.nio.charset.StandardCharsets
data class StateMetaData(
val name: String,
val startTime: Long,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeString(name)
out.writeLong(startTime)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder
.field(NAME, name)
.field(START_TIME, startTime)
}
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder = builder
.field(NAME, name)
.field(START_TIME, startTime)

fun getMapValueString(): String = Strings.toString(XContentType.JSON, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ class StepContext(
val settings: Settings,
val lockService: LockService,
) {
fun getUpdatedContext(metadata: ManagedIndexMetaData): StepContext {
return StepContext(metadata, this.clusterService, this.client, this.threadContext, this.user, this.scriptService, this.settings, this.lockService)
}
fun getUpdatedContext(metadata: ManagedIndexMetaData): StepContext = StepContext(metadata, this.clusterService, this.client, this.threadContext, this.user, this.scriptService, this.settings, this.lockService)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ data class StepMetaData(
val name: String,
val startTime: Long,
val stepStatus: Step.StepStatus,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeString(name)
Expand All @@ -45,9 +46,7 @@ data class StepMetaData(
return builder
}

fun getMapValueString(): String {
return Strings.toString(XContentType.JSON, this)
}
fun getMapValueString(): String = Strings.toString(XContentType.JSON, this)

companion object {
const val STEP = "step"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken

data class TransformActionProperties(
val transformId: String?,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeOptionalString(transformId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import java.util.Locale
data class ValidationResult(
val validationMessage: String,
val validationStatus: Validate.ValidationStatus,
) : Writeable, ToXContentFragment {
) : Writeable,
ToXContentFragment {

override fun writeTo(out: StreamOutput) {
out.writeString(validationMessage)
Expand All @@ -39,9 +40,7 @@ data class ValidationResult(
return builder
}

fun getMapValueString(): String {
return Strings.toString(XContentType.JSON, this)
}
fun getMapValueString(): String = Strings.toString(XContentType.JSON, this)

companion object {
const val VALIDATE = "validate"
Expand Down
Loading

0 comments on commit 49da816

Please sign in to comment.