diff --git a/.github/workflows/multi-node-test-workflow.yml b/.github/workflows/multi-node-test-workflow.yml new file mode 100644 index 00000000..f80a7686 --- /dev/null +++ b/.github/workflows/multi-node-test-workflow.yml @@ -0,0 +1,27 @@ +name: Multi node test workflow +# This workflow is triggered on pull requests to master +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + build: + # Job name + name: Build Alerting + # This job runs on Linux + runs-on: ubuntu-latest + steps: + # This step uses the checkout Github action: https://github.com/actions/checkout + - name: Checkout Branch + uses: actions/checkout@v2 + # This step uses the setup-java Github action: https://github.com/actions/setup-java + - name: Set Up JDK 14 + uses: actions/setup-java@v1 + with: + java-version: 14 + - name: Run integration tests with multi node config + run: ./gradlew integTest -PnumNodes=3 diff --git a/README.md b/README.md index 6ff68c34..08024638 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,10 @@ When launching a cluster using one of the above commands, logs are placed in `al #### Run integration tests with Security enabled 1. Setup a local odfe cluster with security plugin. -`./gradlew build` -`./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername=es-integrationtest -Dhttps=true -Duser=admin -Dpassword=admin` -`./gradlew :alerting:integTestRunner -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername=es-integrationtest -Dhttps=true -Duser=admin -Dpassword=admin --tests "com.amazon.opendistroforelasticsearch.alerting.MonitorRunnerIT.test execute monitor returns search result"` + + - `./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername=es-integrationtest -Dhttps=true -Duser=admin -Dpassword=admin` + + - `./gradlew :alerting:integTestRunner -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername=es-integrationtest -Dhttps=true -Duser=admin -Dpassword=admin --tests "com.amazon.opendistroforelasticsearch.alerting.MonitorRunnerIT.test execute monitor returns search result"` ### Debugging @@ -75,7 +76,7 @@ You must start your debugger to listen for remote JVM before running the below c To debug code running in an actual server, run: ``` -./gradlew :alerting:integTest -Des.debug # to start a cluster and run integ tests +./gradlew :alerting:integTest -Dcluster.debug # to start a cluster and run integ tests ``` OR @@ -84,18 +85,20 @@ OR ./gradlew :alerting:run --debug-jvm # to just start a cluster that can be debugged ``` -The Elasticsearch server JVM will launch suspended and wait for a debugger to attach to `localhost:5005` before starting the Elasticsearch server. -The IDE needs to listen for the remote JVM. If using Intellij you must set your debug configuration to "Listen to remote JVM" and make sure "Auto Restart" is checked. -You must start your debugger to listen for remote JVM before running the commands. +The Elasticsearch server JVM will launch suspended and wait for a debugger to attach to `localhost:5005` before starting the Elasticsearch server. The IDE needs to listen for the remote JVM. If using Intellij you must set your debug configuration to "Listen to remote JVM" and make sure "Auto Restart" is checked. You must start your debugger to listen for remote JVM before running the commands. To debug code running in an integ test (which exercises the server from a separate JVM), run: ``` -./gradlew -Dtest.debug :alerting:integTest +./gradlew :alerting:integTest -Dtest.debug ``` -The test runner JVM will start suspended and wait for a debugger to attach to `localhost:5005` before running the tests. +The test runner JVM will start suspended and wait for a debugger to attach to `localhost:8000` before running the tests. +Additionally, it is possible to attach one debugger to the cluster JVM and another debugger to the test runner. First, make sure one debugger is listening on port `5005` and the other is listening on port `8000`. Then, run: +``` +./gradlew :alerting:integTest -Dtest.debug -Dcluster.debug +``` ### Advanced: Launching multi-node clusters locally diff --git a/alerting/build.gradle b/alerting/build.gradle index 853c3c22..9d67e6d9 100644 --- a/alerting/build.gradle +++ b/alerting/build.gradle @@ -1,6 +1,3 @@ -import java.nio.charset.StandardCharsets -import java.nio.file.Files - /* * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * @@ -15,19 +12,18 @@ import java.nio.file.Files * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ + +import org.elasticsearch.gradle.test.RestIntegTestTask + apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'elasticsearch.esplugin' -apply plugin: 'elasticsearch.testclusters' apply plugin: 'jacoco' def usingRemoteCluster = System.properties.containsKey('tests.rest.cluster') || System.properties.containsKey('tests.cluster') def usingMultiNode = project.properties.containsKey('numNodes') -// Only apply jacoco test coverage if we are running a local single node cluster -if (!usingRemoteCluster && !usingMultiNode) { - apply from: '../build-tools/esplugin-coverage.gradle' -} + ext { projectSubstitutions = [:] @@ -88,6 +84,9 @@ dependencyLicenses.enabled = false validateNebulaPom.enabled = false thirdPartyAudit.enabled = false +loggerUsageCheck.enabled = false +licenseHeaders.enabled = false + def es_tmp_dir = rootProject.file('build/private/es_tmp').absoluteFile es_tmp_dir.mkdirs() @@ -95,38 +94,17 @@ test { systemProperty 'tests.security.manager', 'false' } -def _numNodes = findProperty('numNodes') as Integer ?: 1 -integTest { - runner { - systemProperty 'tests.security.manager', 'false' - systemProperty 'java.io.tmpdir', es_tmp_dir.absolutePath - - systemProperty "https", System.getProperty("https") - systemProperty "user", System.getProperty("user") - systemProperty "password", System.getProperty("password") - - // The 'doFirst' delays till execution time. - doFirst { - // Tell the test JVM if the cluster JVM is running under a debugger so that tests can - // use longer timeouts for requests. - def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null - systemProperty 'cluster.debug', isDebuggingCluster - // Set number of nodes system property to be used in tests - systemProperty 'cluster.number_of_nodes', "${_numNodes}" - // There seems to be an issue when running multi node run or integ tasks with unicast_hosts - // not being written, the waitForAllConditions ensures it's written - getClusters().forEach { cluster -> - cluster.waitForAllConditions() - } - } - - // The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable - if (System.getProperty("test.debug") != null) { - jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' - } - } +task integTest(type: RestIntegTestTask) { + description = "Run integration tests against integTest cluster" + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath } +tasks.named("check").configure { dependsOn(integTest) } +Zip bundle = (Zip) project.getTasks().getByName("bundlePlugin"); +integTest.dependsOn(bundle) +integTest.getClusters().forEach{c -> c.plugin(project.getObjects().fileProperty().value(bundle.getArchiveFile()))} +def _numNodes = findProperty('numNodes') as Integer ?: 1 testClusters.integTest { testDistribution = "OSS" // Cluster shrink exception thrown if we try to set numberOfNodes to 1, so only apply if > 1 @@ -134,15 +112,44 @@ testClusters.integTest { // When running integration tests it doesn't forward the --debug-jvm to the cluster anymore // i.e. we have to use a custom property to flag when we want to debug elasticsearch JVM // since we also support multi node integration tests we increase debugPort per node - if (System.getProperty("es.debug") != null) { + if (System.getProperty("cluster.debug") != null) { def debugPort = 5005 nodes.forEach { node -> - node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=*:${debugPort}") + node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=${debugPort}") debugPort += 1 } } } +integTest { + systemProperty 'tests.security.manager', 'false' + systemProperty 'java.io.tmpdir', es_tmp_dir.absolutePath + + systemProperty "https", System.getProperty("https") + systemProperty "user", System.getProperty("user") + systemProperty "password", System.getProperty("password") + + // The 'doFirst' delays till execution time. + doFirst { + // Tell the test JVM if the cluster JVM is running under a debugger so that tests can + // use longer timeouts for requests. + def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null + systemProperty 'cluster.debug', isDebuggingCluster + // Set number of nodes system property to be used in tests + systemProperty 'cluster.number_of_nodes', "${_numNodes}" + // There seems to be an issue when running multi node run or integ tasks with unicast_hosts + // not being written, the waitForAllConditions ensures it's written + getClusters().forEach { cluster -> + cluster.waitForAllConditions() + } + } + + // The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable + if (System.getProperty("test.debug") != null) { + jvmArgs '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=8000' + } +} + run { doFirst { // There seems to be an issue when running multi node run or integ tasks with unicast_hosts @@ -151,6 +158,12 @@ run { cluster.waitForAllConditions() } } + // useCluster testClusters.integTest +} + +// Only apply jacoco test coverage if we are running a local single node cluster +if (!usingRemoteCluster && !usingMultiNode) { + apply from: '../build-tools/esplugin-coverage.gradle' } apply from: '../build-tools/pkgbuild.gradle' diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt index af78c2e0..224e6a1b 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt @@ -438,7 +438,7 @@ class MonitorRunner( private fun contentParser(bytesReference: BytesReference): XContentParser { val xcp = XContentHelper.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON) - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) return xcp } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertError.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertError.kt index 9e95eb06..22a4ed32 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertError.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertError.kt @@ -52,7 +52,7 @@ data class AlertError(val timestamp: Instant, val message: String) : Writeable, lateinit var timestamp: Instant lateinit var message: String - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertIndices.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertIndices.kt index 799f2f65..ebb9395d 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertIndices.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertIndices.kt @@ -42,7 +42,6 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse import org.elasticsearch.client.Client import org.elasticsearch.cluster.ClusterChangedEvent import org.elasticsearch.cluster.ClusterStateListener -import org.elasticsearch.cluster.LocalNodeMasterListener import org.elasticsearch.cluster.service.ClusterService import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.unit.TimeValue @@ -66,11 +65,10 @@ class AlertIndices( private val client: Client, private val threadPool: ThreadPool, private val clusterService: ClusterService -) : LocalNodeMasterListener, ClusterStateListener { +) : ClusterStateListener { init { clusterService.addListener(this) - clusterService.addLocalNodeMasterListener(this) clusterService.clusterSettings.addSettingsUpdateConsumer(ALERT_HISTORY_ENABLED) { historyEnabled = it } clusterService.clusterSettings.addSettingsUpdateConsumer(ALERT_HISTORY_MAX_DOCS) { historyMaxDocs = it } clusterService.clusterSettings.addSettingsUpdateConsumer(ALERT_HISTORY_INDEX_MAX_AGE) { historyMaxAge = it } @@ -123,6 +121,8 @@ class AlertIndices( @Volatile private var requestTimeout = AlertingSettings.REQUEST_TIMEOUT.get(settings) + @Volatile private var isMaster = false + // for JobsMonitor to report var lastRolloverTime: TimeValue? = null @@ -132,7 +132,7 @@ class AlertIndices( private var scheduledRollover: Cancellable? = null - override fun onMaster() { + fun onMaster() { try { // TODO: Change current actionGet requests within rolloverHistoryIndex() rolloverAndDeleteHistoryIndices() to use suspendUntil // try to rollover immediately as we might be restarting the cluster @@ -147,16 +147,28 @@ class AlertIndices( } } - override fun offMaster() { + fun offMaster() { scheduledRollover?.cancel() } - override fun executorName(): String { + private fun executorName(): String { return ThreadPool.Names.MANAGEMENT } override fun clusterChanged(event: ClusterChangedEvent) { - // if the indexes have been deleted they need to be reinitalized + // Instead of using a LocalNodeMasterListener to track master changes, this service will + // track them here to avoid conditions where master listener events run after other + // listeners that depend on what happened in the master listener + if (this.isMaster != event.localNodeMaster()) { + this.isMaster = event.localNodeMaster() + if (this.isMaster) { + onMaster() + } else { + offMaster() + } + } + + // if the indexes have been deleted they need to be reinitialized alertIndexInitialized = event.state().routingTable().hasIndex(ALERT_INDEX) historyIndexInitialized = event.state().metadata().hasAlias(HISTORY_WRITE_INDEX) } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt index 52a330c0..ecfc5a1d 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt @@ -111,6 +111,6 @@ suspend fun moveAlerts(client: Client, monitorId: String, monitor: Monitor? = nu private fun alertContentParser(bytesReference: BytesReference): XContentParser { val xcp = XContentHelper.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytesReference, XContentType.JSON) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) return xcp } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/ActionExecutionResult.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/ActionExecutionResult.kt index fcc6e242..88d4467d 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/ActionExecutionResult.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/ActionExecutionResult.kt @@ -72,7 +72,7 @@ data class ActionExecutionResult( var throttledCount: Int = 0 var lastExecutionTime: Instant? = null - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Alert.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Alert.kt index d886006a..af6aafeb 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Alert.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Alert.kt @@ -172,7 +172,7 @@ data class Alert( val errorHistory: MutableList = mutableListOf() var actionExecutionResults: MutableList = mutableListOf() - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() @@ -192,14 +192,14 @@ data class Alert( ACKNOWLEDGED_TIME_FIELD -> acknowledgedTime = xcp.instant() ERROR_MESSAGE_FIELD -> errorMessage = xcp.textOrNull() ALERT_HISTORY_FIELD -> { - ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { errorHistory.add(AlertError.parse(xcp)) } } SEVERITY_FIELD -> severity = xcp.text() ACTION_EXECUTION_RESULTS_FIELD -> { - ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { actionExecutionResults.add(ActionExecutionResult.parse(xcp)) } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Monitor.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Monitor.kt index bfb4f036..6aa9d711 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Monitor.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Monitor.kt @@ -183,7 +183,7 @@ data class Monitor( val triggers: MutableList = mutableListOf() val inputs: MutableList = mutableListOf() - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() @@ -195,13 +195,13 @@ data class Monitor( ENABLED_FIELD -> enabled = xcp.booleanValue() SCHEDULE_FIELD -> schedule = Schedule.parse(xcp) INPUTS_FIELD -> { - ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_ARRAY) { inputs.add(Input.parse(xcp)) } } TRIGGERS_FIELD -> { - ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_ARRAY) { triggers.add(Trigger.parse(xcp)) } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Trigger.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Trigger.kt index 5723fb5a..d34cdbc1 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Trigger.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Trigger.kt @@ -87,7 +87,7 @@ data class Trigger( lateinit var severity: String lateinit var condition: Script val actions: MutableList = mutableListOf() - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() @@ -106,7 +106,7 @@ data class Trigger( xcp.nextToken() } ACTIONS_FIELD -> { - ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_ARRAY) { actions.add(Action.parse(xcp)) } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Action.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Action.kt index 8a1e9f87..ea727ed9 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Action.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Action.kt @@ -123,7 +123,7 @@ data class Action( var throttleEnabled = false var throttle: Throttle? = null - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Throttle.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Throttle.kt index 4aebddf1..f1f7a50b 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Throttle.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/action/Throttle.kt @@ -62,7 +62,7 @@ data class Throttle( var value: Int = 0 var unit: ChronoUnit = ChronoUnit.MINUTES // only support MINUTES throttle unit currently - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Chime.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Chime.kt index 63b458b0..87cd5863 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Chime.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Chime.kt @@ -58,7 +58,7 @@ data class Chime(val url: String) : ToXContent { fun parse(xcp: XContentParser): Chime { lateinit var url: String - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/CustomWebhook.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/CustomWebhook.kt index 13f88fef..d4c74744 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/CustomWebhook.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/CustomWebhook.kt @@ -99,7 +99,7 @@ data class CustomWebhook( var username: String? = null var password: String? = null - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Destination.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Destination.kt index c7f69a48..6d60a804 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Destination.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Destination.kt @@ -147,7 +147,7 @@ data class Destination( var lastUpdateTime: Instant? = null var schemaVersion = NO_SCHEMA_VERSION - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() @@ -204,11 +204,11 @@ data class Destination( @JvmStatic @Throws(IOException::class) fun parseWithType(xcp: XContentParser, id: String = NO_ID, version: Long = NO_VERSION): Destination { - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) + ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) val destination = parse(xcp, id, version) - ensureExpectedToken(XContentParser.Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.END_OBJECT, xcp.nextToken(), xcp) return destination } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/SNS.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/SNS.kt index 31722f61..ad63cb2b 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/SNS.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/SNS.kt @@ -52,7 +52,7 @@ data class SNS(val topicARN: String, val roleARN: String) : ToXContent { lateinit var topicARN: String lateinit var roleARN: String - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Slack.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Slack.kt index e1b0a3b7..6dbc3a4a 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Slack.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/Slack.kt @@ -58,7 +58,7 @@ data class Slack(val url: String) : ToXContent { fun parse(xcp: XContentParser): Slack { lateinit var url: String - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/Email.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/Email.kt index 3eb0897f..52e79ea8 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/Email.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/Email.kt @@ -65,7 +65,7 @@ data class Email( lateinit var emailAccountID: String val recipients: MutableList = mutableListOf() - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() @@ -73,7 +73,7 @@ data class Email( when (fieldName) { EMAIL_ACCOUNT_ID_FIELD -> emailAccountID = xcp.text() RECIPIENTS_FIELD -> { - ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_ARRAY) { recipients.add(Recipient.parse(xcp)) } @@ -164,7 +164,7 @@ data class Recipient( var emailGroupID: String? = null var email: String? = null - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailAccount.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailAccount.kt index dff45316..2f2684fd 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailAccount.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailAccount.kt @@ -120,7 +120,7 @@ data class EmailAccount( var port: Int = -1 lateinit var method: String - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() @@ -155,11 +155,11 @@ data class EmailAccount( @JvmStatic @Throws(IOException::class) fun parseWithType(xcp: XContentParser, id: String = NO_ID, version: Long = NO_VERSION): EmailAccount { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) + ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) val emailAccount = parse(xcp, id, version) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp) return emailAccount } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailGroup.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailGroup.kt index cc52e267..cb6c520b 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailGroup.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/destination/email/EmailGroup.kt @@ -90,7 +90,7 @@ data class EmailGroup( lateinit var name: String val emails: MutableList = mutableListOf() - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() @@ -99,7 +99,7 @@ data class EmailGroup( SCHEMA_VERSION -> schemaVersion = xcp.intValue() NAME_FIELD -> name = xcp.text() EMAILS_FIELD -> { - ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_ARRAY) { emails.add(EmailEntry.parse(xcp)) } @@ -121,11 +121,11 @@ data class EmailGroup( @JvmStatic @Throws(IOException::class) fun parseWithType(xcp: XContentParser, id: String = NO_ID, version: Long = NO_VERSION): EmailGroup { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) + ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) val emailGroup = parse(xcp, id, version) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp) return emailGroup } @@ -174,7 +174,7 @@ data class EmailEntry(val email: String) : Writeable, ToXContent { fun parse(xcp: XContentParser): EmailEntry { lateinit var email: String - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt index 68dc28e8..95d56395 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt @@ -74,13 +74,13 @@ class RestAcknowledgeAlertAction : BaseRestHandler() { */ private fun getAlertIds(xcp: XContentParser): List { val ids = mutableListOf() - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() when (fieldName) { "alerts" -> { - ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { ids.add(xcp.text()) } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt index 6e0912b5..67fa8cf0 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt @@ -58,7 +58,7 @@ class RestExecuteMonitorAction : BaseRestHandler() { client.execute(ExecuteMonitorAction.INSTANCE, execMonitorRequest, RestToXContentListener(channel)) } else { val xcp = request.contentParser() - ensureExpectedToken(START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(START_OBJECT, xcp.nextToken(), xcp) val monitor = Monitor.parse(xcp, Monitor.NO_ID, Monitor.NO_VERSION) val execMonitorRequest = ExecuteMonitorRequest(dryrun, requestEnd, null, monitor) client.execute(ExecuteMonitorAction.INSTANCE, execMonitorRequest, RestToXContentListener(channel)) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt index 3691f395..9ca654b0 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt @@ -70,7 +70,7 @@ class RestIndexDestinationAction : BaseRestHandler() { // Validate request by parsing JSON to Destination val xcp = request.contentParser() - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) val destination = Destination.parse(xcp, id) 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/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailAccountAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailAccountAction.kt index 8d158733..1b1fbb1e 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailAccountAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailAccountAction.kt @@ -67,7 +67,7 @@ class RestIndexEmailAccountAction : BaseRestHandler() { // Validate request by parsing JSON to EmailAccount val xcp = request.contentParser() - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) val emailAccount = EmailAccount.parse(xcp, id) 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/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailGroupAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailGroupAction.kt index 461511d8..6aa5dca4 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailGroupAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexEmailGroupAction.kt @@ -67,7 +67,7 @@ class RestIndexEmailGroupAction : BaseRestHandler() { // Validate request by parsing JSON to EmailGroup val xcp = request.contentParser() - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) val emailGroup = EmailGroup.parse(xcp, id) 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/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt index 0b9dbd83..af039294 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt @@ -72,7 +72,7 @@ class RestIndexMonitorAction : BaseRestHandler() { // Validate request by parsing JSON to Monitor val xcp = request.contentParser() - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) val monitor = Monitor.parse(xcp, id).copy(lastUpdateTime = 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/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportAcknowledgeAlertAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportAcknowledgeAlertAction.kt index 7eeb85b9..e631e3e0 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportAcknowledgeAlertAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportAcknowledgeAlertAction.kt @@ -81,7 +81,7 @@ class TransportAcknowledgeAlertAction @Inject constructor( val updateRequests = response.hits.flatMap { hit -> val xcp = XContentHelper.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceRef, XContentType.JSON) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) val alert = Alert.parse(xcp, hit.id, hit.version) alerts[alert.id] = alert if (alert.state == Alert.State.ACTIVE) { diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetAlertsAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetAlertsAction.kt index 02242833..08b11088 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetAlertsAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetAlertsAction.kt @@ -154,7 +154,7 @@ class TransportGetAlertsAction @Inject constructor( val alerts = response.hits.map { hit -> val xcp = XContentHelper.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceRef, XContentType.JSON) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) val alert = Alert.parse(xcp, hit.id, hit.version) alert } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetDestinationsAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetDestinationsAction.kt index f042a160..1a043509 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetDestinationsAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/transport/TransportGetDestinationsAction.kt @@ -159,9 +159,9 @@ class TransportGetDestinationsAction @Inject constructor( val primaryTerm = hit.primaryTerm.toInt() val xcp = XContentFactory.xContent(XContentType.JSON) .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, hit.sourceAsString) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) destinations.add(Destination.parse(xcp, id, version, seqNo, primaryTerm)) } actionListener.onResponse(GetDestinationsResponse(RestStatus.OK, totalDestinationCount, destinations)) diff --git a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt index 937f4ad3..4b1c4ea2 100644 --- a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt +++ b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt @@ -128,7 +128,7 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { assertEquals("Unable to get email account $emailAccountID", RestStatus.OK, response.restStatus()) val parser = createParser(XContentType.JSON.xContent(), response.entity.content) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser) lateinit var id: String var version: Long = 0 @@ -185,7 +185,7 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { assertEquals("Unable to get email group $emailGroupID", RestStatus.OK, response.restStatus()) val parser = createParser(XContentType.JSON.xContent(), response.entity.content) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser) lateinit var id: String var version: Long = 0 @@ -348,7 +348,7 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { assertEquals("Unable to get monitor $monitorId", RestStatus.OK, response.restStatus()) val parser = createParser(XContentType.JSON.xContent(), response.entity.content) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser) lateinit var id: String var version: Long = 0 diff --git a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt index 97986100..4e2a90c4 100644 --- a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt +++ b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt @@ -433,7 +433,7 @@ class MonitorRunnerIT : AlertingRestTestCase() { verifyAlert(errorAlert, monitor, ERROR) executeMonitor(monitor.id) assertEquals("Error does not match", - "Failed evaluating trigger:\nparam[0]; return true\n^---- HERE", errorAlert.errorMessage) + "Failed evaluating trigger:\nparam[0]; return true\n ^---- HERE", errorAlert.errorMessage) } fun `test execute monitor limits alert error history to 10 error messages`() { diff --git a/build-tools/esplugin-coverage.gradle b/build-tools/esplugin-coverage.gradle index 8bfae297..1d4478ca 100644 --- a/build-tools/esplugin-coverage.gradle +++ b/build-tools/esplugin-coverage.gradle @@ -51,7 +51,7 @@ task dummyIntegTest(type: Test) { } } -integTest.runner { +integTest { systemProperty 'jacoco.dir', "${jacocoDir}" } @@ -77,5 +77,5 @@ jacocoTestReport { } project.gradle.projectsEvaluated { - jacocoTestReport.dependsOn integTest.runner + jacocoTestReport.dependsOn integTest } diff --git a/build.gradle b/build.gradle index 3cc84c78..d174e4da 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply from: 'build-tools/repositories.gradle' ext { - es_version = '7.9.1' + es_version = '7.10.0' kotlin_version = '1.3.72' } @@ -50,7 +50,7 @@ allprojects { group = "com.amazon.opendistroforelasticsearch" // Increment the final digit when there's a new plugin versions for the same opendistro version // Reset the final digit to 0 when upgrading to a new opendistro version - version = "${opendistroVersion}.1" + version = "${opendistroVersion}.0" apply from: "$rootDir/build-tools/repositories.gradle" @@ -79,7 +79,6 @@ task ktlint(type: JavaExec, group: "verification") { main = "com.github.shyiko.ktlint.Main" classpath = configurations.ktlint args "alerting/**/*.kt", "elastic-api/**/*.kt", "core/**/*.kt" - } task ktlintFormat(type: JavaExec, group: "formatting") { diff --git a/core/build.gradle b/core/build.gradle index f28c6359..bea25432 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -25,7 +25,7 @@ dependencies { compile "com.cronutils:cron-utils:7.0.5" compile "org.elasticsearch.client:elasticsearch-rest-client:${es_version}" compile 'com.google.googlejavaformat:google-java-format:1.3' - compile "com.amazon.opendistroforelasticsearch:common-utils:${opendistroVersion}.1" + compile "com.amazon.opendistroforelasticsearch:common-utils:${opendistroVersion}.0" testImplementation "org.elasticsearch.test:framework:${es_version}" testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}" diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/JobSweeper.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/JobSweeper.kt index 91491f69..b43c5f83 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/JobSweeper.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/JobSweeper.kt @@ -420,8 +420,8 @@ class JobSweeper( } private fun isSweepableJobType(xcp: XContentParser): Boolean { - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) + XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp) val jobType = xcp.currentName() return sweepableJobTypes.contains(jobType) } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Input.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Input.kt index 4c5c0477..fb6b768e 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Input.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Input.kt @@ -27,11 +27,11 @@ interface Input : Writeable, ToXContentObject { @Throws(IOException::class) fun parse(xcp: XContentParser): Input { - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) + ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) val input = xcp.namedObject(Input::class.java, xcp.currentName(), null) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp) return input } } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt index 88aa1bd4..76d4c26c 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt @@ -56,7 +56,7 @@ sealed class Schedule : Writeable, ToXContentObject { var unit: ChronoUnit? = null var schedule: Schedule? = null var type: TYPE? = null - ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { val fieldname = xcp.currentName() xcp.nextToken() diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduledJob.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduledJob.kt index a2c2fd12..7e7a0fc5 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduledJob.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduledJob.kt @@ -71,11 +71,11 @@ interface ScheduledJob : Writeable, ToXContentObject { */ @Throws(IOException::class) fun parse(xcp: XContentParser, id: String = NO_ID, version: Long = NO_VERSION): ScheduledJob { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp::getTokenLocation) - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) + ensureExpectedToken(Token.FIELD_NAME, xcp.nextToken(), xcp) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) val job = xcp.namedObject(ScheduledJob::class.java, xcp.currentName(), null) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp) return job.fromDocument(id, version) } @@ -87,9 +87,9 @@ interface ScheduledJob : Writeable, ToXContentObject { */ @Throws(IOException::class) fun parse(xcp: XContentParser, type: String, id: String = NO_ID, version: Long = NO_VERSION): ScheduledJob { - ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.nextToken(), xcp) val job = xcp.namedObject(ScheduledJob::class.java, type, null) - ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.END_OBJECT, xcp.nextToken(), xcp) return job.fromDocument(id, version) } } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/SearchInput.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/SearchInput.kt index 6e8101f3..81640221 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/SearchInput.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/SearchInput.kt @@ -67,13 +67,13 @@ data class SearchInput(val indices: List, val query: SearchSourceBuilder val indices = mutableListOf() lateinit var searchSourceBuilder: SearchSourceBuilder - ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_OBJECT) { val fieldName = xcp.currentName() xcp.nextToken() when (fieldName) { INDICES_FIELD -> { - ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp::getTokenLocation) + ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != Token.END_ARRAY) { indices.add(xcp.text()) } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/schedule/JobSchedulerMetrics.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/schedule/JobSchedulerMetrics.kt index 363b8ae1..ce13312d 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/schedule/JobSchedulerMetrics.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/schedule/JobSchedulerMetrics.kt @@ -48,7 +48,7 @@ class JobSchedulerMetrics : ToXContentFragment, Writeable { override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { if (lastExecutionTime != null) - builder.timeField("last_execution_time", "last_execution_time", Instant.ofEpochMilli(lastExecutionTime).toEpochMilli()) + builder.timeField("last_execution_time", "last_execution_time_in_millis", Instant.ofEpochMilli(lastExecutionTime).toEpochMilli()) builder.field("running_on_time", runningOnTime) return builder } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/elasticapi/ElasticExtensions.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/elasticapi/ElasticExtensions.kt index 798dcff4..fe9d8afe 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/elasticapi/ElasticExtensions.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/elasticapi/ElasticExtensions.kt @@ -134,7 +134,8 @@ fun XContentBuilder.optionalTimeField(name: String, instant: Instant?): XContent if (instant == null) { return nullField(name) } - return this.timeField(name, name, instant.toEpochMilli()) + // second name as readableName should be different than first name + return this.timeField(name, "${name}_in_millis", instant.toEpochMilli()) } fun XContentBuilder.optionalUserField(name: String, user: User?): XContentBuilder { diff --git a/gradle.properties b/gradle.properties index d87063aa..6de2cfcd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,4 +13,4 @@ # permissions and limitations under the License. # -version = 1.11.0 \ No newline at end of file +version = 1.12.0 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c053..e708b1c0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 622ab64a..12d38de6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index fbd7c515..4f906e0c 100755 --- a/gradlew +++ b/gradlew @@ -130,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index a9f778a7..ac1b06f9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/release-notes/opendistro-for-elasticsearch-alerting.release-notes-1.12.0.0.md b/release-notes/opendistro-for-elasticsearch-alerting.release-notes-1.12.0.0.md new file mode 100644 index 00000000..bdab7085 --- /dev/null +++ b/release-notes/opendistro-for-elasticsearch-alerting.release-notes-1.12.0.0.md @@ -0,0 +1,10 @@ +## 2020-11-17, Version 1.12.0.0 + +Compatible with Elasticsearch 7.10.0 + +### Bug Fixes +* get user info from threadcontext ([#289](https://github.com/opendistro-for-elasticsearch/alerting/pull/289)) +* Fix filter by user.backendroles and integ tests for it ([#290](https://github.com/opendistro-for-elasticsearch/alerting/pull/290)) + +### Maintenance + * Adds support for Elasticsearch 7.10.0 ([#300](https://github.com/opendistro-for-elasticsearch/alerting/pull/300))