forked from opensearch-project/alerting
-
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.
fan out monitor request, response, action
- Loading branch information
Showing
6 changed files
with
207 additions
and
5 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
10 changes: 10 additions & 0 deletions
10
alerting/src/main/kotlin/org/opensearch/alerting/action/DocLevelMonitorFanOutAction.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,10 @@ | ||
package org.opensearch.alerting.action | ||
|
||
import org.opensearch.action.ActionType | ||
|
||
class DocLevelMonitorFanOutAction private constructor() : ActionType<DocLevelMonitorFanOutResponse>(NAME, ::DocLevelMonitorFanOutResponse) { | ||
companion object { | ||
val INSTANCE = DocLevelMonitorFanOutAction() | ||
const val NAME = "cluster:admin/opensearch/alerting/monitor/doclevel/fanout" | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
alerting/src/main/kotlin/org/opensearch/alerting/action/DocLevelMonitorFanOutRequest.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,79 @@ | ||
package org.opensearch.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.alerting.model.IndexExecutionContext | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import org.opensearch.core.index.shard.ShardId | ||
import org.opensearch.core.xcontent.ToXContent | ||
import org.opensearch.core.xcontent.ToXContentObject | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import java.io.IOException | ||
|
||
class DocLevelMonitorFanOutRequest : ActionRequest, ToXContentObject { | ||
|
||
val nodeId: String | ||
val monitorId: String | ||
val executionId: String | ||
val indexExecutionContexts: List<IndexExecutionContext> | ||
val shardIds: List<ShardId> | ||
|
||
constructor( | ||
nodeId: String, | ||
monitorId: String, | ||
executionId: String, | ||
indexExecutionContexts: List<IndexExecutionContext>, | ||
shardIds: List<ShardId>, | ||
) : super() { | ||
this.nodeId = nodeId | ||
this.monitorId = monitorId | ||
this.executionId = executionId | ||
this.indexExecutionContexts = indexExecutionContexts | ||
this.shardIds = shardIds | ||
require(shardIds.isEmpty()) { } | ||
require(indexExecutionContexts.isEmpty()) { } | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
nodeId = sin.readString(), | ||
monitorId = sin.readString(), | ||
executionId = sin.readString(), | ||
indexExecutionContexts = sin.readList { IndexExecutionContext(sin) }, | ||
shardIds = sin.readList(::ShardId) | ||
) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(nodeId) | ||
out.writeString(monitorId) | ||
out.writeString(executionId) | ||
out.writeCollection(indexExecutionContexts) | ||
out.writeCollection(shardIds) | ||
} | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
var actionValidationException: ActionRequestValidationException? = null | ||
if (shardIds.isEmpty()) { | ||
actionValidationException = ActionRequestValidationException() | ||
actionValidationException.addValidationError("shard_ids is null or empty") | ||
} | ||
if (indexExecutionContexts.isEmpty()) | ||
if (actionValidationException == null) | ||
actionValidationException = ActionRequestValidationException() | ||
actionValidationException!!.addValidationError("index_execution_contexts is null or empty") | ||
return actionValidationException | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
builder.startObject() | ||
.field("node_id", nodeId) | ||
.field("monitor_id", nodeId) | ||
.field("execution_id", nodeId) | ||
.field("index_execution_contexts", indexExecutionContexts) | ||
.field("shard_ids", shardIds) | ||
return builder.endObject() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
alerting/src/main/kotlin/org/opensearch/alerting/action/DocLevelMonitorFanOutResponse.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,60 @@ | ||
package org.opensearch.alerting.action | ||
|
||
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.index.shard.ShardId | ||
import org.opensearch.core.xcontent.ToXContent | ||
import org.opensearch.core.xcontent.ToXContentObject | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import java.io.IOException | ||
|
||
class DocLevelMonitorFanOutResponse : ActionResponse, ToXContentObject { | ||
|
||
val nodeId: String | ||
val executionId: String | ||
val monitorId: String | ||
val shardIdFailureMap: Map<ShardId, Exception> | ||
val findingIds: List<String> | ||
// for shards not delegated to nodes sequence number would be -3 (new number shard was not queried), | ||
val lastRunContexts: Map<String, Any> | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), | ||
sin.readString(), | ||
sin.readString(), | ||
sin.readMap() as Map<ShardId, Exception>, | ||
sin.readStringList(), | ||
sin.readMap()!! as Map<String, Any>, | ||
) | ||
|
||
constructor( | ||
nodeId: String, | ||
executionId: String, | ||
monitorId: String, | ||
shardIdFailureMap: Map<ShardId, Exception>, | ||
findingIds: List<String>, | ||
lastRunContexts: Map<String, Any>, | ||
) : super() { | ||
this.nodeId = nodeId | ||
this.executionId = executionId | ||
this.monitorId = monitorId | ||
this.shardIdFailureMap = shardIdFailureMap | ||
this.findingIds = findingIds | ||
this.lastRunContexts = lastRunContexts | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeMap(lastRunContexts) | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
builder.startObject() | ||
.field("last_run_contexts", lastRunContexts) | ||
.endObject() | ||
return builder | ||
} | ||
} |
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