|
| 1 | +package org.opensearch.commons.alerting.action |
| 2 | + |
| 3 | +import org.opensearch.commons.alerting.model.Monitor |
| 4 | +import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID |
| 5 | +import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM |
| 6 | +import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO |
| 7 | +import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION |
| 8 | +import org.opensearch.commons.notifications.action.BaseResponse |
| 9 | +import org.opensearch.core.common.io.stream.StreamInput |
| 10 | +import org.opensearch.core.common.io.stream.StreamOutput |
| 11 | +import org.opensearch.core.xcontent.ToXContent.Params |
| 12 | +import org.opensearch.core.xcontent.XContentBuilder |
| 13 | +import java.io.IOException |
| 14 | + |
| 15 | +class UpdateMonitorStateResponse : BaseResponse { |
| 16 | + var id: String |
| 17 | + var version: Long |
| 18 | + var seqNo: Long |
| 19 | + var primaryTerm: Long |
| 20 | + var monitor: Monitor |
| 21 | + |
| 22 | + constructor( |
| 23 | + id: String, |
| 24 | + version: Long, |
| 25 | + seqNo: Long, |
| 26 | + primaryTerm: Long, |
| 27 | + monitor: Monitor |
| 28 | + ) : super() { |
| 29 | + this.id = id |
| 30 | + this.version = version |
| 31 | + this.seqNo = seqNo |
| 32 | + this.primaryTerm = primaryTerm |
| 33 | + this.monitor = monitor |
| 34 | + } |
| 35 | + |
| 36 | + @Throws(IOException::class) |
| 37 | + constructor(sin: StreamInput) : this( |
| 38 | + sin.readString(), // id |
| 39 | + sin.readLong(), // version |
| 40 | + sin.readLong(), // seqNo |
| 41 | + sin.readLong(), // primaryTerm |
| 42 | + Monitor.readFrom(sin) as Monitor // monitor |
| 43 | + ) |
| 44 | + |
| 45 | + @Throws(IOException::class) |
| 46 | + override fun writeTo(out: StreamOutput) { |
| 47 | + out.writeString(id) |
| 48 | + out.writeLong(version) |
| 49 | + out.writeLong(seqNo) |
| 50 | + out.writeLong(primaryTerm) |
| 51 | + monitor.writeTo(out) |
| 52 | + } |
| 53 | + |
| 54 | + @Throws(IOException::class) |
| 55 | + override fun toXContent(builder: XContentBuilder, params: Params): XContentBuilder { |
| 56 | + return builder.startObject() |
| 57 | + .field(_ID, id) |
| 58 | + .field(_VERSION, version) |
| 59 | + .field(_SEQ_NO, seqNo) |
| 60 | + .field(_PRIMARY_TERM, primaryTerm) |
| 61 | + .field("Monitor", monitor) |
| 62 | + .endObject() |
| 63 | + } |
| 64 | +} |
0 commit comments