Skip to content

Commit ada97ee

Browse files
committed
adding a bunch more models
1 parent c58c354 commit ada97ee

File tree

6 files changed

+182
-40
lines changed

6 files changed

+182
-40
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ object AlertingActions {
2828

2929
// Alerting V2
3030
const val INDEX_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/write"
31+
const val GET_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/get"
3132
const val SEARCH_MONITORS_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/search"
3233
const val DELETE_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/delete"
3334

@@ -99,6 +100,10 @@ object AlertingActions {
99100
val INDEX_MONITOR_V2_ACTION_TYPE =
100101
ActionType(INDEX_MONITOR_V2_ACTION_NAME, ::IndexMonitorV2Response)
101102

103+
@JvmField
104+
val GET_MONITOR_V2_ACTION_TYPE =
105+
ActionType(GET_MONITOR_V2_ACTION_NAME, ::GetMonitorV2Response)
106+
102107
@JvmField
103108
val SEARCH_MONITORS_V2_ACTION_TYPE =
104109
ActionType(SEARCH_MONITORS_V2_ACTION_NAME, ::SearchResponse)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.opensearch.commons.alerting.action
2+
3+
import java.io.IOException
4+
import org.opensearch.action.ActionRequest
5+
import org.opensearch.action.ActionRequestValidationException
6+
import org.opensearch.core.common.io.stream.StreamInput
7+
import org.opensearch.core.common.io.stream.StreamOutput
8+
import org.opensearch.search.fetch.subphase.FetchSourceContext
9+
10+
class GetMonitorV2Request : ActionRequest {
11+
val monitorV2Id: String
12+
val version: Long
13+
val srcContext: FetchSourceContext?
14+
15+
constructor(
16+
monitorV2Id: String,
17+
version: Long,
18+
srcContext: FetchSourceContext?
19+
) : super() {
20+
this.monitorV2Id = monitorV2Id
21+
this.version = version
22+
this.srcContext = srcContext
23+
}
24+
25+
@Throws(IOException::class)
26+
constructor(sin: StreamInput) : this(
27+
sin.readString(), // monitorV2Id
28+
sin.readLong(), // version
29+
if (sin.readBoolean()) {
30+
FetchSourceContext(sin) // srcContext
31+
} else {
32+
null
33+
}
34+
)
35+
36+
override fun validate(): ActionRequestValidationException? {
37+
return null
38+
}
39+
40+
@Throws(IOException::class)
41+
override fun writeTo(out: StreamOutput) {
42+
out.writeString(monitorV2Id)
43+
out.writeLong(version)
44+
out.writeBoolean(srcContext != null)
45+
srcContext?.writeTo(out)
46+
}
47+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.opensearch.commons.alerting.action
2+
3+
import java.io.IOException
4+
import org.opensearch.commons.alerting.model.MonitorV2
5+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID
6+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM
7+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO
8+
import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION
9+
import org.opensearch.commons.notifications.action.BaseResponse
10+
import org.opensearch.core.common.io.stream.StreamInput
11+
import org.opensearch.core.common.io.stream.StreamOutput
12+
import org.opensearch.core.xcontent.ToXContent
13+
import org.opensearch.core.xcontent.XContentBuilder
14+
15+
class GetMonitorV2Response : BaseResponse {
16+
var id: String
17+
var version: Long
18+
var seqNo: Long
19+
var primaryTerm: Long
20+
var monitorV2: MonitorV2?
21+
22+
constructor(
23+
id: String,
24+
version: Long,
25+
seqNo: Long,
26+
primaryTerm: Long,
27+
monitorV2: MonitorV2?
28+
) : super() {
29+
this.id = id
30+
this.version = version
31+
this.seqNo = seqNo
32+
this.primaryTerm = primaryTerm
33+
this.monitorV2 = monitorV2
34+
}
35+
36+
@Throws(IOException::class)
37+
constructor(sin: StreamInput) : this(
38+
id = sin.readString(), // id
39+
version = sin.readLong(), // version
40+
seqNo = sin.readLong(), // seqNo
41+
primaryTerm = sin.readLong(), // primaryTerm
42+
monitorV2 = if (sin.readBoolean()) {
43+
MonitorV2.readFrom(sin) // monitorV2
44+
} else {
45+
null
46+
}
47+
)
48+
49+
@Throws(IOException::class)
50+
override fun writeTo(out: StreamOutput) {
51+
out.writeString(id)
52+
out.writeLong(version)
53+
out.writeLong(seqNo)
54+
out.writeLong(primaryTerm)
55+
if (monitorV2 != null) {
56+
out.writeBoolean(true)
57+
monitorV2?.writeTo(out)
58+
} else {
59+
out.writeBoolean(false)
60+
}
61+
}
62+
63+
@Throws(IOException::class)
64+
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
65+
builder.startObject()
66+
.field(_ID, id)
67+
.field(_VERSION, version)
68+
.field(_SEQ_NO, seqNo)
69+
.field(_PRIMARY_TERM, primaryTerm)
70+
if (monitorV2 != null) {
71+
builder.field("monitorV2", monitorV2)
72+
}
73+
return builder.endObject()
74+
}
75+
}

src/main/kotlin/org/opensearch/commons/alerting/model/MonitorV2.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ interface MonitorV2 : ScheduledJob {
3030
override val schedule: Schedule
3131
override val lastUpdateTime: Instant // required for scheduled job maintenance
3232
override val enabledTime: Instant? // required for scheduled job maintenance
33-
val labels: Map<String, String>?
3433
val triggers: List<TriggerV2>
3534

35+
fun asTemplateArg(): Map<String, Any?>
36+
3637
enum class MonitorV2Type(val value: String) {
3738
PPL_MONITOR(PPL_MONITOR_TYPE);
3839

@@ -47,8 +48,6 @@ interface MonitorV2 : ScheduledJob {
4748
}
4849
}
4950

50-
fun asTemplateArg(): Map<String, Any?>
51-
5251
companion object {
5352
// scheduled job field names
5453
const val TYPE_FIELD = "type"
@@ -61,7 +60,6 @@ interface MonitorV2 : ScheduledJob {
6160
const val SCHEDULE_FIELD = "schedule"
6261
const val LAST_UPDATE_TIME_FIELD = "last_update_time"
6362
const val ENABLED_TIME_FIELD = "enabled_time"
64-
const val LABELS_FIELD = "labels"
6563
const val TRIGGERS_FIELD = "triggers"
6664

6765
// default values
@@ -108,14 +106,5 @@ interface MonitorV2 : ScheduledJob {
108106
}
109107
}
110108
}
111-
112-
@Suppress("UNCHECKED_CAST")
113-
fun convertLabelsMap(map: Map<String, Any>): Map<String, String> {
114-
if (map.values.all { it is String }) {
115-
return map as Map<String, String>
116-
} else {
117-
throw ClassCastException("at least one value in the map was not a string: $map")
118-
}
119-
}
120109
}
121110
}

0 commit comments

Comments
 (0)