-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose delete monitor api from alerting (#251)
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> (cherry picked from commit 68da168)
- Loading branch information
1 parent
03fd527
commit 592e120
Showing
6 changed files
with
142 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
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
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/org/opensearch/commons/alerting/action/DeleteMonitorRequest.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,35 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.action.support.WriteRequest | ||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
class DeleteMonitorRequest : ActionRequest { | ||
|
||
val monitorId: String | ||
val refreshPolicy: WriteRequest.RefreshPolicy | ||
|
||
constructor(monitorId: String, refreshPolicy: WriteRequest.RefreshPolicy) : super() { | ||
this.monitorId = monitorId | ||
this.refreshPolicy = refreshPolicy | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
monitorId = sin.readString(), | ||
refreshPolicy = WriteRequest.RefreshPolicy.readFrom(sin) | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(monitorId) | ||
refreshPolicy.writeTo(out) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/opensearch/commons/alerting/action/DeleteMonitorResponse.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,38 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.xcontent.ToXContent | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.commons.alerting.util.IndexUtils | ||
import org.opensearch.commons.notifications.action.BaseResponse | ||
|
||
class DeleteMonitorResponse : BaseResponse { | ||
var id: String | ||
var version: Long | ||
|
||
constructor( | ||
id: String, | ||
version: Long | ||
) : super() { | ||
this.id = id | ||
this.version = version | ||
} | ||
|
||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // id | ||
sin.readLong() // version | ||
) | ||
|
||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeLong(version) | ||
} | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
return builder.startObject() | ||
.field(IndexUtils._ID, id) | ||
.field(IndexUtils._VERSION, version) | ||
.endObject() | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/test/kotlin/org/opensearch/commons/alerting/action/DeleteMonitorRequestTests.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,26 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.opensearch.action.support.WriteRequest | ||
import org.opensearch.common.io.stream.BytesStreamOutput | ||
import org.opensearch.common.io.stream.StreamInput | ||
|
||
class DeleteMonitorRequestTests { | ||
|
||
@Test | ||
fun `test delete monitor request`() { | ||
|
||
val req = DeleteMonitorRequest("1234", WriteRequest.RefreshPolicy.IMMEDIATE) | ||
Assert.assertNotNull(req) | ||
Assert.assertEquals("1234", req.monitorId) | ||
Assert.assertEquals("true", req.refreshPolicy.value) | ||
|
||
val out = BytesStreamOutput() | ||
req.writeTo(out) | ||
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) | ||
val newReq = DeleteMonitorRequest(sin) | ||
Assert.assertEquals("1234", newReq.monitorId) | ||
Assert.assertEquals("true", newReq.refreshPolicy.value) | ||
} | ||
} |