-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added noop trigger Signed-off-by: Petar Dzepina <[email protected]> (cherry picked from commit c507ac9) Co-authored-by: Petar Dzepina <[email protected]>
- Loading branch information
1 parent
26a117e
commit db60532
Showing
6 changed files
with
123 additions
and
2 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
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/org/opensearch/commons/alerting/model/NoOpTrigger.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,76 @@ | ||
package org.opensearch.commons.alerting.model | ||
|
||
import org.opensearch.common.CheckedFunction | ||
import org.opensearch.common.UUIDs | ||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.xcontent.XContentParserUtils | ||
import org.opensearch.commons.alerting.model.action.Action | ||
import org.opensearch.core.ParseField | ||
import org.opensearch.core.xcontent.NamedXContentRegistry | ||
import org.opensearch.core.xcontent.ToXContent | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import org.opensearch.core.xcontent.XContentParser | ||
import java.io.IOException | ||
|
||
data class NoOpTrigger( | ||
override val id: String = UUIDs.base64UUID(), | ||
override val name: String = "NoOp trigger", | ||
override val severity: String = "", | ||
override val actions: List<Action> = listOf(), | ||
) : Trigger { | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this() | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
builder.startObject() | ||
.startObject(NOOP_TRIGGER_FIELD) | ||
.field(ID_FIELD, id) | ||
.endObject() | ||
.endObject() | ||
return builder | ||
} | ||
|
||
override fun name(): String { | ||
return NOOP_TRIGGER_FIELD | ||
} | ||
|
||
fun asTemplateArg(): Map<String, Any> { | ||
return mapOf() | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
} | ||
|
||
companion object { | ||
const val ID_FIELD = "id" | ||
const val NOOP_TRIGGER_FIELD = "noop_trigger" | ||
val XCONTENT_REGISTRY = NamedXContentRegistry.Entry( | ||
Trigger::class.java, ParseField(NOOP_TRIGGER_FIELD), | ||
CheckedFunction { parseInner(it) } | ||
) | ||
|
||
@JvmStatic @Throws(IOException::class) | ||
fun parseInner(xcp: XContentParser): NoOpTrigger { | ||
var id = UUIDs.base64UUID() | ||
if (xcp.currentToken() == XContentParser.Token.START_OBJECT) xcp.nextToken() | ||
if (xcp.currentName() == ID_FIELD) { | ||
xcp.nextToken() | ||
id = xcp.text() | ||
xcp.nextToken() | ||
} | ||
if (xcp.currentToken() != XContentParser.Token.END_OBJECT) { | ||
XContentParserUtils.throwUnknownToken(xcp.currentToken(), xcp.tokenLocation) | ||
} | ||
return NoOpTrigger(id = id) | ||
} | ||
|
||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun readFrom(sin: StreamInput): NoOpTrigger { | ||
return NoOpTrigger(sin) | ||
} | ||
} | ||
} |
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
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