-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added workflow as a composite monitor #380
Changes from 2 commits
8233e7f
a2a2ede
b66c0dc
6e2f32f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
class DeleteWorkflowRequest : ActionRequest { | ||
|
||
val workflowId: String | ||
val deleteDelegateMonitors: Boolean? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. java docs |
||
val refreshPolicy: WriteRequest.RefreshPolicy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove refresh policy |
||
|
||
constructor(workflowId: String, deleteDelegateMonitors: Boolean?, refreshPolicy: WriteRequest.RefreshPolicy) : super() { | ||
this.workflowId = workflowId | ||
this.deleteDelegateMonitors = deleteDelegateMonitors | ||
this.refreshPolicy = refreshPolicy | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
workflowId = sin.readString(), | ||
deleteDelegateMonitors = sin.readOptionalBoolean(), | ||
refreshPolicy = WriteRequest.RefreshPolicy.readFrom(sin) | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(workflowId) | ||
out.writeOptionalBoolean(deleteDelegateMonitors) | ||
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.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.xcontent.ToXContent | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.commons.alerting.util.IndexUtils | ||
import org.opensearch.commons.notifications.action.BaseResponse | ||
|
||
class DeleteWorkflowResponse : 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,47 @@ | ||
/* | ||
* 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.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.rest.RestRequest | ||
import java.io.IOException | ||
|
||
class GetWorkflowRequest : ActionRequest { | ||
val workflowId: String | ||
val version: Long | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove version from request. User should be able to fetch by id |
||
val method: RestRequest.Method | ||
|
||
constructor( | ||
workflowId: String, | ||
version: Long, | ||
method: RestRequest.Method | ||
) : super() { | ||
this.workflowId = workflowId | ||
this.version = version | ||
this.method = method | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // workflowId | ||
sin.readLong(), // version | ||
sin.readEnum(RestRequest.Method::class.java) // method | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(workflowId) | ||
out.writeLong(version) | ||
out.writeEnum(method) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.xcontent.ToXContent | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.commons.alerting.model.Workflow | ||
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.rest.RestStatus | ||
import java.io.IOException | ||
|
||
class GetWorkflowResponse : BaseResponse { | ||
var id: String | ||
var version: Long | ||
var seqNo: Long | ||
var primaryTerm: Long | ||
private var status: RestStatus | ||
var workflow: Workflow? | ||
|
||
constructor( | ||
id: String, | ||
version: Long, | ||
seqNo: Long, | ||
primaryTerm: Long, | ||
status: RestStatus, | ||
workflow: Workflow? | ||
) : super() { | ||
this.id = id | ||
this.version = version | ||
this.seqNo = seqNo | ||
this.primaryTerm = primaryTerm | ||
this.status = status | ||
this.workflow = workflow | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // id | ||
sin.readLong(), // version | ||
sin.readLong(), // seqNo | ||
sin.readLong(), // primaryTerm | ||
sin.readEnum(RestStatus::class.java), // RestStatus | ||
if (sin.readBoolean()) { | ||
Workflow.readFrom(sin) // monitor | ||
} else null | ||
) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeLong(version) | ||
out.writeLong(seqNo) | ||
out.writeLong(primaryTerm) | ||
out.writeEnum(status) | ||
if (workflow != null) { | ||
out.writeBoolean(true) | ||
workflow?.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 (workflow != null) | ||
builder.field("workflow", workflow) | ||
|
||
return builder.endObject() | ||
} | ||
|
||
override fun getStatus(): RestStatus { | ||
return this.status | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also add execute workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could - but then we need to extract the ExecuteWorkflowRequest.
Should I add a execute workflow method here or?