Skip to content

Commit

Permalink
Fix all the compile warnings and detekt issues (#603)
Browse files Browse the repository at this point in the history
* Fix all the compile warnings and detekt issues

Signed-off-by: bowenlan-amzn <[email protected]>

* Fix time capture is 0

Signed-off-by: bowenlan-amzn <[email protected]>

Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Nov 21, 2022
1 parent c7df8df commit f4741c2
Show file tree
Hide file tree
Showing 66 changed files with 238 additions and 181 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/bwc-test-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Backward compatibility test workflow
on:
pull_request:
branches:
- "*"
push:
branches:
- "*"

jobs:
test:
# This job runs on Linux
runs-on: ubuntu-latest
steps:
# This step uses the setup-java Github action: https://github.com/actions/setup-java
- name: Set Up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
# index-management
- name: Checkout Branch
uses: actions/checkout@v2
- name: Run IM Backwards Compatibility Tests
run: |
echo "Running backwards compatibility tests..."
./gradlew bwcTestSuite
- name: Upload failed logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: logs
path: build/testclusters/indexmanagementBwcCluster*/logs/*
1 change: 1 addition & 0 deletions .github/workflows/create-documentation-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Create Documentation Issue
on:
pull_request:
types:
- closed
- labeled
env:
PR_NUMBER: ${{ github.event.number }}
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/dco.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: [ main ]

jobs:
linkchecker:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 1 addition & 20 deletions .github/workflows/multi-node-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ on:
- "*"

jobs:
build:
# Job name
name: Build Index Management
test:
# This job runs on Linux
runs-on: ubuntu-latest
steps:
Expand All @@ -31,20 +29,3 @@ jobs:
with:
name: logs
path: build/testclusters/integTest-*/logs/*
bwc:
name: Run Index Management Backwards Compatibility Tests
# This job runs on Linux
runs-on: ubuntu-latest
steps:
# This step uses the setup-java Github action: https://github.com/actions/setup-java
- name: Set Up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
# index-management
- name: Checkout Branch
uses: actions/checkout@v2
- name: Run IM Backwards Compatibility Tests
run: |
echo "Running backwards compatibility tests..."
./gradlew bwcTestSuite
2 changes: 0 additions & 2 deletions .github/workflows/test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:

jobs:
build:
# Job name
name: Build Index Management
env:
BUILD_ARGS: ${{ matrix.os_build_args }}
WORKING_DIR: ${{ matrix.working_directory }}.
Expand Down
15 changes: 13 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,24 @@ task ktlint(type: JavaExec, group: "verification") {
classpath = configurations.ktlint
args "src/**/*.kt", "spi/src/main/**/*.kt"
}

check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt", "spi/src/main/**/*.kt"
// https://github.com/pinterest/ktlint/issues/1391
jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED"
}

detekt {
config = files("detekt.yml")
buildUponDefaultConfig = true
}
// When writing detekt Gradle first finds the extension with this name,
// but with a string it should look for a task with that name instead
check.dependsOn "detekt"

configurations.testImplementation {
exclude module: "securemock"
Expand Down Expand Up @@ -656,7 +660,14 @@ run {
}
}

compileKotlin { kotlinOptions.freeCompilerArgs = ['-Xjsr305=strict'] }
compileKotlin {
kotlinOptions.freeCompilerArgs = ['-Xjsr305=strict']
kotlinOptions.allWarningsAsErrors = true
}

compileTestKotlin {
kotlinOptions.allWarningsAsErrors = true
}

apply from: 'build-tools/pkgbuild.gradle'

Expand Down
5 changes: 3 additions & 2 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODO: Remove this before initial release, only for developmental purposes
build:
maxIssues: 20
maxIssues: 0

exceptions:
TooGenericExceptionCaught:
Expand All @@ -14,6 +13,8 @@ style:
MaxLineLength:
maxLineLength: 150
excludes: ['**/test/**']
FunctionOnlyReturningConstant:
active: false

complexity:
LargeClass:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ class ManagedIndexCoordinator(
}
clusterService.clusterSettings.addSettingsUpdateConsumer(METADATA_SERVICE_STATUS) {
metadataServiceEnabled = it == 0
if (!metadataServiceEnabled) scheduledMoveMetadata?.cancel()
else initMoveMetadata()
if (!metadataServiceEnabled) {
logger.info("Canceling metadata moving job because of cluster setting update.")
scheduledMoveMetadata?.cancel()
} else initMoveMetadata()
}
clusterService.clusterSettings.addSettingsUpdateConsumer(TEMPLATE_MIGRATION_CONTROL) {
templateMigrationEnabled = it >= 0L
Expand Down Expand Up @@ -202,8 +204,8 @@ class ManagedIndexCoordinator(
// Instead of using a LocalNodeMasterListener to track cluster manager changes, this service will
// track them here to avoid conditions where cluster manager listener events run after other
// listeners that depend on what happened in the cluster manager listener
if (this.isClusterManager != event.localNodeMaster()) {
this.isClusterManager = event.localNodeMaster()
if (this.isClusterManager != event.localNodeClusterManager()) {
this.isClusterManager = event.localNodeClusterManager()
if (this.isClusterManager) {
onClusterManager()
} else {
Expand All @@ -215,7 +217,7 @@ class ManagedIndexCoordinator(

if (event.isNewCluster) return

if (!event.localNodeMaster()) return
if (!event.localNodeClusterManager()) return

if (!event.metadataChanged()) return

Expand Down Expand Up @@ -380,7 +382,7 @@ class ManagedIndexCoordinator(
}

/**
* Find a policy that has highest priority ism template with matching index pattern to the index and is created before index creation date. If
* Find a policy that has the highest priority ism template with matching index pattern to the index and is created before index creation date. If
* the policy has user, ensure that the user can manage the index if not find the one that can.
* */
private suspend fun findMatchingPolicy(indexName: String, creationDate: Long, policies: List<Policy>): Policy? {
Expand Down Expand Up @@ -422,7 +424,7 @@ class ManagedIndexCoordinator(
try {
val request = ManagedIndexRequest().indices(indexName)
withClosableContext(IndexManagementSecurityContext("ApplyPolicyOnIndexCreation", settings, threadPool.threadContext, policy.user)) {
val response: AcknowledgedResponse = client.suspendUntil { execute(ManagedIndexAction.INSTANCE, request, it) }
client.suspendUntil<Client, AcknowledgedResponse> { execute(ManagedIndexAction.INSTANCE, request, it) }
}
} catch (e: OpenSearchSecurityException) {
logger.debug("Skipping applying policy ${policy.id} on $indexName as the policy user is missing permissions", e)
Expand Down Expand Up @@ -473,13 +475,13 @@ class ManagedIndexCoordinator(
// If ISM is disabled return early
if (!isIndexStateManagementEnabled()) return

// Do not setup background sweep if we're not the elected cluster manager node
if (!clusterService.state().nodes().isLocalNodeElectedMaster) return
// Do not set up background sweep if we're not the elected cluster manager node
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager) return

// Cancel existing background sweep
scheduledFullSweep?.cancel()

// Setup an anti-entropy/self-healing background sweep, in case we fail to create a ManagedIndexConfig job
// Set up an anti-entropy/self-healing background sweep, in case we fail to create a ManagedIndexConfig job
val scheduledSweep = Runnable {
val elapsedTime = getFullSweepElapsedTime()

Expand All @@ -505,7 +507,7 @@ class ManagedIndexCoordinator(
fun initMoveMetadata() {
if (!metadataServiceEnabled) return
if (!isIndexStateManagementEnabled()) return
if (!clusterService.state().nodes().isLocalNodeElectedMaster) return
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager) return
scheduledMoveMetadata?.cancel()

if (metadataService.finishFlag) {
Expand Down Expand Up @@ -535,7 +537,7 @@ class ManagedIndexCoordinator(
fun initTemplateMigration(enableSetting: Long) {
if (!templateMigrationEnabled) return
if (!isIndexStateManagementEnabled()) return
if (!clusterService.state().nodes().isLocalNodeElectedMaster) return
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager) return
scheduledTemplateMigration?.cancel()

// if service has finished, re-enable it
Expand Down Expand Up @@ -657,8 +659,7 @@ class ManagedIndexCoordinator(
if (scrollIDsToClear.isNotEmpty()) {
val clearScrollRequest = ClearScrollRequest()
clearScrollRequest.scrollIds(scrollIDsToClear.toList())
val clearScrollResponse: ClearScrollResponse =
client.suspendUntil { execute(ClearScrollAction.INSTANCE, clearScrollRequest, it) }
client.suspendUntil<Client, ClearScrollResponse> { execute(ClearScrollAction.INSTANCE, clearScrollRequest, it) }
}
}
return managedIndexUuids
Expand Down Expand Up @@ -693,7 +694,7 @@ class ManagedIndexCoordinator(
val mRes: MultiGetResponse = client.suspendUntil { multiGet(mReq, it) }
val responses = mRes.responses
if (responses.first().isFailed) {
// config index may not initialised yet
// config index may not initialise yet
logger.error("get managed-index failed: ${responses.first().failure.failure}")
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ object ManagedIndexRunner :
// If this action is not allowed and the step to be executed is the first step in the action then we will fail
// as this action has been removed from the AllowList, but if its not the first step we will let it finish as it's already inflight
if (action?.isAllowed(allowList) == false && step != null && action.isFirstStep(step.name) && action.type != TransitionsAction.name) {
val info = mapOf("message" to "Attempted to execute action=${action?.type} which is not allowed.")
val info = mapOf("message" to "Attempted to execute action=${action.type} which is not allowed.")
val updated = updateManagedIndexMetaData(
managedIndexMetaData.copy(
policyRetryInfo = PolicyRetryInfoMetaData(true, 0), info = info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ class MetadataService(

override fun onResponse(response: ClusterUpdateSettingsResponse) {
if (!response.isAcknowledged) {
logger.error("Update template migration setting to $status is not acknowledged")
logger.error("Update metadata migration setting to $status is not acknowledged")
throw IndexManagementException.wrap(
Exception("Update template migration setting to $status is not acknowledged")
Exception("Update metadata migration setting to $status is not acknowledged")
)
} else {
logger.info("Successfully update template migration setting to $status")
logger.info("Successfully metadata template migration setting to $status")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class SweptManagedIndexConfig(
) {

companion object {
@Suppress("ComplexMethod", "UnusedPrivateMember")
@Suppress("ComplexMethod", "UNUSED_PARAMETER")
@JvmStatic
@Throws(IOException::class)
fun parse(xcp: XContentParser, id: String = NO_ID, seqNo: Long, primaryTerm: Long): SweptManagedIndexConfig {
Expand Down Expand Up @@ -60,11 +60,11 @@ data class SweptManagedIndexConfig(
}

return SweptManagedIndexConfig(
requireNotNull(index) { "SweptManagedIndexConfig index is null" },
index,
seqNo,
primaryTerm,
requireNotNull(uuid) { "SweptManagedIndexConfig uuid is null" },
requireNotNull(policyID) { "SweptManagedIndexConfig policy id is null" },
uuid,
policyID,
policy,
changePolicy
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.opensearch.ExceptionsHelper
import org.opensearch.OpenSearchException
import org.opensearch.action.support.WriteRequest
import org.opensearch.action.support.master.AcknowledgedResponse
import org.opensearch.client.Client
import org.opensearch.index.engine.VersionConflictEngineException
import org.opensearch.indexmanagement.indexstatemanagement.action.RollupAction
import org.opensearch.indexmanagement.opensearchapi.suspendUntil
Expand Down Expand Up @@ -85,7 +86,7 @@ class AttemptCreateRollupJobStep(private val action: RollupAction) : Step(name)
logger.info("Attempting to re-start the job $rollupId")
try {
val startRollupRequest = StartRollupRequest(rollupId)
val response: AcknowledgedResponse = client.suspendUntil { execute(StartRollupAction.INSTANCE, startRollupRequest, it) }
client.suspendUntil<Client, AcknowledgedResponse> { execute(StartRollupAction.INSTANCE, startRollupRequest, it) }
stepStatus = StepStatus.COMPLETED
info = mapOf("message" to getSuccessRestartMessage(rollupId, indexName))
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class TransportChangePolicyAction @Inject constructor(
)
)
// if there exists a transitionTo on the ManagedIndexMetaData then we will
// fail as they might not of meant to add a ChangePolicy when its on the next state
// fail as they might not of meant to add a ChangePolicy when it's on the next state
managedIndexMetadata?.transitionTo != null ->
failedIndices.add(
FailedIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ open class ExplainResponse : ActionResponse, ToXContentObject {
indexPolicyIDs = sin.readStringList(),
indexMetadatas = sin.readList { ManagedIndexMetaData.fromStreamInput(it) },
totalManagedIndices = sin.readInt(),
enabledState = sin.readMap() as Map<String, Boolean>,
enabledState = sin.readMap(StreamInput::readString, StreamInput::readBoolean),
policies = sin.readMap(StreamInput::readString, ::Policy),
validationResults = sin.readList { ValidationResult.fromStreamInput(it) }
)
Expand All @@ -68,7 +68,11 @@ open class ExplainResponse : ActionResponse, ToXContentObject {
out.writeStringCollection(indexPolicyIDs)
out.writeCollection(indexMetadatas)
out.writeInt(totalManagedIndices)
out.writeMap(enabledState)
out.writeMap(
enabledState,
{ _out, key -> _out.writeString(key) },
{ _out, enable -> _out.writeBoolean(enable) }
)
out.writeMap(
policies,
{ _out, key -> _out.writeString(key) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ fun checkMetadata(
val t2 = when (configIndexMetadata) {
is ManagedIndexMetaData -> configIndexMetadata.stepMetaData?.startTime
is Map<*, *> -> {
@Suppress("UNCHECKED_CAST")
val stepMetadata = configIndexMetadata["step"] as Map<String, Any>?
stepMetadata?.get("start_time")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ suspend fun removeClusterStateMetadatas(client: Client, logger: Logger, indices:
}

const val MASTER_TIMEOUT_DEPRECATED_MESSAGE =
"Parameter [master_timeout] is deprecated and will be removed in 3.0. To support inclusive language, please use [cluster_manager_timeout] instead."
"Parameter [master_timeout] is deprecated and will be removed in 3.0. " +
"To support inclusive language, please use [cluster_manager_timeout] instead."
const val DUPLICATE_PARAMETER_ERROR_MESSAGE =
"Please only use one of the request parameters [master_timeout, cluster_manager_timeout]."
fun parseClusterManagerTimeout(request: RestRequest, deprecationLogger: DeprecationLogger, restActionName: String): TimeValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ValidateDelete(
if (!deleteIndexExists(indexName) || !validIndex(indexName)) {
return this
}
val (rolloverTarget, isDataStream) = getRolloverTargetOrUpdateInfo(indexName)
val (rolloverTarget, _) = getRolloverTargetOrUpdateInfo(indexName)
if (rolloverTarget != null && !notWriteIndexForDataStream(rolloverTarget, indexName)) {
return this // can't be deleted if it's write index
}
Expand Down
Loading

0 comments on commit f4741c2

Please sign in to comment.