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
@@ -0,0 +1,10 @@
package org.opensearch.alerting.actionv2

import org.opensearch.action.ActionType

class DeleteMonitorV2Action private constructor() : ActionType<DeleteMonitorV2Response>(NAME, ::DeleteMonitorV2Response) {
companion object {
val INSTANCE = DeleteMonitorV2Action()
const val NAME = "cluster:admin/opensearch/alerting/v2/monitor/delete"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.opensearch.alerting.actionv2

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.alerting.actionv2

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,10 @@
package org.opensearch.alerting.actionv2

import org.opensearch.action.ActionType

class ExecuteMonitorV2Action private constructor() : ActionType<ExecuteMonitorV2Response>(NAME, ::ExecuteMonitorV2Response) {
companion object {
val INSTANCE = ExecuteMonitorV2Action()
const val NAME = "cluster:admin/opensearch/alerting/v2/monitor/execute"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.opensearch.alerting.actionv2

import org.opensearch.action.ActionRequest
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.action.ValidateActions
import org.opensearch.alerting.core.modelv2.MonitorV2
import org.opensearch.common.unit.TimeValue
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.alerting.actionv2

import org.opensearch.alerting.core.modelv2.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,10 @@
package org.opensearch.alerting.actionv2

import org.opensearch.action.ActionType

class GetMonitorV2Action private constructor() : ActionType<GetMonitorV2Response>(NAME, ::GetMonitorV2Response) {
companion object {
val INSTANCE = GetMonitorV2Action()
const val NAME = "cluster:admin/opensearch/alerting/v2/monitor/get"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.opensearch.alerting.actionv2

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.alerting.actionv2

import org.opensearch.alerting.core.modelv2.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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.opensearch.alerting.actionv2

import org.opensearch.action.ActionType

class IndexMonitorV2Action private constructor() : ActionType<IndexMonitorV2Response>(NAME, ::IndexMonitorV2Response) {
companion object {
val INSTANCE = IndexMonitorV2Action()
const val NAME = "cluster:admin/opensearch/alerting/v2/monitor/write"
}
}
Loading
Loading