Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Adds support for ES 7.7.0 (#205)
Browse files Browse the repository at this point in the history
* Adds support for ES 7.7.0

* Update the Release Notes

* Update the requirement of JDK 14 in README

* Update the Java version in 'push-notification-jar' workflow
  • Loading branch information
ftianli-amzn authored May 20, 2020
1 parent 16cfc36 commit 9f405c2
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 88 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push-notification-jar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '13'
java-version: '14'

- name: Upload Notification Jar to Maven
env:
passphrase: ${{ secrets.PASSPHRASE }}
run: |
cd ..
export JAVA13_HOME=$JAVA_HOME
export JAVA14_HOME=$JAVA_HOME
aws s3 cp s3://opendistro-docs/github-actions/pgp-public-key .
aws s3 cp s3://opendistro-docs/github-actions/pgp-private-key .
Expand All @@ -41,4 +41,4 @@ jobs:
cd alerting/notification
../gradlew publishShadowPublicationToSonatype-stagingRepository -Dcompiler.java=13 -Dbuild.snapshot=false -Djavax.net.ssl.trustStore=$JAVA_HOME/lib/security/cacerts
../gradlew publishShadowPublicationToSonatype-stagingRepository -Dcompiler.java=14 -Dbuild.snapshot=false -Djavax.net.ssl.trustStore=$JAVA_HOME/lib/security/cacerts
2 changes: 1 addition & 1 deletion .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
strategy:
matrix:
java: [13]
java: [14]
# Job name
name: Build Alerting with JDK ${{ matrix.java }}
# This job runs on Linux
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
strategy:
matrix:
java: [13]
java: [14]
# Job name
name: Build Alerting with JDK ${{ matrix.java }}
# This job runs on Linux
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Please see our [documentation](https://opendistro.github.io/for-elasticsearch-do

1. Check out this package from version control.
1. Launch Intellij IDEA, choose **Import Project**, and select the `settings.gradle` file in the root of this package.
1. To build from the command line, set `JAVA_HOME` to point to a JDK >= 13 before running `./gradlew`.
1. To build from the command line, set `JAVA_HOME` to point to a JDK >= 14 before running `./gradlew`.


## Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, P
indexNameExpressionResolver: IndexNameExpressionResolver?,
nodesInCluster: Supplier<DiscoveryNodes>
): List<RestHandler> {
return listOf(RestGetMonitorAction(restController),
RestDeleteMonitorAction(restController),
RestIndexMonitorAction(settings, restController, scheduledJobIndices, clusterService),
RestSearchMonitorAction(restController),
RestExecuteMonitorAction(settings, restController, runner),
RestAcknowledgeAlertAction(restController),
RestScheduledJobStatsHandler(restController, "_alerting"),
RestIndexDestinationAction(settings, restController, scheduledJobIndices, clusterService),
RestDeleteDestinationAction(restController))
return listOf(RestGetMonitorAction(),
RestDeleteMonitorAction(),
RestIndexMonitorAction(settings, scheduledJobIndices, clusterService),
RestSearchMonitorAction(),
RestExecuteMonitorAction(settings, runner),
RestAcknowledgeAlertAction(),
RestScheduledJobStatsHandler("_alerting"),
RestIndexDestinationAction(settings, scheduledJobIndices, clusterService),
RestDeleteDestinationAction())
}

override fun getActions(): List<ActionPlugin.ActionHandler<out ActionRequest, out ActionResponse>> {
Expand All @@ -130,7 +130,8 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, P
xContentRegistry: NamedXContentRegistry,
environment: Environment,
nodeEnvironment: NodeEnvironment,
namedWriteableRegistry: NamedWriteableRegistry
namedWriteableRegistry: NamedWriteableRegistry,
indexNameExpressionResolver: IndexNameExpressionResolver
): Collection<Any> {
// Need to figure out how to use the Elasticsearch DI classes rather than handwiring things here.
val settings = environment.settings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ class AlertIndices(
}
if (existsResponse.isExists) return true

val request = CreateIndexRequest(index).mapping(MAPPING_TYPE, alertMapping(), XContentType.JSON)
val request = CreateIndexRequest(index)
.mapping(MAPPING_TYPE, alertMapping(), XContentType.JSON)
.settings(Settings.builder().put("index.hidden", true).build())

if (alias != null) request.alias(Alias(alias))
return try {
val createIndexResponse: CreateIndexResponse = client.admin().indices().suspendUntil { create(request, it) }
Expand Down Expand Up @@ -259,6 +262,7 @@ class AlertIndices(
val request = RolloverRequest(HISTORY_WRITE_INDEX, null)
request.createIndexRequest.index(HISTORY_INDEX_PATTERN)
.mapping(MAPPING_TYPE, alertMapping(), XContentType.JSON)
.settings(Settings.builder().put("index.hidden", true).build())
request.addMaxIndexDocsCondition(historyMaxDocs)
request.addMaxIndexAgeCondition(historyMaxAge)
val response = client.admin().indices().rolloversIndex(request).actionGet(requestTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.BytesRestResponse
import org.elasticsearch.rest.RestChannel
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestRequest.Method.POST
import org.elasticsearch.rest.RestStatus
Expand All @@ -62,17 +62,19 @@ private val log: Logger = LogManager.getLogger(RestAcknowledgeAlertAction::class
* The user provides the monitorID to which these alerts pertain and in the content of the request provides
* the ids to the alerts he would like to acknowledge.
*/
class RestAcknowledgeAlertAction(controller: RestController) : BaseRestHandler() {

init {
// Acknowledge alerts
controller.registerHandler(POST, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}/_acknowledge/alerts", this)
}
class RestAcknowledgeAlertAction : BaseRestHandler() {

override fun getName(): String {
return "acknowledge_alert_action"
}

override fun routes(): List<Route> {
return listOf(
// Acknowledge alerts
Route(POST, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}/_acknowledge/alerts")
)
}

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val monitorId = request.param("monitorID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ import org.elasticsearch.action.support.WriteRequest
import org.elasticsearch.client.node.NodeClient
import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.action.RestStatusToXContentListener
import java.io.IOException

/**
* This class consists of the REST handler to delete destination.
*/
class RestDeleteDestinationAction(controller: RestController) : BaseRestHandler() {

init {
controller.registerHandler(RestRequest.Method.DELETE, "${AlertingPlugin.DESTINATION_BASE_URI}/{destinationID}", this)
}
class RestDeleteDestinationAction : BaseRestHandler() {

override fun getName(): String {
return "delete_destination_action"
}

override fun routes(): List<Route> {
return listOf(
Route(RestRequest.Method.DELETE, "${AlertingPlugin.DESTINATION_BASE_URI}/{destinationID}")
)
}

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val destinationId = request.param("destinationID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy
import org.elasticsearch.client.node.NodeClient
import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestRequest.Method.DELETE
import org.elasticsearch.rest.action.RestStatusToXContentListener
Expand All @@ -34,17 +34,18 @@ import java.io.IOException
* When a monitor is deleted, all alerts are moved to the [Alert.State.DELETED] state and moved to the alert history index.
* If this process fails the monitor is not deleted.
*/
class RestDeleteMonitorAction(controller: RestController) :
BaseRestHandler() {

init {
controller.registerHandler(DELETE, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}", this) // Delete a monitor
}
class RestDeleteMonitorAction : BaseRestHandler() {

override fun getName(): String {
return "delete_monitor_action"
}

override fun routes(): List<Route> {
return listOf(
Route(DELETE, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}") // Delete a monitor
)
}

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val monitorId = request.param("monitorID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.BytesRestResponse
import org.elasticsearch.rest.RestChannel
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestRequest.Method.POST
import org.elasticsearch.rest.RestStatus
Expand All @@ -48,17 +48,18 @@ private val log = LogManager.getLogger(RestExecuteMonitorAction::class.java)

class RestExecuteMonitorAction(
val settings: Settings,
restController: RestController,
private val runner: MonitorRunner
) : BaseRestHandler() {

init {
restController.registerHandler(POST, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}/_execute", this)
restController.registerHandler(POST, "${AlertingPlugin.MONITOR_BASE_URI}/_execute", this)
}

override fun getName(): String = "execute_monitor_action"

override fun routes(): List<Route> {
return listOf(
Route(POST, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}/_execute"),
Route(POST, "${AlertingPlugin.MONITOR_BASE_URI}/_execute")
)
}

override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
return RestChannelConsumer { channel ->
val dryrun = request.paramAsBoolean("dryrun", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.BytesRestResponse
import org.elasticsearch.rest.RestChannel
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestRequest.Method.GET
import org.elasticsearch.rest.RestRequest.Method.HEAD
Expand All @@ -45,18 +45,20 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext
/**
* This class consists of the REST handler to retrieve a monitor .
*/
class RestGetMonitorAction(controller: RestController) : BaseRestHandler() {

init {
// Get a specific monitor
controller.registerHandler(GET, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}", this)
controller.registerHandler(HEAD, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}", this)
}
class RestGetMonitorAction : BaseRestHandler() {

override fun getName(): String {
return "get_monitor_action"
}

override fun routes(): List<Route> {
return listOf(
// Get a specific monitor
Route(GET, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}"),
Route(HEAD, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}")
)
}

override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val monitorId = request.param("monitorID")
if (monitorId == null || monitorId.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.BytesRestResponse
import org.elasticsearch.rest.RestChannel
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestResponse
import org.elasticsearch.rest.RestStatus
Expand All @@ -63,7 +63,6 @@ private val log = LogManager.getLogger(RestIndexDestinationAction::class.java)
*/
class RestIndexDestinationAction(
settings: Settings,
controller: RestController,
jobIndices: ScheduledJobIndices,
clusterService: ClusterService
) : BaseRestHandler() {
Expand All @@ -72,8 +71,6 @@ class RestIndexDestinationAction(
@Volatile private var indexTimeout = INDEX_TIMEOUT.get(settings)

init {
controller.registerHandler(RestRequest.Method.POST, AlertingPlugin.DESTINATION_BASE_URI, this) // Creates new destination
controller.registerHandler(RestRequest.Method.PUT, "${AlertingPlugin.DESTINATION_BASE_URI}/{destinationID}", this)
scheduledJobIndices = jobIndices

clusterService.clusterSettings.addSettingsUpdateConsumer(INDEX_TIMEOUT) { indexTimeout = it }
Expand All @@ -84,6 +81,13 @@ class RestIndexDestinationAction(
return "index_destination_action"
}

override fun routes(): List<Route> {
return listOf(
Route(RestRequest.Method.POST, AlertingPlugin.DESTINATION_BASE_URI), // Creates new destination
Route(RestRequest.Method.PUT, "${AlertingPlugin.DESTINATION_BASE_URI}/{destinationID}")
)
}

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): BaseRestHandler.RestChannelConsumer {
val id = request.param("destinationID", Destination.NO_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.BytesRestResponse
import org.elasticsearch.rest.RestChannel
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestRequest.Method.POST
import org.elasticsearch.rest.RestRequest.Method.PUT
Expand All @@ -77,7 +77,6 @@ private val log = LogManager.getLogger(RestIndexMonitorAction::class.java)
*/
class RestIndexMonitorAction(
settings: Settings,
controller: RestController,
jobIndices: ScheduledJobIndices,
clusterService: ClusterService
) : BaseRestHandler() {
Expand All @@ -90,8 +89,6 @@ class RestIndexMonitorAction(
@Volatile private var maxActionThrottle = MAX_ACTION_THROTTLE_VALUE.get(settings)

init {
controller.registerHandler(POST, AlertingPlugin.MONITOR_BASE_URI, this) // Create a new monitor
controller.registerHandler(PUT, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}", this)
scheduledJobIndices = jobIndices

clusterService.clusterSettings.addSettingsUpdateConsumer(ALERTING_MAX_MONITORS) { maxMonitors = it }
Expand All @@ -105,6 +102,13 @@ class RestIndexMonitorAction(
return "index_monitor_action"
}

override fun routes(): List<Route> {
return listOf(
Route(POST, AlertingPlugin.MONITOR_BASE_URI), // Create a new monitor
Route(PUT, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}")
)
}

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val id = request.param("monitorID", Monitor.NO_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.elasticsearch.rest.BaseRestHandler
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
import org.elasticsearch.rest.BytesRestResponse
import org.elasticsearch.rest.RestChannel
import org.elasticsearch.rest.RestController
import org.elasticsearch.rest.RestHandler.Route
import org.elasticsearch.rest.RestRequest
import org.elasticsearch.rest.RestRequest.Method.GET
import org.elasticsearch.rest.RestRequest.Method.POST
Expand All @@ -45,17 +45,20 @@ import java.io.IOException
/**
* Rest handlers to search for monitors.
*/
class RestSearchMonitorAction(controller: RestController) : BaseRestHandler() {
init {
// Search for monitors
controller.registerHandler(POST, "${AlertingPlugin.MONITOR_BASE_URI}/_search", this)
controller.registerHandler(GET, "${AlertingPlugin.MONITOR_BASE_URI}/_search", this)
}
class RestSearchMonitorAction : BaseRestHandler() {

override fun getName(): String {
return "search_monitor_action"
}

override fun routes(): List<Route> {
return listOf(
// Search for monitors
Route(POST, "${AlertingPlugin.MONITOR_BASE_URI}/_search"),
Route(GET, "${AlertingPlugin.MONITOR_BASE_URI}/_search")
)
}

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val searchSourceBuilder = SearchSourceBuilder()
Expand Down
Loading

0 comments on commit 9f405c2

Please sign in to comment.