in alerting/src/main/kotlin/org/opensearch/alerting/model/QueryLevelTrigger.kt [128:176]
fun parseInner(xcp: XContentParser): QueryLevelTrigger {
var id = UUIDs.base64UUID() // assign a default triggerId if one is not specified
lateinit var name: String
lateinit var severity: String
lateinit var condition: Script
val actions: MutableList<Action> = mutableListOf()
if (xcp.currentToken() != Token.START_OBJECT && xcp.currentToken() != Token.FIELD_NAME) {
XContentParserUtils.throwUnknownToken(xcp.currentToken(), xcp.tokenLocation)
}
// If the parser began on START_OBJECT, move to the next token so that the while loop enters on
// the fieldName (or END_OBJECT if it's empty).
if (xcp.currentToken() == Token.START_OBJECT) xcp.nextToken()
while (xcp.currentToken() != Token.END_OBJECT) {
val fieldName = xcp.currentName()
xcp.nextToken()
when (fieldName) {
ID_FIELD -> id = xcp.text()
NAME_FIELD -> name = xcp.text()
SEVERITY_FIELD -> severity = xcp.text()
CONDITION_FIELD -> {
xcp.nextToken()
condition = Script.parse(xcp)
require(condition.lang == Script.DEFAULT_SCRIPT_LANG) {
"Invalid script language. Allowed languages are [${Script.DEFAULT_SCRIPT_LANG}]"
}
xcp.nextToken()
}
ACTIONS_FIELD -> {
ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp)
while (xcp.nextToken() != Token.END_ARRAY) {
actions.add(Action.parse(xcp))
}
}
}
xcp.nextToken()
}
return QueryLevelTrigger(
name = requireNotNull(name) { "Trigger name is null" },
severity = requireNotNull(severity) { "Trigger severity is null" },
condition = requireNotNull(condition) { "Trigger condition is null" },
actions = requireNotNull(actions) { "Trigger actions are null" },
id = requireNotNull(id) { "Trigger id is null." }
)
}