From 311d7f6202999ce75a478c1f6f28597f01cae2c6 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Mon, 10 Oct 2022 14:34:18 -0700 Subject: [PATCH] Accept of list of monitor ids in findings and alerts request dtos (#277) Signed-off-by: Surya Sashank Nistala --- .../commons/alerting/action/GetAlertsRequest.kt | 9 +++++++-- .../commons/alerting/action/GetFindingsRequest.kt | 9 +++++++-- .../commons/alerting/action/GetAlertsRequestTests.kt | 5 ++++- .../commons/alerting/action/GetFindingsRequestTests.kt | 5 ++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt index bdda4e93..5804ff08 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt @@ -13,19 +13,22 @@ class GetAlertsRequest : ActionRequest { val alertState: String val monitorId: String? val alertIndex: String? + val monitorIds: List? constructor( table: Table, severityLevel: String, alertState: String, monitorId: String?, - alertIndex: String? + alertIndex: String?, + monitorIds: List? = null ) : super() { this.table = table this.severityLevel = severityLevel this.alertState = alertState this.monitorId = monitorId this.alertIndex = alertIndex + this.monitorIds = monitorIds } @Throws(IOException::class) @@ -34,7 +37,8 @@ class GetAlertsRequest : ActionRequest { severityLevel = sin.readString(), alertState = sin.readString(), monitorId = sin.readOptionalString(), - alertIndex = sin.readOptionalString() + alertIndex = sin.readOptionalString(), + monitorIds = sin.readOptionalStringList() ) override fun validate(): ActionRequestValidationException? { @@ -48,5 +52,6 @@ class GetAlertsRequest : ActionRequest { out.writeString(alertState) out.writeOptionalString(monitorId) out.writeOptionalString(alertIndex) + out.writeOptionalStringCollection(monitorIds) } } diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt index 4f852a64..ae65ca26 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -11,18 +11,21 @@ class GetFindingsRequest : ActionRequest { val findingId: String? val table: Table val monitorId: String? + val monitorIds: List? val findingIndex: String? constructor( findingId: String?, table: Table, monitorId: String? = null, - findingIndexName: String? = null + findingIndexName: String? = null, + monitorIds: List? = null ) : super() { this.findingId = findingId this.table = table this.monitorId = monitorId this.findingIndex = findingIndexName + this.monitorIds = monitorIds } @Throws(IOException::class) @@ -30,7 +33,8 @@ class GetFindingsRequest : ActionRequest { findingId = sin.readOptionalString(), table = Table.readFrom(sin), monitorId = sin.readOptionalString(), - findingIndexName = sin.readOptionalString() + findingIndexName = sin.readOptionalString(), + monitorIds = sin.readOptionalStringList() ) override fun validate(): ActionRequestValidationException? { @@ -43,5 +47,6 @@ class GetFindingsRequest : ActionRequest { table.writeTo(out) out.writeOptionalString(monitorId) out.writeOptionalString(findingIndex) + out.writeOptionalStringCollection(monitorIds) } } diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt index 3b2024a5..43c2f61c 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt @@ -3,6 +3,7 @@ package org.opensearch.commons.alerting.action import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.common.io.stream.StreamInput @@ -15,7 +16,7 @@ internal class GetAlertsRequestTests { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetAlertsRequest(table, "1", "active", null, null) + val req = GetAlertsRequest(table, "1", "active", null, null, listOf("1", "2")) assertNotNull(req) val out = BytesStreamOutput() @@ -27,6 +28,8 @@ internal class GetAlertsRequestTests { assertEquals("active", newReq.alertState) assertNull(newReq.monitorId) assertEquals(table, newReq.table) + assertTrue(newReq.monitorIds!!.contains("1")) + assertTrue(newReq.monitorIds!!.contains("2")) } @Test diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt index 54fab737..f83cb8de 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt @@ -3,6 +3,7 @@ package org.opensearch.commons.alerting.action import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.common.io.stream.StreamInput @@ -15,7 +16,7 @@ internal class GetFindingsRequestTests { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "finding_index_name") + val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2")) assertNotNull(req) val out = BytesStreamOutput() @@ -27,6 +28,8 @@ internal class GetFindingsRequestTests { assertEquals("2121", newReq.findingId) assertEquals("finding_index_name", newReq.findingIndex) assertEquals(table, newReq.table) + assertTrue(newReq.monitorIds!!.contains("1")) + assertTrue(newReq.monitorIds!!.contains("2")) } @Test