Skip to content

Commit

Permalink
acknowledge chained alert request for workflow (#459)
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <[email protected]>
(cherry picked from commit fcb853e)
  • Loading branch information
eirsep authored and github-actions[bot] committed Jun 21, 2023
1 parent 03505f0 commit 6e3efd8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.commons.alerting.action

import org.opensearch.action.ActionRequest
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import java.io.IOException
import java.util.Collections

/** Request DTO for acknowledging chained alerts generated by workflow.*/
class AcknowledgeChainedAlertRequest : ActionRequest {
val workflowId: String
val alertIds: List<String>

constructor(
workflowId: String,
alertIds: List<String>,
) : super() {
this.workflowId = workflowId
this.alertIds = alertIds
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
sin.readString(), // workflowId
Collections.unmodifiableList(sin.readStringList()), // alertIds
)

override fun validate(): ActionRequestValidationException? {
return null
}

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(workflowId)
out.writeStringCollection(alertIds)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

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.Test
import org.opensearch.common.io.stream.BytesStreamOutput
import org.opensearch.common.io.stream.StreamInput

class AcknowledgeChainedAlertRequestTests {

@Test
fun `test acknowledge chained alert request`() {
val req = AcknowledgeChainedAlertRequest("1234", mutableListOf("1", "2", "3", "4"))
assertNotNull(req)
val out = BytesStreamOutput()
req.writeTo(out)
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newReq = AcknowledgeChainedAlertRequest(sin)
assertEquals("1234", newReq.workflowId)
assertEquals(4, newReq.alertIds.size)
}
}

0 comments on commit 6e3efd8

Please sign in to comment.