forked from opensearch-project/common-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move get monitor and search monitor action / request / responses to c…
…ommon-utils (opensearch-project#566) (opensearch-project#567) * Add get monitor request/response * Remove status from response; add to interface * Add UT * Repeat for search monitor action --------- (cherry picked from commit 2ff995b) Signed-off-by: Tyler Ohlsen <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: AWSHurneyt <[email protected]>
- Loading branch information
1 parent
5edec6a
commit 93c4bb7
Showing
9 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeString(name) | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), | ||
sin.readString() | ||
) | ||
|
||
companion object { | ||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun readFrom(sin: StreamInput): AssociatedWorkflow { | ||
return AssociatedWorkflow(sin) | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/opensearch/commons/alerting/action/SearchMonitorRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
searchRequest = SearchRequest(sin) | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
searchRequest.writeTo(out) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.