Skip to content

Commit 5307c44

Browse files
committed
feat: create request and response classes for monitor status update
Signed-off-by: vikhy-aws <[email protected]>
1 parent cb9d38b commit 5307c44

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ object AlertingActions {
2424
const val INDEX_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/write"
2525
const val SEARCH_COMMENTS_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/search"
2626
const val DELETE_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/delete"
27+
const val UPDATE_MONITOR_STATE_ACTION_NAME = "cluster:admin/opensearch/alerting/monitor/toggle"
2728

2829
@JvmField
2930
val INDEX_MONITOR_ACTION_TYPE =
@@ -88,4 +89,8 @@ object AlertingActions {
8889
@JvmField
8990
val DELETE_COMMENT_ACTION_TYPE =
9091
ActionType(DELETE_COMMENT_ACTION_NAME, ::DeleteCommentResponse)
92+
93+
@JvmField
94+
val UPDATE_MONITOR_STATE_ACTION_TYPE =
95+
ActionType(UPDATE_MONITOR_STATE_ACTION_NAME, ::UpdateMonitorStateResponse)
9196
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.opensearch.commons.alerting.action
2+
3+
import org.opensearch.action.ActionRequest
4+
import org.opensearch.action.ActionRequestValidationException
5+
import org.opensearch.core.common.io.stream.StreamInput
6+
import org.opensearch.core.common.io.stream.StreamOutput
7+
import org.opensearch.rest.RestRequest
8+
import java.io.IOException
9+
10+
class UpdateMonitorStateRequest : ActionRequest {
11+
val monitorId: String
12+
val enabled: Boolean
13+
val seqNo: Long
14+
val primaryTerm: Long
15+
val method: RestRequest.Method
16+
17+
constructor(
18+
monitorId: String,
19+
enabled: Boolean,
20+
seqNo: Long,
21+
primaryTerm: Long,
22+
method: RestRequest.Method,
23+
) : super() {
24+
this.monitorId = monitorId
25+
this.enabled = enabled
26+
this.seqNo = seqNo
27+
this.primaryTerm = primaryTerm
28+
this.method = method
29+
}
30+
31+
@Throws(IOException::class)
32+
constructor(sin: StreamInput) : this (
33+
monitorId = sin.readString(),
34+
enabled = sin.readBoolean(),
35+
seqNo = sin.readLong(),
36+
primaryTerm = sin.readLong(),
37+
method = sin.readEnum(RestRequest.Method::class.java),
38+
)
39+
40+
@Throws(IOException::class)
41+
override fun writeTo(out: StreamOutput) {
42+
out.writeString(monitorId)
43+
out.writeBoolean(enabled)
44+
out.writeLong(seqNo)
45+
out.writeLong(primaryTerm)
46+
out.writeEnum(method)
47+
}
48+
49+
override fun validate(): ActionRequestValidationException? {
50+
return null
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.opensearch.commons.alerting.action
2+
3+
import org.opensearch.commons.alerting.model.Monitor
4+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID
5+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM
6+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO
7+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION
8+
import org.opensearch.commons.notifications.action.BaseResponse
9+
import org.opensearch.core.common.io.stream.StreamInput
10+
import org.opensearch.core.common.io.stream.StreamOutput
11+
import org.opensearch.core.xcontent.ToXContent.Params
12+
import org.opensearch.core.xcontent.XContentBuilder
13+
import java.io.IOException
14+
15+
class UpdateMonitorStateResponse : BaseResponse {
16+
var id: String
17+
var version: Long
18+
var seqNo: Long
19+
var primaryTerm: Long
20+
var monitor: Monitor
21+
22+
constructor(
23+
id: String,
24+
version: Long,
25+
seqNo: Long,
26+
primaryTerm: Long,
27+
monitor: Monitor
28+
) : super() {
29+
this.id = id
30+
this.version = version
31+
this.seqNo = seqNo
32+
this.primaryTerm = primaryTerm
33+
this.monitor = monitor
34+
}
35+
36+
@Throws(IOException::class)
37+
constructor(sin: StreamInput) : this(
38+
sin.readString(), // id
39+
sin.readLong(), // version
40+
sin.readLong(), // seqNo
41+
sin.readLong(), // primaryTerm
42+
Monitor.readFrom(sin) as Monitor // monitor
43+
)
44+
45+
@Throws(IOException::class)
46+
override fun writeTo(out: StreamOutput) {
47+
out.writeString(id)
48+
out.writeLong(version)
49+
out.writeLong(seqNo)
50+
out.writeLong(primaryTerm)
51+
monitor.writeTo(out)
52+
}
53+
54+
@Throws(IOException::class)
55+
override fun toXContent(builder: XContentBuilder, params: Params): XContentBuilder {
56+
return builder.startObject()
57+
.field(_ID, id)
58+
.field(_VERSION, version)
59+
.field(_SEQ_NO, seqNo)
60+
.field(_PRIMARY_TERM, primaryTerm)
61+
.field("Monitor", monitor)
62+
.endObject()
63+
}
64+
}

0 commit comments

Comments
 (0)