Skip to content

Commit fcb853e

Browse files
authored
acknowledge chained alert request for workflow (#459)
Signed-off-by: Surya Sashank Nistala <[email protected]>
1 parent 5ef9b55 commit fcb853e

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.commons.alerting.action
7+
8+
import org.opensearch.action.ActionRequest
9+
import org.opensearch.action.ActionRequestValidationException
10+
import org.opensearch.common.io.stream.StreamInput
11+
import org.opensearch.common.io.stream.StreamOutput
12+
import java.io.IOException
13+
import java.util.Collections
14+
15+
/** Request DTO for acknowledging chained alerts generated by workflow.*/
16+
class AcknowledgeChainedAlertRequest : ActionRequest {
17+
val workflowId: String
18+
val alertIds: List<String>
19+
20+
constructor(
21+
workflowId: String,
22+
alertIds: List<String>,
23+
) : super() {
24+
this.workflowId = workflowId
25+
this.alertIds = alertIds
26+
}
27+
28+
@Throws(IOException::class)
29+
constructor(sin: StreamInput) : this(
30+
sin.readString(), // workflowId
31+
Collections.unmodifiableList(sin.readStringList()), // alertIds
32+
)
33+
34+
override fun validate(): ActionRequestValidationException? {
35+
return null
36+
}
37+
38+
@Throws(IOException::class)
39+
override fun writeTo(out: StreamOutput) {
40+
out.writeString(workflowId)
41+
out.writeStringCollection(alertIds)
42+
}
43+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.commons.alerting.action
7+
8+
import org.junit.jupiter.api.Assertions.assertEquals
9+
import org.junit.jupiter.api.Assertions.assertNotNull
10+
import org.junit.jupiter.api.Test
11+
import org.opensearch.common.io.stream.BytesStreamOutput
12+
import org.opensearch.common.io.stream.StreamInput
13+
14+
class AcknowledgeChainedAlertRequestTests {
15+
16+
@Test
17+
fun `test acknowledge chained alert request`() {
18+
val req = AcknowledgeChainedAlertRequest("1234", mutableListOf("1", "2", "3", "4"))
19+
assertNotNull(req)
20+
val out = BytesStreamOutput()
21+
req.writeTo(out)
22+
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
23+
val newReq = AcknowledgeChainedAlertRequest(sin)
24+
assertEquals("1234", newReq.workflowId)
25+
assertEquals(4, newReq.alertIds.size)
26+
}
27+
}

0 commit comments

Comments
 (0)