From 5307c44c9215efc98032ec989ff715f16fb984dc Mon Sep 17 00:00:00 2001 From: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com> Date: Wed, 15 Jan 2025 21:25:38 -0800 Subject: [PATCH 1/3] feat: create request and response classes for monitor status update Signed-off-by: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com> --- .../alerting/action/AlertingActions.kt | 5 ++ .../action/UpdateMonitorStateRequest.kt | 52 +++++++++++++++ .../action/UpdateMonitorStateResponse.kt | 64 +++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt create mode 100644 src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt index fcf98261..6d6443e1 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt @@ -24,6 +24,7 @@ object AlertingActions { const val INDEX_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/write" const val SEARCH_COMMENTS_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/search" const val DELETE_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/delete" + const val UPDATE_MONITOR_STATE_ACTION_NAME = "cluster:admin/opensearch/alerting/monitor/toggle" @JvmField val INDEX_MONITOR_ACTION_TYPE = @@ -88,4 +89,8 @@ object AlertingActions { @JvmField val DELETE_COMMENT_ACTION_TYPE = ActionType(DELETE_COMMENT_ACTION_NAME, ::DeleteCommentResponse) + + @JvmField + val UPDATE_MONITOR_STATE_ACTION_TYPE = + ActionType(UPDATE_MONITOR_STATE_ACTION_NAME, ::UpdateMonitorStateResponse) } diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt new file mode 100644 index 00000000..d55569cb --- /dev/null +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt @@ -0,0 +1,52 @@ +package org.opensearch.commons.alerting.action + +import org.opensearch.action.ActionRequest +import org.opensearch.action.ActionRequestValidationException +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.rest.RestRequest +import java.io.IOException + +class UpdateMonitorStateRequest : ActionRequest { + val monitorId: String + val enabled: Boolean + val seqNo: Long + val primaryTerm: Long + val method: RestRequest.Method + + constructor( + monitorId: String, + enabled: Boolean, + seqNo: Long, + primaryTerm: Long, + method: RestRequest.Method, + ) : super() { + this.monitorId = monitorId + this.enabled = enabled + this.seqNo = seqNo + this.primaryTerm = primaryTerm + this.method = method + } + + @Throws(IOException::class) + constructor(sin: StreamInput) : this ( + monitorId = sin.readString(), + enabled = sin.readBoolean(), + seqNo = sin.readLong(), + primaryTerm = sin.readLong(), + method = sin.readEnum(RestRequest.Method::class.java), + ) + + @Throws(IOException::class) + override fun writeTo(out: StreamOutput) { + out.writeString(monitorId) + out.writeBoolean(enabled) + out.writeLong(seqNo) + out.writeLong(primaryTerm) + out.writeEnum(method) + } + + override fun validate(): ActionRequestValidationException? { + return null + } +} diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt new file mode 100644 index 00000000..fa9be5b1 --- /dev/null +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt @@ -0,0 +1,64 @@ +package org.opensearch.commons.alerting.action + +import org.opensearch.commons.alerting.model.Monitor +import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID +import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM +import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO +import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION +import org.opensearch.commons.notifications.action.BaseResponse +import org.opensearch.core.common.io.stream.StreamInput +import org.opensearch.core.common.io.stream.StreamOutput +import org.opensearch.core.xcontent.ToXContent.Params +import org.opensearch.core.xcontent.XContentBuilder +import java.io.IOException + +class UpdateMonitorStateResponse : BaseResponse { + var id: String + var version: Long + var seqNo: Long + var primaryTerm: Long + var monitor: Monitor + + constructor( + id: String, + version: Long, + seqNo: Long, + primaryTerm: Long, + monitor: Monitor + ) : super() { + this.id = id + this.version = version + this.seqNo = seqNo + this.primaryTerm = primaryTerm + this.monitor = monitor + } + + @Throws(IOException::class) + constructor(sin: StreamInput) : this( + sin.readString(), // id + sin.readLong(), // version + sin.readLong(), // seqNo + sin.readLong(), // primaryTerm + Monitor.readFrom(sin) as Monitor // monitor + ) + + @Throws(IOException::class) + override fun writeTo(out: StreamOutput) { + out.writeString(id) + out.writeLong(version) + out.writeLong(seqNo) + out.writeLong(primaryTerm) + monitor.writeTo(out) + } + + @Throws(IOException::class) + override fun toXContent(builder: XContentBuilder, params: Params): XContentBuilder { + return builder.startObject() + .field(_ID, id) + .field(_VERSION, version) + .field(_SEQ_NO, seqNo) + .field(_PRIMARY_TERM, primaryTerm) + .field("Monitor", monitor) + .endObject() + } +} From 32c7c8475d6988827ebd5ee2e5d7801c96201422 Mon Sep 17 00:00:00 2001 From: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:45:23 -0800 Subject: [PATCH 2/3] feat: add request and response classes to implement toggle monitor state api in alerting Signed-off-by: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com> --- .../opensearch/commons/alerting/action/AlertingActions.kt | 6 +++--- ...UpdateMonitorStateRequest.kt => ToggleMonitorRequest.kt} | 2 +- ...dateMonitorStateResponse.kt => ToggleMonitorResponse.kt} | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/main/kotlin/org/opensearch/commons/alerting/action/{UpdateMonitorStateRequest.kt => ToggleMonitorRequest.kt} (96%) rename src/main/kotlin/org/opensearch/commons/alerting/action/{UpdateMonitorStateResponse.kt => ToggleMonitorResponse.kt} (97%) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt index 6d6443e1..35f6d04c 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt @@ -24,7 +24,7 @@ object AlertingActions { const val INDEX_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/write" const val SEARCH_COMMENTS_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/search" const val DELETE_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/delete" - const val UPDATE_MONITOR_STATE_ACTION_NAME = "cluster:admin/opensearch/alerting/monitor/toggle" + const val TOGGLE_MONITOR_ACTION_NAME = "cluster:admin/opensearch/alerting/monitor/toggle" @JvmField val INDEX_MONITOR_ACTION_TYPE = @@ -91,6 +91,6 @@ object AlertingActions { ActionType(DELETE_COMMENT_ACTION_NAME, ::DeleteCommentResponse) @JvmField - val UPDATE_MONITOR_STATE_ACTION_TYPE = - ActionType(UPDATE_MONITOR_STATE_ACTION_NAME, ::UpdateMonitorStateResponse) + val TOGGLE_MONITOR_ACTION_TYPE = + ActionType(TOGGLE_MONITOR_ACTION_NAME, ::ToggleMonitorResponse) } diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt similarity index 96% rename from src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt rename to src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt index d55569cb..2b81f11d 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt @@ -7,7 +7,7 @@ import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.rest.RestRequest import java.io.IOException -class UpdateMonitorStateRequest : ActionRequest { +class ToggleMonitorRequest : ActionRequest { val monitorId: String val enabled: Boolean val seqNo: Long diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorResponse.kt similarity index 97% rename from src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt rename to src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorResponse.kt index fa9be5b1..0dfd9f19 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorResponse.kt @@ -12,7 +12,7 @@ import org.opensearch.core.xcontent.ToXContent.Params import org.opensearch.core.xcontent.XContentBuilder import java.io.IOException -class UpdateMonitorStateResponse : BaseResponse { +class ToggleMonitorResponse : BaseResponse { var id: String var version: Long var seqNo: Long From e3805a1495815ee1d83f968b340d5c09f69ea40b Mon Sep 17 00:00:00 2001 From: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:32:21 -0800 Subject: [PATCH 3/3] fix: fix lint issues Signed-off-by: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com> --- .../commons/alerting/action/ToggleMonitorRequest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt index 2b81f11d..5572b7b9 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/ToggleMonitorRequest.kt @@ -19,7 +19,7 @@ class ToggleMonitorRequest : ActionRequest { enabled: Boolean, seqNo: Long, primaryTerm: Long, - method: RestRequest.Method, + method: RestRequest.Method ) : super() { this.monitorId = monitorId this.enabled = enabled @@ -34,7 +34,7 @@ class ToggleMonitorRequest : ActionRequest { enabled = sin.readBoolean(), seqNo = sin.readLong(), primaryTerm = sin.readLong(), - method = sin.readEnum(RestRequest.Method::class.java), + method = sin.readEnum(RestRequest.Method::class.java) ) @Throws(IOException::class)