From fcb853e8543240629fff568d3d5712a65a287f47 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Wed, 21 Jun 2023 09:07:44 -0700 Subject: [PATCH] acknowledge chained alert request for workflow (#459) Signed-off-by: Surya Sashank Nistala --- .../action/AcknowledgeChainedAlertRequest.kt | 43 +++++++++++++++++++ .../AcknowledgeChainedAlertRequestTests.kt | 27 ++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequest.kt create mode 100644 src/test/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequestTests.kt diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequest.kt new file mode 100644 index 00000000..a89c6332 --- /dev/null +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequest.kt @@ -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 + + constructor( + workflowId: String, + alertIds: List, + ) : 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) + } +} diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequestTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequestTests.kt new file mode 100644 index 00000000..012e370e --- /dev/null +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequestTests.kt @@ -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) + } +}