in src/main/kotlin/org/opensearch/indexmanagement/rollup/model/ISMRollup.kt [148:198]
fun parse(
xcp: XContentParser
): ISMRollup {
var description = ""
var targetIndex = ""
var pageSize = 0
val dimensions = mutableListOf<Dimension>()
val metrics = mutableListOf<RollupMetrics>()
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
val fieldName = xcp.currentName()
xcp.nextToken()
when (fieldName) {
Rollup.DESCRIPTION_FIELD -> description = xcp.text()
Rollup.TARGET_INDEX_FIELD -> targetIndex = xcp.text()
Rollup.PAGE_SIZE_FIELD -> pageSize = xcp.intValue()
Rollup.DIMENSIONS_FIELD -> {
XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_ARRAY,
xcp.currentToken(),
xcp
)
while (xcp.nextToken() != XContentParser.Token.END_ARRAY) {
dimensions.add(Dimension.parse(xcp))
}
}
Rollup.METRICS_FIELD -> {
XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_ARRAY,
xcp.currentToken(),
xcp
)
while (xcp.nextToken() != XContentParser.Token.END_ARRAY) {
metrics.add(RollupMetrics.parse(xcp))
}
}
else -> throw IllegalArgumentException("Invalid field, [$fieldName] not supported in ISM Rollup.")
}
}
return ISMRollup(
description = description,
pageSize = pageSize,
dimensions = dimensions,
metrics = metrics,
targetIndex = targetIndex
)
}