From b2635073981fca913cdc849765289a4ad9b3f32f Mon Sep 17 00:00:00 2001 From: Drew Baugher <46505179+dbbaughe@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:26:42 -0800 Subject: [PATCH 1/3] Updates workflows to upload logs if it fails --- .github/workflows/multi-node-test-workflow.yml | 6 ++++++ .github/workflows/test-and-build-workflow.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/multi-node-test-workflow.yml b/.github/workflows/multi-node-test-workflow.yml index 70cbeca5f..d0fbd62e5 100644 --- a/.github/workflows/multi-node-test-workflow.yml +++ b/.github/workflows/multi-node-test-workflow.yml @@ -25,3 +25,9 @@ jobs: java-version: 14 - name: Run integration tests with multi node config run: ./gradlew integTest -PnumNodes=3 + - name: Upload failed logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: logs + path: build/testclusters/integTest-*/logs/* diff --git a/.github/workflows/test-and-build-workflow.yml b/.github/workflows/test-and-build-workflow.yml index 25534b781..f933f6354 100644 --- a/.github/workflows/test-and-build-workflow.yml +++ b/.github/workflows/test-and-build-workflow.yml @@ -27,6 +27,12 @@ jobs: java-version: 14 - name: Build with Gradle run: ./gradlew build + - name: Upload failed logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: logs + path: build/testclusters/integTest-*/logs/* - name: Create Artifact Path run: | mkdir -p index-management-artifacts From 678813757d893f863dfdfc907e0b230b22a9166f Mon Sep 17 00:00:00 2001 From: Drew Baugher <46505179+dbbaughe@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:32:16 -0800 Subject: [PATCH 2/3] Refactors elastic extensions to higher level --- .../indexmanagement/IndexManagementIndices.kt | 2 +- .../elasticapi/ElasticExtensions.kt | 126 ++++++++++++++++-- .../IndexStateManagementHistory.kt | 2 +- .../ManagedIndexCoordinator.kt | 4 +- .../ManagedIndexRunner.kt | 6 +- .../elasticapi/ElasticExtensions.kt | 102 -------------- .../model/destination/Destination.kt | 2 +- .../step/allocation/AttemptAllocationStep.kt | 2 +- .../step/close/AttemptCloseStep.kt | 2 +- .../step/delete/AttemptDeleteStep.kt | 2 +- .../forcemerge/AttemptCallForceMergeStep.kt | 4 +- .../step/forcemerge/AttemptSetReadOnlyStep.kt | 2 +- .../step/forcemerge/WaitForForceMergeStep.kt | 4 +- .../AttemptSetIndexPriorityStep.kt | 2 +- .../notification/AttemptNotificationStep.kt | 2 +- .../step/open/AttemptOpenStep.kt | 2 +- .../step/readonly/SetReadOnlyStep.kt | 2 +- .../step/readwrite/SetReadWriteStep.kt | 2 +- .../AttemptSetReplicaCountStep.kt | 2 +- .../step/rollover/AttemptRolloverStep.kt | 4 +- .../step/snapshot/AttemptSnapshotStep.kt | 2 +- .../step/snapshot/WaitForSnapshotStep.kt | 2 +- .../step/transition/AttemptTransitionStep.kt | 4 +- 23 files changed, 144 insertions(+), 140 deletions(-) diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/IndexManagementIndices.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/IndexManagementIndices.kt index 6aed96434..4f8610342 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/IndexManagementIndices.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/IndexManagementIndices.kt @@ -16,7 +16,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.util.IndexUtils import com.amazon.opendistroforelasticsearch.indexmanagement.util.OpenForTesting import com.amazon.opendistroforelasticsearch.indexmanagement.util._DOC diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/elasticapi/ElasticExtensions.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/elasticapi/ElasticExtensions.kt index c12b738ea..967c8e835 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/elasticapi/ElasticExtensions.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/elasticapi/ElasticExtensions.kt @@ -18,24 +18,43 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi import com.amazon.opendistroforelasticsearch.indexmanagement.util.NO_ID +import com.amazon.opendistroforelasticsearch.jobscheduler.spi.utils.LockService +import kotlinx.coroutines.delay +import org.apache.logging.log4j.Logger +import org.elasticsearch.ElasticsearchException +import org.elasticsearch.ExceptionsHelper +import org.elasticsearch.action.ActionListener +import org.elasticsearch.action.bulk.BackoffPolicy +import org.elasticsearch.action.support.DefaultShardOperationFailedException +import org.elasticsearch.client.ElasticsearchClient import org.elasticsearch.common.bytes.BytesReference +import org.elasticsearch.common.unit.TimeValue +import org.elasticsearch.common.xcontent.ToXContent import org.elasticsearch.common.xcontent.XContentBuilder +import org.elasticsearch.common.xcontent.XContentHelper import org.elasticsearch.common.xcontent.XContentParser +import org.elasticsearch.common.xcontent.XContentParser.Token import org.elasticsearch.common.xcontent.XContentParserUtils +import org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken +import org.elasticsearch.common.xcontent.XContentType import org.elasticsearch.index.seqno.SequenceNumbers +import org.elasticsearch.rest.RestStatus +import org.elasticsearch.transport.RemoteTransportException import java.io.IOException import java.time.Instant +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine -fun XContentBuilder.optionalTimeField(name: String, instant: Instant?): XContentBuilder { - if (instant == null) { - return nullField(name) - } - return this.timeField(name, name, instant.toEpochMilli()) +/** Convert an object to maps and lists representation */ +fun ToXContent.convertToMap(): Map { + val bytesReference = XContentHelper.toXContent(this, XContentType.JSON, false) + return XContentHelper.convertToMap(bytesReference, false, XContentType.JSON).v2() } fun XContentParser.instant(): Instant? { return when { - currentToken() == XContentParser.Token.VALUE_NULL -> null + currentToken() == Token.VALUE_NULL -> null currentToken().isValue -> Instant.ofEpochMilli(longValue()) else -> { XContentParserUtils.throwUnknownToken(currentToken(), tokenLocation) @@ -44,11 +63,98 @@ fun XContentParser.instant(): Instant? { } } +fun XContentBuilder.optionalTimeField(name: String, instant: Instant?): XContentBuilder { + if (instant == null) { + return nullField(name) + } + return this.timeField(name, name, instant.toEpochMilli()) +} + +/** + * Retries the given [block] of code as specified by the receiver [BackoffPolicy], + * if [block] throws an [ElasticsearchException] that is retriable (502, 503, 504). + * + * If all retries fail the final exception will be rethrown. Exceptions caught during intermediate retries are + * logged as warnings to [logger]. Similar to [org.elasticsearch.action.bulk.Retry], except this retries on + * 502, 503, 504 error codes as well as 429. + * + * @param logger - logger used to log intermediate failures + * @param retryOn - any additional [RestStatus] values that should be retried + * @param block - the block of code to retry. This should be a suspend function. + */ +suspend fun BackoffPolicy.retry( + logger: Logger, + retryOn: List = emptyList(), + block: suspend (backoff: TimeValue) -> T +): T { + val iter = iterator() + var backoff: TimeValue = TimeValue.ZERO + do { + try { + return block(backoff) + } catch (e: ElasticsearchException) { + if (iter.hasNext() && (e.isRetryable() || retryOn.contains(e.status()))) { + backoff = iter.next() + logger.warn("Operation failed. Retrying in $backoff.", e) + delay(backoff.millis) + } else { + throw e + } + } + } while (true) +} + +/** + * Retries on 502, 503 and 504 per elastic client's behavior: https://github.com/elastic/elasticsearch-net/issues/2061 + * 429 must be retried manually as it's not clear if it's ok to retry for requests other than Bulk requests. + */ +fun ElasticsearchException.isRetryable(): Boolean { + return (status() in listOf(RestStatus.BAD_GATEWAY, RestStatus.SERVICE_UNAVAILABLE, RestStatus.GATEWAY_TIMEOUT)) +} + /** * Extension function for ES 6.3 and above that duplicates the ES 6.2 XContentBuilder.string() method. */ fun XContentBuilder.string(): String = BytesReference.bytes(this).utf8ToString() +/** + * Converts [ElasticsearchClient] methods that take a callback into a kotlin suspending function. + * + * @param block - a block of code that is passed an [ActionListener] that should be passed to the ES client API. + */ +suspend fun C.suspendUntil(block: C.(ActionListener) -> Unit): T = + suspendCoroutine { cont -> + block(object : ActionListener { + override fun onResponse(response: T) = cont.resume(response) + + override fun onFailure(e: Exception) = cont.resumeWithException(e) + }) + } + +/** + * Converts [LockService] methods that take a callback into a kotlin suspending function. + * + * @param block - a block of code that is passed an [ActionListener] that should be passed to the LockService API. + */ +suspend fun LockService.suspendUntil(block: LockService.(ActionListener) -> Unit): T = + suspendCoroutine { cont -> + block(object : ActionListener { + override fun onResponse(response: T) = cont.resume(response) + + override fun onFailure(e: Exception) = cont.resumeWithException(e) + }) + } + +fun Throwable.findRemoteTransportException(): RemoteTransportException? { + if (this is RemoteTransportException) return this + return this.cause?.findRemoteTransportException() +} + +fun DefaultShardOperationFailedException.getUsefulCauseString(): String { + val rte = this.cause?.findRemoteTransportException() + return if (rte == null) this.toString() else ExceptionsHelper.unwrapCause(rte).toString() +} + @JvmOverloads @Throws(IOException::class) fun XContentParser.parseWithType( @@ -57,10 +163,10 @@ fun XContentParser.parseWithType( primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, parse: (xcp: XContentParser, id: String, seqNo: Long, primaryTerm: Long) -> T ): T { - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, nextToken(), this::getTokenLocation) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, nextToken(), this::getTokenLocation) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, nextToken(), this::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, nextToken(), this::getTokenLocation) + ensureExpectedToken(Token.FIELD_NAME, nextToken(), this::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, nextToken(), this::getTokenLocation) val parsed = parse(this, id, seqNo, primaryTerm) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, this.nextToken(), this::getTokenLocation) + ensureExpectedToken(Token.END_OBJECT, this.nextToken(), this::getTokenLocation) return parsed } diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt index 19e8ad651..66fa1f4f9 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt @@ -17,7 +17,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanageme import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementIndices import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.Step diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt index 8898974b0..5c7eba561 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt @@ -20,11 +20,11 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementIndi import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getClusterStateManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getPolicyID -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.retry +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.retry import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.shouldCreateManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.shouldDeleteManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.shouldDeleteManagedIndexMetaData -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.coordinator.ClusterStateManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt index 1776ce13c..1fdb326d3 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt @@ -17,14 +17,14 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanageme import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.action.Action -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.convertToMap +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.convertToMap import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata.UpdateManagedIndexMetaDataAction import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata.UpdateManagedIndexMetaDataRequest import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getPolicyID -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.retry +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.retry import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.string -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Policy diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/elasticapi/ElasticExtensions.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/elasticapi/ElasticExtensions.kt index 1b5539f83..ab2d32b28 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/elasticapi/ElasticExtensions.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/elasticapi/ElasticExtensions.kt @@ -20,99 +20,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanageme import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.coordinator.ClusterStateManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.utils.LockService -import kotlinx.coroutines.delay -import org.apache.logging.log4j.Logger -import org.elasticsearch.ElasticsearchException -import org.elasticsearch.ExceptionsHelper -import org.elasticsearch.action.ActionListener -import org.elasticsearch.action.bulk.BackoffPolicy -import org.elasticsearch.action.support.DefaultShardOperationFailedException -import org.elasticsearch.client.ElasticsearchClient import org.elasticsearch.cluster.metadata.IndexMetadata -import org.elasticsearch.common.xcontent.ToXContent -import org.elasticsearch.common.xcontent.XContentHelper -import org.elasticsearch.common.xcontent.XContentType -import org.elasticsearch.rest.RestStatus -import org.elasticsearch.transport.RemoteTransportException -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException -import kotlin.coroutines.suspendCoroutine - -/** Convert an object to maps and lists representation */ -fun ToXContent.convertToMap(): Map { - val bytesReference = XContentHelper.toXContent(this, XContentType.JSON, false) - return XContentHelper.convertToMap(bytesReference, false, XContentType.JSON).v2() -} - -/** - * Retries the given [block] of code as specified by the receiver [BackoffPolicy], - * if [block] throws an [ElasticsearchException] that is retriable (502, 503, 504). - * - * If all retries fail the final exception will be rethrown. Exceptions caught during intermediate retries are - * logged as warnings to [logger]. Similar to [org.elasticsearch.action.bulk.Retry], except this retries on - * 502, 503, 504 error codes as well as 429. - * - * @param logger - logger used to log intermediate failures - * @param retryOn - any additional [RestStatus] values that should be retried - * @param block - the block of code to retry. This should be a suspend function. - */ -suspend fun BackoffPolicy.retry( - logger: Logger, - retryOn: List = emptyList(), - block: suspend () -> T -): T { - val iter = iterator() - do { - try { - return block() - } catch (e: ElasticsearchException) { - if (iter.hasNext() && (e.isRetryable() || retryOn.contains(e.status()))) { - val backoff = iter.next() - logger.warn("Operation failed. Retrying in $backoff.", e) - delay(backoff.millis) - } else { - throw e - } - } - } while (true) -} - -/** - * Retries on 502, 503 and 504 per elastic client's behavior: https://github.com/elastic/elasticsearch-net/issues/2061 - * 429 must be retried manually as it's not clear if it's ok to retry for requests other than Bulk requests. - */ -fun ElasticsearchException.isRetryable(): Boolean { - return (status() in listOf(RestStatus.BAD_GATEWAY, RestStatus.SERVICE_UNAVAILABLE, RestStatus.GATEWAY_TIMEOUT)) -} - -/** - * Converts [ElasticsearchClient] methods that take a callback into a kotlin suspending function. - * - * @param block - a block of code that is passed an [ActionListener] that should be passed to the ES client API. - */ -suspend fun C.suspendUntil(block: C.(ActionListener) -> Unit): T = - suspendCoroutine { cont -> - block(object : ActionListener { - override fun onResponse(response: T) = cont.resume(response) - - override fun onFailure(e: Exception) = cont.resumeWithException(e) - }) - } - -/** - * Converts [LockService] methods that take a callback into a kotlin suspending function. - * - * @param block - a block of code that is passed an [ActionListener] that should be passed to the LockService API. - */ -suspend fun LockService.suspendUntil(block: LockService.(ActionListener) -> Unit): T = - suspendCoroutine { cont -> - block(object : ActionListener { - override fun onResponse(response: T) = cont.resume(response) - - override fun onFailure(e: Exception) = cont.resumeWithException(e) - }) - } /** * Compares current and previous IndexMetaData to determine if we should create [ManagedIndexConfig]. @@ -190,13 +98,3 @@ fun IndexMetadata.getManagedIndexMetaData(): ManagedIndexMetaData? { } return null } - -fun Throwable.findRemoteTransportException(): RemoteTransportException? { - if (this is RemoteTransportException) return this - return this.cause?.findRemoteTransportException() -} - -fun DefaultShardOperationFailedException.getUsefulCauseString(): String { - val rte = this.cause?.findRemoteTransportException() - return if (rte == null) this.toString() else ExceptionsHelper.unwrapCause(rte).toString() -} diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt index 76b9eab7c..342051915 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/destination/Destination.kt @@ -21,7 +21,7 @@ import com.amazon.opendistroforelasticsearch.alerting.destination.message.ChimeM import com.amazon.opendistroforelasticsearch.alerting.destination.message.CustomWebhookMessage import com.amazon.opendistroforelasticsearch.alerting.destination.message.SlackMessage import com.amazon.opendistroforelasticsearch.alerting.destination.response.DestinationResponse -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.convertToMap +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.convertToMap import org.apache.logging.log4j.LogManager import org.elasticsearch.common.io.stream.StreamInput import org.elasticsearch.common.io.stream.StreamOutput diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt index 3be701da1..c6292ee57 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.allocation -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.AllocationActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt index 9bd345d57..44047a132 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.close -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.CloseActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt index cfdcf1aad..6b1c66a5f 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.delete -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.DeleteActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt index 851893d0f..52622cee7 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt @@ -15,8 +15,8 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.forcemerge -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getUsefulCauseString -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.getUsefulCauseString +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ForceMergeActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.ActionProperties diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt index 6852fc500..8b475b053 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.forcemerge -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ForceMergeActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt index 8a54decf0..7a34136ed 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt @@ -15,8 +15,8 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.forcemerge -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getUsefulCauseString -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.getUsefulCauseString +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ForceMergeActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.ActionProperties diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt index 0b81f4c3f..adb573cf3 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.indexpriority -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.IndexPriorityActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt index 526c4a09d..be6976965 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.notification -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.convertToMap +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.convertToMap import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.NotificationActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt index de565a9cd..b454d88b3 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.open -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.OpenActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt index 4d44a9f2d..6d23fc8f1 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.readonly -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ReadOnlyActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt index 7fb2a567b..990f9d287 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.readwrite -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ReadWriteActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptSetReplicaCountStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptSetReplicaCountStep.kt index 5f06afe32..e897baafa 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptSetReplicaCountStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptSetReplicaCountStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.replicacount -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ReplicaCountActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt index 1bb996eb2..562bc97f9 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt @@ -16,8 +16,8 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.rollover import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getRolloverAlias -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getUsefulCauseString -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.getUsefulCauseString +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.RolloverActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt index 64aa7af55..2c54b34c4 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.snapshot -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.SnapshotActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.ActionProperties diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt index 55453694b..895f401ed 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.snapshot -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.SnapshotActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.ActionProperties diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt index 208b70bc1..0b959e839 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt @@ -15,8 +15,8 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.transition -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getUsefulCauseString -import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.suspendUntil +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.getUsefulCauseString +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.suspendUntil import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.TransitionsActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.StepMetaData From c733b70d6ef9f96d12dc2a44097704156a67afbd Mon Sep 17 00:00:00 2001 From: Drew Baugher <46505179+dbbaughe@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:41:27 -0700 Subject: [PATCH 3/3] Cleans up parsing with type helper and tests --- .../ManagedIndexCoordinator.kt | 6 ++++-- .../indexstatemanagement/ManagedIndexRunner.kt | 5 +++-- .../model/ManagedIndexConfig.kt | 17 ----------------- .../indexstatemanagement/model/Policy.kt | 17 ----------------- .../coordinator/SweptManagedIndexConfig.kt | 14 ++------------ .../resthandler/RestIndexPolicyAction.kt | 3 ++- .../changepolicy/TransportChangePolicyAction.kt | 7 +++++-- .../getpolicy/TransportGetPolicyAction.kt | 5 +++-- .../IndexStateManagementRestTestCase.kt | 5 +++-- .../ManagedIndexConfigTests.kt | 13 +++++++------ .../action/NotificationActionIT.kt | 17 ++++++++++++----- .../indexstatemanagement/model/XContentTests.kt | 9 +++++---- .../util/ManagedIndexUtilsTests.kt | 5 +++-- 13 files changed, 49 insertions(+), 74 deletions(-) diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt index 5c7eba561..e94fb82af 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt @@ -17,6 +17,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanageme import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementIndices +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getClusterStateManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getPolicyID @@ -46,6 +47,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util.isFailed import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util.isPolicyCompleted import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util.updateEnableManagedIndexRequest +import com.amazon.opendistroforelasticsearch.indexmanagement.util.NO_ID import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -354,8 +356,8 @@ class ManagedIndexCoordinator( val managedIndexSearchRequest = getSweptManagedIndexSearchRequest() val response: SearchResponse = client.suspendUntil { search(managedIndexSearchRequest, it) } return response.hits.map { - it.id to SweptManagedIndexConfig.parseWithType(contentParser(it.sourceRef), - it.seqNo, it.primaryTerm) + it.id to contentParser(it.sourceRef).parseWithType(NO_ID, it.seqNo, + it.primaryTerm, SweptManagedIndexConfig.Companion::parse) }.toMap() } diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt index 1fdb326d3..760060039 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt @@ -18,6 +18,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanageme import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.action.Action import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.convertToMap +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata.UpdateManagedIndexMetaDataAction import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.updateindexmetadata.UpdateManagedIndexMetaDataRequest import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getManagedIndexMetaData @@ -348,7 +349,7 @@ object ManagedIndexRunner : ScheduledJobRunner, updateManagedIndexMetaData(updatedManagedIndexMetaData) } - @Suppress("ReturnCount") + @Suppress("ReturnCount", "BlockingMethodInNonBlockingContext") private suspend fun getPolicy(policyID: String): Policy? { try { val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, policyID) @@ -362,7 +363,7 @@ object ManagedIndexRunner : ScheduledJobRunner, return withContext(Dispatchers.IO) { val xcp = XContentHelper.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, policySource, XContentType.JSON) - Policy.parseWithType(xcp, getResponse.id, getResponse.seqNo, getResponse.primaryTerm) + xcp.parseWithType(getResponse.id, getResponse.seqNo, getResponse.primaryTerm, Policy.Companion::parse) } } catch (e: Exception) { logger.error("Failed to get policy: $policyID", e) diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt index d1f3a3b1b..141c33f5b 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt @@ -182,22 +182,5 @@ data class ManagedIndexConfig( changePolicy = changePolicy ) } - - @JvmStatic - @JvmOverloads - @Throws(IOException::class) - fun parseWithType( - xcp: XContentParser, - id: String = NO_ID, - seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM - ): ManagedIndexConfig { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - val managedIndexConfig = parse(xcp, id, seqNo, primaryTerm) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - return managedIndexConfig - } } } diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/Policy.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/Policy.kt index 923682eba..85f165ce6 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/Policy.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/Policy.kt @@ -164,22 +164,5 @@ data class Policy( states.toList() ) } - - @JvmStatic - @JvmOverloads - @Throws(IOException::class) - fun parseWithType( - xcp: XContentParser, - id: String = NO_ID, - seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM - ): Policy { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - val policy = parse(xcp, id, seqNo, primaryTerm) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - return policy - } } } diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt index 2160eb340..368514718 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/coordinator/SweptManagedIndexConfig.kt @@ -18,6 +18,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanageme import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ChangePolicy import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Policy +import com.amazon.opendistroforelasticsearch.indexmanagement.util.NO_ID import org.elasticsearch.common.xcontent.XContentParser import org.elasticsearch.common.xcontent.XContentParser.Token import org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken @@ -43,7 +44,7 @@ data class SweptManagedIndexConfig( @Suppress("ComplexMethod") @JvmStatic @Throws(IOException::class) - fun parse(xcp: XContentParser, seqNo: Long, primaryTerm: Long): SweptManagedIndexConfig { + fun parse(xcp: XContentParser, id: String = NO_ID, seqNo: Long, primaryTerm: Long): SweptManagedIndexConfig { lateinit var index: String lateinit var uuid: String lateinit var policyID: String @@ -78,16 +79,5 @@ data class SweptManagedIndexConfig( changePolicy ) } - - @JvmStatic - @Throws(IOException::class) - fun parseWithType(xcp: XContentParser, seqNo: Long, primaryTerm: Long): SweptManagedIndexConfig { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - val sweptManagedIndex = parse(xcp, seqNo, primaryTerm) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - return sweptManagedIndex - } } } diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt index f2ec38c33..fb21d51d9 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/resthandler/RestIndexPolicyAction.kt @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.resthandler import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.POLICY_BASE_URI +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Policy import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.ALLOW_LIST import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.indexpolicy.IndexPolicyAction @@ -76,7 +77,7 @@ class RestIndexPolicyAction( } val xcp = request.contentParser() - val policy = Policy.parseWithType(xcp = xcp, id = id).copy(lastUpdatedTime = Instant.now()) + val policy = xcp.parseWithType(id = id, parse = Policy.Companion::parse).copy(lastUpdatedTime = Instant.now()) val seqNo = request.paramAsLong(IF_SEQ_NO, SequenceNumbers.UNASSIGNED_SEQ_NO) val primaryTerm = request.paramAsLong(IF_PRIMARY_TERM, SequenceNumbers.UNASSIGNED_PRIMARY_TERM) diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt index 4feefd44b..5248f7f88 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/changepolicy/TransportChangePolicyAction.kt @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.changepolicy import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getManagedIndexMetaData import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.elasticapi.getPolicyID import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig @@ -27,6 +28,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util.isSafeToChange import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util.updateManagedIndexRequest import com.amazon.opendistroforelasticsearch.indexmanagement.util.IndexUtils +import com.amazon.opendistroforelasticsearch.indexmanagement.util.NO_ID import org.apache.logging.log4j.LogManager import org.elasticsearch.ElasticsearchStatusException import org.elasticsearch.action.ActionListener @@ -117,7 +119,7 @@ class TransportChangePolicyAction @Inject constructor( LoggingDeprecationHandler.INSTANCE, response.sourceAsBytesRef, XContentType.JSON - ).use { Policy.parseWithType(it, response.id, response.seqNo, response.primaryTerm) } + ).use { it.parseWithType(response.id, response.seqNo, response.primaryTerm, Policy.Companion::parse) } getClusterState() } @@ -181,7 +183,8 @@ class TransportChangePolicyAction @Inject constructor( // The id is the index uuid if (!it.isFailed && it.response != null) { foundManagedIndices.add(it.response.id) - SweptManagedIndexConfig.parseWithType(contentParser(it.response.sourceAsBytesRef), it.response.seqNo, it.response.primaryTerm) + contentParser(it.response.sourceAsBytesRef).parseWithType(NO_ID, it.response.seqNo, + it.response.primaryTerm, SweptManagedIndexConfig.Companion::parse) } else { null } diff --git a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt index 35bdbb702..310c91f11 100644 --- a/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt +++ b/src/main/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPolicyAction.kt @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.transport.action.getpolicy import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Policy import org.elasticsearch.ElasticsearchStatusException import org.elasticsearch.action.ActionListener @@ -39,7 +40,7 @@ class TransportGetPolicyAction @Inject constructor( actionFilters: ActionFilters, val xContentRegistry: NamedXContentRegistry ) : HandledTransportAction( - GetPolicyAction.NAME, transportService, actionFilters, ::GetPolicyRequest + GetPolicyAction.NAME, transportService, actionFilters, ::GetPolicyRequest ) { override fun doExecute(task: Task, request: GetPolicyRequest, listener: ActionListener) { GetPolicyHandler(client, listener, request).start() @@ -80,7 +81,7 @@ class TransportGetPolicyAction @Inject constructor( response.sourceAsBytesRef, XContentType.JSON ).use { xcp -> - policy = Policy.parseWithType(xcp, response.id, response.seqNo, response.primaryTerm) + policy = xcp.parseWithType(response.id, response.seqNo, response.primaryTerm, Policy.Companion::parse) } } diff --git a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt index 975089c95..84c137edd 100644 --- a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt +++ b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt @@ -21,6 +21,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlug import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementIndices import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.ISM_BASE_URI import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementRestTestCase +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ChangePolicy import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData @@ -242,7 +243,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() val hit = searchResponse.hits.hits.firstOrNull() return hit?.run { val xcp = createParser(jsonXContent, this.sourceRef) - ManagedIndexConfig.parseWithType(xcp, id, seqNo, primaryTerm) + xcp.parseWithType(id, seqNo, primaryTerm, ManagedIndexConfig.Companion::parse) } } @@ -253,7 +254,7 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() assertTrue("Did not find managed index config", getResponse.isExists) return getResponse?.run { val xcp = createParser(jsonXContent, sourceAsBytesRef) - ManagedIndexConfig.parseWithType(xcp, id, seqNo, primaryTerm) + xcp.parseWithType(id, seqNo, primaryTerm, ManagedIndexConfig.Companion::parse) } } diff --git a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt index 0b868ec82..0e67a7bc9 100644 --- a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt +++ b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/ManagedIndexConfigTests.kt @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.common.xcontent.XContentParser @@ -34,22 +35,22 @@ class ManagedIndexConfigTests : ESTestCase() { val missingPolicyID = """{"managed_index":{"name":"edpNNwdVXG","enabled":false,"index":"DcdVHfmQUI","index_uuid":"SdcNvtdyAZYyrVkFMoQr","schedule":{"interval":{"start_time":1560402722674,"period":5,"unit":"Minutes"}},"last_updated_time":1560402722676,"enabled_time":null,"policy_seq_no":5,"policy_primary_term":17,"policy":{"name":"KumaJGCWPi","last_updated_time":1560402722676,"schema_version":348392,"error_notification":null,"default_state":"EpbLVqVhtL","states":[{"name":"EpbLVqVhtL","action":[],"transitions":[]},{"name":"IIJxQdcenu","action":[],"transitions":[]},{"name":"zSXlbLUBqG","action":[],"transitions":[]},{"name":"nYRPBojBiy","action":[],"transitions":[]}]},"change_policy":{"policy_id":"BtrDpcCBeT","state":"obxAkRuhvq"}}}""" assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for missing indexUuid") { - ManagedIndexConfig.parseWithType(parserWithType(missingIndexUuid)) + parserWithType(missingIndexUuid).parseWithType(parse = ManagedIndexConfig.Companion::parse) } assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for missing index") { - ManagedIndexConfig.parseWithType(parserWithType(missingIndex)) + parserWithType(missingIndex).parseWithType(parse = ManagedIndexConfig.Companion::parse) } assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for missing name") { - ManagedIndexConfig.parseWithType(parserWithType(missingName)) + parserWithType(missingName).parseWithType(parse = ManagedIndexConfig.Companion::parse) } assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for missing schedule") { - ManagedIndexConfig.parseWithType(parserWithType(missingSchedule)) + parserWithType(missingSchedule).parseWithType(parse = ManagedIndexConfig.Companion::parse) } assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for missing lastUpdatedTime") { - ManagedIndexConfig.parseWithType(parserWithType(missingLastUpdatedTime)) + parserWithType(missingLastUpdatedTime).parseWithType(parse = ManagedIndexConfig.Companion::parse) } assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for missing policyID") { - ManagedIndexConfig.parseWithType(parserWithType(missingPolicyID)) + parserWithType(missingPolicyID).parseWithType(parse = ManagedIndexConfig.Companion::parse) } } diff --git a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt index 04f8defa2..814d13108 100644 --- a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt +++ b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/action/NotificationActionIT.kt @@ -23,6 +23,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.destination.Destination import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.destination.DestinationType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.randomErrorNotification +import com.amazon.opendistroforelasticsearch.indexmanagement.makeRequest import com.amazon.opendistroforelasticsearch.indexmanagement.waitFor import org.elasticsearch.script.Script import org.elasticsearch.script.ScriptType @@ -35,7 +36,8 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { private val testIndexName = javaClass.simpleName.toLowerCase(Locale.ROOT) // cannot test chime/slack in integ tests, but can test a custom webhook by - // using the POST call to write to the local integTest cluster and verify that index exists + // using the POST call to write to the local integTest cluster and verify that index has 1 doc + @Suppress("UNCHECKED_CAST") fun `test custom webhook notification`() { val indexName = "${testIndexName}_index" val policyID = "${testIndexName}_testPolicyName" @@ -72,6 +74,7 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { createPolicy(policy, policyID) createIndex(indexName, policyID) + createIndex(notificationIndex) val managedIndexConfig = getExistingManagedIndexConfig(indexName) @@ -80,14 +83,18 @@ class NotificationActionIT : IndexStateManagementRestTestCase() { waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(indexName).policyID) } - // verify index does not exist - assertFalse("Notification index exists before notification has been sent", indexExists(notificationIndex)) + // verify index does not have any docs + assertEquals("Notification index has docs before notification has been sent", 0, (client().makeRequest("GET", "$notificationIndex/_search") + .asMap() as Map>>)["hits"]!!["total"]!!["value"]) // Speed up to second execution where it will trigger the first execution of the action which // should call notification custom webhook and create the doc in notification_index updateManagedIndexConfigStartTime(managedIndexConfig) - // verify index does exist - waitFor { assertTrue("Notification index does not exist", indexExists(notificationIndex)) } + // verify index gets a doc + waitFor { + assertEquals("Notification index does not have a doc", 1, (client().makeRequest("GET", "$notificationIndex/_search") + .asMap() as Map>>)["hits"]!!["total"]!!["value"]) + } } } diff --git a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/XContentTests.kt b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/XContentTests.kt index fe158cdc7..63d2e5212 100644 --- a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/XContentTests.kt +++ b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/model/XContentTests.kt @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.action.ActionConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.nonNullRandomConditions import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.randomAllocationActionConfig @@ -46,7 +47,7 @@ class XContentTests : ESTestCase() { val policy = randomPolicy() val policyString = policy.toJsonString() - val parsedPolicy = Policy.parseWithType(parserWithType(policyString), policy.id, policy.seqNo, policy.primaryTerm) + val parsedPolicy = parserWithType(policyString).parseWithType(policy.id, policy.seqNo, policy.primaryTerm, Policy.Companion::parse) assertEquals("Round tripping Policy doesn't work", policy, parsedPolicy) } @@ -184,12 +185,12 @@ class XContentTests : ESTestCase() { val configTwoString = configTwo.toJsonString() val configThreeString = configThree.toJsonString() val parsedConfig = - ManagedIndexConfig.parseWithType(parserWithType(configString), config.id, config.seqNo, config.primaryTerm) + parserWithType(configString).parseWithType(config.id, config.seqNo, config.primaryTerm, ManagedIndexConfig.Companion::parse) val parsedConfigTwo = - ManagedIndexConfig.parseWithType(parserWithType(configTwoString), configTwo.id, configTwo.seqNo, configTwo.primaryTerm) + parserWithType(configTwoString).parseWithType(configTwo.id, configTwo.seqNo, configTwo.primaryTerm, ManagedIndexConfig.Companion::parse) configThree = configThree.copy(id = "some_doc_id", seqNo = 17, primaryTerm = 1) val parsedConfigThree = - ManagedIndexConfig.parseWithType(parserWithType(configThreeString), configThree.id, configThree.seqNo, configThree.primaryTerm) + parserWithType(configThreeString).parseWithType(configThree.id, configThree.seqNo, configThree.primaryTerm, ManagedIndexConfig.Companion::parse) assertEquals("Round tripping ManagedIndexConfig doesn't work", config, parsedConfig) assertEquals("Round tripping ManagedIndexConfig doesn't work with null change policy", configTwo, parsedConfigTwo) diff --git a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt index 14d84d333..dcc283129 100644 --- a/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt +++ b/src/test/kotlin/com/amazon/opendistroforelasticsearch/indexmanagement/indexstatemanagement/util/ManagedIndexUtilsTests.kt @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX +import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.parseWithType import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Conditions import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Transition @@ -49,7 +50,7 @@ class ManagedIndexUtilsTests : ESTestCase() { assertEquals("Incorrect uuid used as document id on request", uuid, createRequest.id()) val source = createRequest.source() - val managedIndexConfig = ManagedIndexConfig.parseWithType(contentParser(source)) + val managedIndexConfig = contentParser(source).parseWithType(parse = ManagedIndexConfig.Companion::parse) assertEquals("Incorrect index on ManagedIndexConfig source", index, managedIndexConfig.index) assertEquals("Incorrect name on ManagedIndexConfig source", index, managedIndexConfig.name) assertEquals("Incorrect index uuid on ManagedIndexConfig source", uuid, managedIndexConfig.indexUuid) @@ -123,7 +124,7 @@ class ManagedIndexUtilsTests : ESTestCase() { assertEquals("Incorrect uuid used as document id on request", clusterConfigToCreate.uuid, request.id()) assertTrue("Incorrect request type", request is IndexRequest) val source = (request as IndexRequest).source() - val managedIndexConfig = ManagedIndexConfig.parseWithType(contentParser(source)) + val managedIndexConfig = contentParser(source).parseWithType(parse = ManagedIndexConfig.Companion::parse) assertEquals("Incorrect index on ManagedIndexConfig source", clusterConfigToCreate.index, managedIndexConfig.index) assertEquals("Incorrect name on ManagedIndexConfig source", clusterConfigToCreate.index, managedIndexConfig.name)