-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds workflows model and workflow actions for Alerting Plugin (#436)
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
- Loading branch information
Showing
23 changed files
with
1,696 additions
and
4 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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowRequest.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 @@ | ||
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 java.io.IOException | ||
|
||
class DeleteWorkflowRequest : ActionRequest { | ||
|
||
val workflowId: String | ||
/** | ||
* Flag that indicates whether the delegate monitors should be deleted or not. | ||
* If the flag is set to true, Delegate monitors will be deleted only in the case when they are part of the specified workflow and no other. | ||
*/ | ||
val deleteDelegateMonitors: Boolean? | ||
|
||
constructor(workflowId: String, deleteDelegateMonitors: Boolean?) : super() { | ||
this.workflowId = workflowId | ||
this.deleteDelegateMonitors = deleteDelegateMonitors | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
workflowId = sin.readString(), | ||
deleteDelegateMonitors = sin.readOptionalBoolean() | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(workflowId) | ||
out.writeOptionalBoolean(deleteDelegateMonitors) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowResponse.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,48 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.commons.alerting.util.IndexUtils | ||
import org.opensearch.commons.notifications.action.BaseResponse | ||
import org.opensearch.core.xcontent.ToXContent | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
|
||
class DeleteWorkflowResponse : BaseResponse { | ||
var id: String | ||
var version: Long | ||
var nonDeletedMonitors: List<String>? = null | ||
|
||
constructor( | ||
id: String, | ||
version: Long, | ||
nonDeletedMonitors: List<String>? = null | ||
) : super() { | ||
this.id = id | ||
this.version = version | ||
this.nonDeletedMonitors = nonDeletedMonitors | ||
} | ||
|
||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // id | ||
sin.readLong(), // version | ||
sin.readOptionalStringList() | ||
) | ||
|
||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeLong(version) | ||
out.writeOptionalStringCollection(nonDeletedMonitors) | ||
} | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
return builder.startObject() | ||
.field(IndexUtils._ID, id) | ||
.field(IndexUtils._VERSION, version) | ||
.field(NON_DELETED_MONITORS, nonDeletedMonitors) | ||
.endObject() | ||
} | ||
|
||
companion object { | ||
const val NON_DELETED_MONITORS = "NON_DELETED_MONITORS" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowRequest.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,42 @@ | ||
/* | ||
* 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 method: RestRequest.Method | ||
|
||
constructor( | ||
workflowId: String, | ||
method: RestRequest.Method | ||
) : super() { | ||
this.workflowId = workflowId | ||
this.method = method | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // workflowId | ||
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.writeEnum(method) | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowResponse.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,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.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.core.xcontent.ToXContent | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
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 | ||
} | ||
} |
Oops, something went wrong.