Skip to content

Commit

Permalink
Accept of list of monitor ids in findings and alerts request dtos (#277)
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
  • Loading branch information
eirsep authored Oct 10, 2022
1 parent 7a91f54 commit c231644
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ class GetAlertsRequest : ActionRequest {
val alertState: String
val monitorId: String?
val alertIndex: String?
val monitorIds: List<String>?

constructor(
table: Table,
severityLevel: String,
alertState: String,
monitorId: String?,
alertIndex: String?
alertIndex: String?,
monitorIds: List<String>? = null
) : super() {
this.table = table
this.severityLevel = severityLevel
this.alertState = alertState
this.monitorId = monitorId
this.alertIndex = alertIndex
this.monitorIds = monitorIds
}

@Throws(IOException::class)
Expand All @@ -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? {
Expand All @@ -48,5 +52,6 @@ class GetAlertsRequest : ActionRequest {
out.writeString(alertState)
out.writeOptionalString(monitorId)
out.writeOptionalString(alertIndex)
out.writeOptionalStringCollection(monitorIds)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@ class GetFindingsRequest : ActionRequest {
val findingId: String?
val table: Table
val monitorId: String?
val monitorIds: List<String>?
val findingIndex: String?

constructor(
findingId: String?,
table: Table,
monitorId: String? = null,
findingIndexName: String? = null
findingIndexName: String? = null,
monitorIds: List<String>? = null
) : super() {
this.findingId = findingId
this.table = table
this.monitorId = monitorId
this.findingIndex = findingIndexName
this.monitorIds = monitorIds
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
findingId = sin.readOptionalString(),
table = Table.readFrom(sin),
monitorId = sin.readOptionalString(),
findingIndexName = sin.readOptionalString()
findingIndexName = sin.readOptionalString(),
monitorIds = sin.readOptionalStringList()
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -43,5 +47,6 @@ class GetFindingsRequest : ActionRequest {
table.writeTo(out)
out.writeOptionalString(monitorId)
out.writeOptionalString(findingIndex)
out.writeOptionalStringCollection(monitorIds)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit c231644

Please sign in to comment.