File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed
main/kotlin/org/opensearch/commons/alerting
test/kotlin/org/opensearch/commons/alerting/action Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import org.opensearch.commons.alerting.action.IndexMonitorRequest
2828import org.opensearch.commons.alerting.action.IndexMonitorResponse
2929import org.opensearch.commons.alerting.action.IndexWorkflowRequest
3030import org.opensearch.commons.alerting.action.IndexWorkflowResponse
31+ import org.opensearch.commons.alerting.action.PublishBatchFindingsRequest
3132import org.opensearch.commons.alerting.action.PublishFindingsRequest
3233import org.opensearch.commons.alerting.action.SearchMonitorRequest
3334import org.opensearch.commons.alerting.action.SubscribeFindingsResponse
@@ -268,6 +269,24 @@ object AlertingPluginInterface {
268269 )
269270 }
270271
272+ fun publishBatchFindings (
273+ client : NodeClient ,
274+ request : PublishBatchFindingsRequest ,
275+ listener : ActionListener <SubscribeFindingsResponse >
276+ ) {
277+ client.execute(
278+ AlertingActions .SUBSCRIBE_BATCH_FINDINGS_ACTION_TYPE ,
279+ request,
280+ wrapActionListener(listener) { response ->
281+ recreateObject(response) {
282+ SubscribeFindingsResponse (
283+ it
284+ )
285+ }
286+ }
287+ )
288+ }
289+
271290 /* *
272291 * Acknowledge Chained Alerts interface.
273292 * @param client Node client for making transport action
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ object AlertingActions {
1919 const val ACKNOWLEDGE_ALERTS_ACTION_NAME = " cluster:admin/opendistro/alerting/alerts/ack"
2020 const val ACKNOWLEDGE_CHAINED_ALERTS_ACTION_NAME = " cluster:admin/opendistro/alerting/chained_alerts/ack"
2121 const val SUBSCRIBE_FINDINGS_ACTION_NAME = " cluster:admin/opensearch/alerting/findings/subscribe"
22+ const val SUBSCRIBE_BATCH_FINDINGS_ACTION_NAME = " cluster:admin/opensearch/alerting/findings/batch/subscribe"
2223 const val GET_MONITOR_ACTION_NAME = " cluster:admin/opendistro/alerting/monitor/get"
2324 const val SEARCH_MONITORS_ACTION_NAME = " cluster:admin/opendistro/alerting/monitor/search"
2425 const val INDEX_COMMENT_ACTION_NAME = " cluster:admin/opensearch/alerting/comments/write"
@@ -65,6 +66,10 @@ object AlertingActions {
6566 val SUBSCRIBE_FINDINGS_ACTION_TYPE =
6667 ActionType (SUBSCRIBE_FINDINGS_ACTION_NAME , ::SubscribeFindingsResponse )
6768
69+ @JvmField
70+ val SUBSCRIBE_BATCH_FINDINGS_ACTION_TYPE =
71+ ActionType (SUBSCRIBE_BATCH_FINDINGS_ACTION_NAME , ::SubscribeFindingsResponse )
72+
6873 @JvmField
6974 val ACKNOWLEDGE_CHAINED_ALERTS_ACTION_TYPE =
7075 ActionType (ACKNOWLEDGE_CHAINED_ALERTS_ACTION_NAME , ::AcknowledgeAlertResponse )
Original file line number Diff line number Diff line change 1+ package org.opensearch.commons.alerting.action
2+
3+ import org.opensearch.action.ActionRequest
4+ import org.opensearch.action.ActionRequestValidationException
5+ import org.opensearch.commons.alerting.model.Finding
6+ import org.opensearch.core.common.io.stream.StreamInput
7+ import org.opensearch.core.common.io.stream.StreamOutput
8+ import java.io.IOException
9+ import java.util.Collections
10+
11+ class PublishBatchFindingsRequest : ActionRequest {
12+
13+ val monitorId: String
14+
15+ val findings: List <Finding >
16+
17+ constructor (
18+ monitorId: String ,
19+ findings: List <Finding >
20+ ) : super () {
21+ this .monitorId = monitorId
22+ this .findings = findings
23+ }
24+
25+ @Throws(IOException ::class )
26+ constructor (sin: StreamInput ) : this (
27+ monitorId = sin.readString(),
28+ findings = Collections .unmodifiableList(sin.readList(::Finding ))
29+ )
30+
31+ override fun validate (): ActionRequestValidationException ? {
32+ return null
33+ }
34+
35+ override fun writeTo (out : StreamOutput ) {
36+ out .writeString(monitorId)
37+ out .writeCollection(findings)
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ package org.opensearch.commons.alerting.action
2+
3+ import org.junit.jupiter.api.Assertions.assertEquals
4+ import org.junit.jupiter.api.Assertions.assertNotNull
5+ import org.junit.jupiter.api.Test
6+ import org.opensearch.common.io.stream.BytesStreamOutput
7+ import org.opensearch.commons.alerting.randomFinding
8+ import org.opensearch.core.common.io.stream.StreamInput
9+
10+ class PublishBatchFindingsRequestTests {
11+
12+ @Test
13+ fun `test publish batch findings request` () {
14+ val findings = listOf (randomFinding(), randomFinding())
15+ val monitorId = " mid"
16+ val req = PublishBatchFindingsRequest (monitorId, findings)
17+ assertNotNull(req)
18+ assertEquals(monitorId, req.monitorId)
19+ assertEquals(findings, req.findings)
20+
21+ val out = BytesStreamOutput ()
22+ req.writeTo(out )
23+ val sin = StreamInput .wrap(out .bytes().toBytesRef().bytes)
24+ val newReq = PublishBatchFindingsRequest (sin)
25+ assertEquals(monitorId, newReq.monitorId)
26+ assertEquals(findings.size, newReq.findings.size)
27+ assert (newReq.findings.zip(findings).all { (f1, f2) -> f1.id == f2.id })
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments