-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* initial commit, functional but needs refactoring * added lastUpdatedTime to Note object * changed name from alert id to entity id * import cleanup * changing name from Alerting Notes to Alerting Comments * misc fixes and cleanup * adding unit test coverage * misc cleanup * misc review-based cleanup * added validation exception messages --------- (cherry picked from commit acaa844) Signed-off-by: Dennis Toepker <toepkerd@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Dennis Toepker <toepkerd@amazon.com>
- Loading branch information
1 parent
d708613
commit 923e487
Showing
14 changed files
with
578 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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/org/opensearch/commons/alerting/action/DeleteCommentRequest.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,34 @@ | ||
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 java.io.IOException | ||
|
||
class DeleteCommentRequest : ActionRequest { | ||
val commentId: String | ||
|
||
constructor(commentId: String) : super() { | ||
this.commentId = commentId | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
commentId = sin.readString() | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
if (commentId.isBlank()) { | ||
val exception = ActionRequestValidationException() | ||
exception.addValidationError("comment id must not be blank") | ||
return exception | ||
} | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(commentId) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/org/opensearch/commons/alerting/action/DeleteCommentResponse.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,32 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.commons.alerting.util.IndexUtils | ||
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 | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
|
||
class DeleteCommentResponse : BaseResponse { | ||
var commentId: String | ||
|
||
constructor( | ||
id: String | ||
) : super() { | ||
this.commentId = id | ||
} | ||
|
||
constructor(sin: StreamInput) : this( | ||
sin.readString() // commentId | ||
) | ||
|
||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(commentId) | ||
} | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
return builder.startObject() | ||
.field(IndexUtils._ID, commentId) | ||
.endObject() | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/org/opensearch/commons/alerting/action/IndexCommentRequest.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,73 @@ | ||
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 | ||
|
||
/** | ||
* Request to index/create a Comment | ||
* | ||
* entityId: the entity that the Comment is attached to and therefore associated with (e.g. in Alerting, | ||
* the entity is an Alert). This field is expected to be non-blank if the request is to create a new Comment. | ||
* | ||
* commentId: the ID of an existing Comment. This field is expected to be non-blank if the request is to | ||
* update an existing Comment. | ||
*/ | ||
class IndexCommentRequest : ActionRequest { | ||
val entityId: String | ||
val commentId: String | ||
val seqNo: Long | ||
val primaryTerm: Long | ||
val method: RestRequest.Method | ||
var content: String | ||
|
||
constructor( | ||
entityId: String, | ||
commentId: String, | ||
seqNo: Long, | ||
primaryTerm: Long, | ||
method: RestRequest.Method, | ||
content: String | ||
) : super() { | ||
this.entityId = entityId | ||
this.commentId = commentId | ||
this.seqNo = seqNo | ||
this.primaryTerm = primaryTerm | ||
this.method = method | ||
this.content = content | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
entityId = sin.readString(), | ||
commentId = sin.readString(), | ||
seqNo = sin.readLong(), | ||
primaryTerm = sin.readLong(), | ||
method = sin.readEnum(RestRequest.Method::class.java), | ||
content = sin.readString() | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
if (method == RestRequest.Method.POST && entityId.isBlank() || | ||
method == RestRequest.Method.PUT && commentId.isBlank() | ||
) { | ||
val exception = ActionRequestValidationException() | ||
exception.addValidationError("id must not be blank") | ||
return exception | ||
} | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(entityId) | ||
out.writeString(commentId) | ||
out.writeLong(seqNo) | ||
out.writeLong(primaryTerm) | ||
out.writeEnum(method) | ||
out.writeString(content) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/org/opensearch/commons/alerting/action/IndexCommentResponse.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,57 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.commons.alerting.model.Comment | ||
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.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 | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import java.io.IOException | ||
|
||
class IndexCommentResponse : BaseResponse { | ||
var id: String | ||
var seqNo: Long | ||
var primaryTerm: Long | ||
var comment: Comment | ||
|
||
constructor( | ||
id: String, | ||
seqNo: Long, | ||
primaryTerm: Long, | ||
comment: Comment | ||
) : super() { | ||
this.id = id | ||
this.seqNo = seqNo | ||
this.primaryTerm = primaryTerm | ||
this.comment = comment | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
sin.readString(), // id | ||
sin.readLong(), // seqNo | ||
sin.readLong(), // primaryTerm | ||
Comment.readFrom(sin) // comment | ||
) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(id) | ||
out.writeLong(seqNo) | ||
out.writeLong(primaryTerm) | ||
comment.writeTo(out) | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
return builder.startObject() | ||
.field(_ID, id) | ||
.field(_SEQ_NO, seqNo) | ||
.field(_PRIMARY_TERM, primaryTerm) | ||
.field("comment", comment) | ||
.endObject() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/org/opensearch/commons/alerting/action/SearchCommentRequest.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,33 @@ | ||
package org.opensearch.commons.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.action.search.SearchRequest | ||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
class SearchCommentRequest : ActionRequest { | ||
|
||
val searchRequest: SearchRequest | ||
|
||
constructor( | ||
searchRequest: SearchRequest | ||
) : super() { | ||
this.searchRequest = searchRequest | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
searchRequest = SearchRequest(sin) | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
searchRequest.writeTo(out) | ||
} | ||
} |
Oops, something went wrong.