-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create request and response classes for monitor status update
Signed-off-by: vikhy-aws <191836418+vikhy-aws@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateRequest.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,52 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import org.opensearch.rest.RestRequest | ||
import java.io.IOException | ||
|
||
class UpdateMonitorStateRequest : ActionRequest { | ||
val monitorId: String | ||
val enabled: Boolean | ||
val seqNo: Long | ||
val primaryTerm: Long | ||
val method: RestRequest.Method | ||
|
||
constructor( | ||
monitorId: String, | ||
enabled: Boolean, | ||
seqNo: Long, | ||
primaryTerm: Long, | ||
method: RestRequest.Method, | ||
) : super() { | ||
this.monitorId = monitorId | ||
this.enabled = enabled | ||
this.seqNo = seqNo | ||
this.primaryTerm = primaryTerm | ||
this.method = method | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this ( | ||
monitorId = sin.readString(), | ||
enabled = sin.readBoolean(), | ||
seqNo = sin.readLong(), | ||
primaryTerm = sin.readLong(), | ||
method = sin.readEnum(RestRequest.Method::class.java), | ||
) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(monitorId) | ||
out.writeBoolean(enabled) | ||
out.writeLong(seqNo) | ||
out.writeLong(primaryTerm) | ||
out.writeEnum(method) | ||
} | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/kotlin/org/opensearch/commons/alerting/action/UpdateMonitorStateResponse.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,64 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.commons.alerting.model.Monitor | ||
import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID | ||
import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM | ||
import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO | ||
import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION | ||
import org.opensearch.commons.notifications.action.BaseResponse | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import org.opensearch.core.xcontent.ToXContent.Params | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import java.io.IOException | ||
|
||
class UpdateMonitorStateResponse : BaseResponse { | ||
var id: String | ||
var version: Long | ||
var seqNo: Long | ||
var primaryTerm: Long | ||
var monitor: Monitor | ||
|
||
constructor( | ||
id: String, | ||
version: Long, | ||
seqNo: Long, | ||
primaryTerm: Long, | ||
monitor: Monitor | ||
) : super() { | ||
this.id = id | ||
this.version = version | ||
this.seqNo = seqNo | ||
this.primaryTerm = primaryTerm | ||
this.monitor = monitor | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // id | ||
sin.readLong(), // version | ||
sin.readLong(), // seqNo | ||
sin.readLong(), // primaryTerm | ||
Monitor.readFrom(sin) as Monitor // monitor | ||
) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeLong(version) | ||
out.writeLong(seqNo) | ||
out.writeLong(primaryTerm) | ||
monitor.writeTo(out) | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: Params): XContentBuilder { | ||
return builder.startObject() | ||
.field(_ID, id) | ||
.field(_VERSION, version) | ||
.field(_SEQ_NO, seqNo) | ||
.field(_PRIMARY_TERM, primaryTerm) | ||
.field("Monitor", monitor) | ||
.endObject() | ||
} | ||
} |