-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
…ommon-utils (#566) * Add get monitor request/response Signed-off-by: Tyler Ohlsen <[email protected]> * Remove status from response; add to interface Signed-off-by: Tyler Ohlsen <[email protected]> * Add UT Signed-off-by: Tyler Ohlsen <[email protected]> * Repeat for search monitor action Signed-off-by: Tyler Ohlsen <[email protected]> --------- Signed-off-by: Tyler Ohlsen <[email protected]> (cherry picked from commit 2ff995b) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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 org.opensearch.search.fetch.subphase.FetchSourceContext | ||
import java.io.IOException | ||
|
||
class GetMonitorRequest : ActionRequest { | ||
val monitorId: String | ||
val version: Long | ||
val method: RestRequest.Method | ||
val srcContext: FetchSourceContext? | ||
|
||
constructor( | ||
monitorId: String, | ||
version: Long, | ||
method: RestRequest.Method, | ||
srcContext: FetchSourceContext? | ||
) : super() { | ||
this.monitorId = monitorId | ||
this.version = version | ||
this.method = method | ||
this.srcContext = srcContext | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // monitorId | ||
sin.readLong(), // version | ||
sin.readEnum(RestRequest.Method::class.java), // method | ||
if (sin.readBoolean()) { | ||
FetchSourceContext(sin) // srcContext | ||
} else null | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(monitorId) | ||
out.writeLong(version) | ||
out.writeEnum(method) | ||
out.writeBoolean(srcContext != null) | ||
srcContext?.writeTo(out) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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 | ||
import org.opensearch.core.xcontent.ToXContentFragment | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import java.io.IOException | ||
|
||
class GetMonitorResponse : BaseResponse { | ||
var id: String | ||
var version: Long | ||
var seqNo: Long | ||
var primaryTerm: Long | ||
var monitor: Monitor? | ||
var associatedWorkflows: List<AssociatedWorkflow>? | ||
|
||
constructor( | ||
id: String, | ||
version: Long, | ||
seqNo: Long, | ||
primaryTerm: Long, | ||
monitor: Monitor?, | ||
associatedCompositeMonitors: List<AssociatedWorkflow>?, | ||
) : super() { | ||
this.id = id | ||
this.version = version | ||
this.seqNo = seqNo | ||
this.primaryTerm = primaryTerm | ||
this.monitor = monitor | ||
this.associatedWorkflows = associatedCompositeMonitors ?: emptyList() | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
id = sin.readString(), // id | ||
version = sin.readLong(), // version | ||
seqNo = sin.readLong(), // seqNo | ||
primaryTerm = sin.readLong(), // primaryTerm | ||
monitor = if (sin.readBoolean()) { | ||
Monitor.readFrom(sin) // monitor | ||
} else null, | ||
associatedCompositeMonitors = sin.readList((AssociatedWorkflow)::readFrom), | ||
) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeLong(version) | ||
out.writeLong(seqNo) | ||
out.writeLong(primaryTerm) | ||
if (monitor != null) { | ||
out.writeBoolean(true) | ||
monitor?.writeTo(out) | ||
} else { | ||
out.writeBoolean(false) | ||
} | ||
associatedWorkflows?.forEach { | ||
it.writeTo(out) | ||
} | ||
} | ||
|
||
@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 (monitor != null) { | ||
builder.field("monitor", monitor) | ||
} | ||
if (associatedWorkflows != null) { | ||
builder.field("associated_workflows", associatedWorkflows!!.toTypedArray()) | ||
} | ||
return builder.endObject() | ||
} | ||
|
||
class AssociatedWorkflow : ToXContentFragment { | ||
val id: String | ||
val name: String | ||
|
||
constructor(id: String, name: String) { | ||
this.id = id | ||
this.name = name | ||
} | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params?): XContentBuilder { | ||
builder.startObject() | ||
.field("id", id) | ||
.field("name", name) | ||
.endObject() | ||
return builder | ||
Check warning on line 104 in src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt#L100-L104
|
||
} | ||
|
||
fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeString(name) | ||
Check warning on line 109 in src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt#L108-L109
|
||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), | ||
sin.readString() | ||
) | ||
Check warning on line 116 in src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt#L113-L116
|
||
|
||
companion object { | ||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun readFrom(sin: StreamInput): AssociatedWorkflow { | ||
return AssociatedWorkflow(sin) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.action.search.SearchRequest | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
class SearchMonitorRequest : ActionRequest { | ||
|
||
val searchRequest: SearchRequest | ||
|
||
constructor( | ||
searchRequest: SearchRequest | ||
) : super() { | ||
this.searchRequest = searchRequest | ||
Check warning on line 22 in src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt#L21-L22
|
||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
searchRequest = SearchRequest(sin) | ||
) | ||
Check warning on line 28 in src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt Codecov / codecov/patchsrc/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt#L26-L28
|
||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
searchRequest.writeTo(out) | ||
} | ||
} |