Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.opensearch.action.ActionType
import org.opensearch.action.search.SearchResponse

object AlertingActions {
// Alerting V1
const val INDEX_MONITOR_ACTION_NAME = "cluster:admin/opendistro/alerting/monitor/write"
const val INDEX_WORKFLOW_ACTION_NAME = "cluster:admin/opensearch/alerting/workflow/write"
const val GET_ALERTS_ACTION_NAME = "cluster:admin/opendistro/alerting/alerts/get"
Expand All @@ -25,6 +26,13 @@ object AlertingActions {
const val SEARCH_COMMENTS_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/search"
const val DELETE_COMMENT_ACTION_NAME = "cluster:admin/opensearch/alerting/comments/delete"

// Alerting V2
const val INDEX_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/write"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about alertV2 APIs?

const val GET_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/get"
const val SEARCH_MONITORS_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/search"
const val DELETE_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/delete"
const val EXECUTE_MONITOR_V2_ACTION_NAME = "cluster:admin/opensearch/alerting/v2/monitor/execute"

@JvmField
val INDEX_MONITOR_ACTION_TYPE =
ActionType(INDEX_MONITOR_ACTION_NAME, ::IndexMonitorResponse)
Expand Down Expand Up @@ -88,4 +96,24 @@ object AlertingActions {
@JvmField
val DELETE_COMMENT_ACTION_TYPE =
ActionType(DELETE_COMMENT_ACTION_NAME, ::DeleteCommentResponse)

@JvmField
val INDEX_MONITOR_V2_ACTION_TYPE =
ActionType(INDEX_MONITOR_V2_ACTION_NAME, ::IndexMonitorV2Response)

@JvmField
val GET_MONITOR_V2_ACTION_TYPE =
ActionType(GET_MONITOR_V2_ACTION_NAME, ::GetMonitorV2Response)

@JvmField
val SEARCH_MONITORS_V2_ACTION_TYPE =
ActionType(SEARCH_MONITORS_V2_ACTION_NAME, ::SearchResponse)

@JvmField
val DELETE_MONITOR_V2_ACTION_TYPE =
ActionType(DELETE_MONITOR_V2_ACTION_NAME, ::DeleteMonitorV2Response)

@JvmField
val EXECUTE_MONITOR_V2_ACTION_TYPE =
ActionType(EXECUTE_MONITOR_V2_ACTION_NAME, ::ExecuteMonitorV2Response)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.opensearch.commons.alerting.action

import org.opensearch.action.ActionRequest
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.action.support.WriteRequest
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import java.io.IOException

class DeleteMonitorV2Request : ActionRequest {
val monitorV2Id: String
val refreshPolicy: WriteRequest.RefreshPolicy

constructor(monitorV2Id: String, refreshPolicy: WriteRequest.RefreshPolicy) : super() {
this.monitorV2Id = monitorV2Id
this.refreshPolicy = refreshPolicy
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
monitorV2Id = sin.readString(),
refreshPolicy = WriteRequest.RefreshPolicy.readFrom(sin)
)

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

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(monitorV2Id)
refreshPolicy.writeTo(out)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.opensearch.commons.alerting.action

import org.opensearch.commons.alerting.util.IndexUtils
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
import org.opensearch.core.xcontent.XContentBuilder

class DeleteMonitorV2Response : BaseResponse {
var id: String
var version: Long

constructor(
id: String,
version: Long
) : super() {
this.id = id
this.version = version
}

constructor(sin: StreamInput) : this(
sin.readString(), // id
sin.readLong() // version
)

override fun writeTo(out: StreamOutput) {
out.writeString(id)
out.writeLong(version)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject()
.field(IndexUtils._ID, id)
.field(IndexUtils._VERSION, version)
.endObject()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.opensearch.commons.alerting.action

import org.opensearch.action.ActionRequest
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.action.ValidateActions
import org.opensearch.common.unit.TimeValue
import org.opensearch.commons.alerting.model.MonitorV2
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import java.io.IOException

class ExecuteMonitorV2Request : ActionRequest {
val dryrun: Boolean
val monitorId: String? // exactly one of monitorId or monitor must be non-null
val monitorV2: MonitorV2?
val requestStart: TimeValue?
val requestEnd: TimeValue

constructor(
dryrun: Boolean,
monitorId: String?,
monitorV2: MonitorV2?,
requestStart: TimeValue? = null,
requestEnd: TimeValue
) : super() {
this.dryrun = dryrun
this.monitorId = monitorId
this.monitorV2 = monitorV2
this.requestStart = requestStart
this.requestEnd = requestEnd
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
sin.readBoolean(), // dryrun
sin.readOptionalString(), // monitorId
if (sin.readBoolean()) {
MonitorV2.readFrom(sin) // monitor
} else {
null
},
sin.readOptionalTimeValue(),
sin.readTimeValue() // requestEnd
)

override fun validate(): ActionRequestValidationException? =
if (monitorV2 == null && monitorId == null) {
ValidateActions.addValidationError("Neither a monitor ID nor monitor object was supplied", null)
} else {
null
}

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeBoolean(dryrun)
out.writeOptionalString(monitorId)
if (monitorV2 != null) {
out.writeBoolean(true)
monitorV2.writeTo(out)
} else {
out.writeBoolean(false)
}
out.writeOptionalTimeValue(requestStart)
out.writeTimeValue(requestEnd)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.opensearch.commons.alerting.action

import org.opensearch.commons.alerting.model.MonitorV2RunResult
import org.opensearch.core.action.ActionResponse
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.ToXContentObject
import org.opensearch.core.xcontent.XContentBuilder
import java.io.IOException

class ExecuteMonitorV2Response : ActionResponse, ToXContentObject {
val monitorV2RunResult: MonitorV2RunResult<*>

constructor(monitorV2RunResult: MonitorV2RunResult<*>) : super() {
this.monitorV2RunResult = monitorV2RunResult
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
MonitorV2RunResult.readFrom(sin) // monitorRunResult
)

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
monitorV2RunResult.writeTo(out)
}

@Throws(IOException::class)
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return monitorV2RunResult.toXContent(builder, ToXContent.EMPTY_PARAMS)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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.search.fetch.subphase.FetchSourceContext
import java.io.IOException

class GetMonitorV2Request : ActionRequest {
val monitorV2Id: String
val version: Long
val srcContext: FetchSourceContext?

constructor(
monitorV2Id: String,
version: Long,
srcContext: FetchSourceContext?
) : super() {
this.monitorV2Id = monitorV2Id
this.version = version
this.srcContext = srcContext
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
sin.readString(), // monitorV2Id
sin.readLong(), // version
if (sin.readBoolean()) {
FetchSourceContext(sin) // srcContext
} else {
null
}
)

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

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(monitorV2Id)
out.writeLong(version)
out.writeBoolean(srcContext != null)
srcContext?.writeTo(out)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.opensearch.commons.alerting.action

import org.opensearch.commons.alerting.model.MonitorV2
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
import org.opensearch.core.xcontent.XContentBuilder
import java.io.IOException

class GetMonitorV2Response : BaseResponse {
var id: String
var version: Long
var seqNo: Long
var primaryTerm: Long
var monitorV2: MonitorV2?

constructor(
id: String,
version: Long,
seqNo: Long,
primaryTerm: Long,
monitorV2: MonitorV2?
) : super() {
this.id = id
this.version = version
this.seqNo = seqNo
this.primaryTerm = primaryTerm
this.monitorV2 = monitorV2
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
id = sin.readString(), // id
version = sin.readLong(), // version
seqNo = sin.readLong(), // seqNo
primaryTerm = sin.readLong(), // primaryTerm
monitorV2 = if (sin.readBoolean()) {
MonitorV2.readFrom(sin) // monitorV2
} else {
null
}
)

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(id)
out.writeLong(version)
out.writeLong(seqNo)
out.writeLong(primaryTerm)
if (monitorV2 != null) {
out.writeBoolean(true)
monitorV2?.writeTo(out)
} else {
out.writeBoolean(false)
}
}

@Throws(IOException::class)
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder.startObject()
.field(_ID, id)
.field(_VERSION, version)
.field(_SEQ_NO, seqNo)
.field(_PRIMARY_TERM, primaryTerm)
if (monitorV2 != null) {
builder.field("monitorV2", monitorV2)
}
return builder.endObject()
}
}
Loading
Loading