forked from opensearch-project/alerting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Annie Lee <[email protected]>
- Loading branch information
Annie Lee
committed
Mar 10, 2022
1 parent
b9104f1
commit 043fd22
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
alerting/src/main/kotlin/org/opensearch/alerting/action/GetFindingsSearchAction.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,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.alerting.action | ||
|
||
import org.opensearch.action.ActionType | ||
|
||
class GetFindingsSearchAction private constructor() : ActionType<GetFindingsSearchResponse>(NAME, ::GetFindingsSearchResponse) { | ||
companion object { | ||
val INSTANCE = GetFindingsSearchAction() | ||
val NAME = "cluster:admin/opendistro/alerting/findings/get" | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
alerting/src/main/kotlin/org/opensearch/alerting/action/GetFindingsSearchRequest.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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.alerting.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.alerting.model.Table | ||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.search.fetch.subphase.FetchSourceContext | ||
import java.io.IOException | ||
|
||
class GetFindingsSearchRequest : ActionRequest { | ||
val findingsId: String? | ||
val version: Long | ||
val srcContext: FetchSourceContext? | ||
val table: Table | ||
|
||
constructor( | ||
findingsId: String?, | ||
version: Long, | ||
srcContext: FetchSourceContext?, | ||
table: Table, | ||
destinationType: String | ||
) : super() { | ||
this.findingsId = findingsId | ||
this.version = version | ||
this.srcContext = srcContext | ||
this.table = table | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
findingsId = sin.readOptionalString(), | ||
version = sin.readLong(), | ||
srcContext = if (sin.readBoolean()) { | ||
FetchSourceContext(sin) | ||
} else null, | ||
table = Table.readFrom(sin) | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeOptionalString(findingsId) | ||
out.writeLong(version) | ||
out.writeBoolean(srcContext != null) | ||
srcContext?.writeTo(out) | ||
table.writeTo(out) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
alerting/src/main/kotlin/org/opensearch/alerting/action/GetFindingsSearchResponse.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,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.alerting.action | ||
|
||
import org.opensearch.action.ActionResponse | ||
import org.opensearch.alerting.model.Finding | ||
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.ToXContentObject | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.rest.RestStatus | ||
import java.io.IOException | ||
|
||
class GetFindingsSearchResponse : ActionResponse, ToXContentObject { | ||
var status: RestStatus | ||
var totalFindings: Int? | ||
var findings: List<Finding> | ||
|
||
constructor( | ||
status: RestStatus, | ||
totalFindings: Int?, | ||
findings: List<Destination> | ||
) : super() { | ||
this.status = status | ||
this.totalFindings = totalFindings | ||
this.findings = findings | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) { | ||
this.status = sin.readEnum(RestStatus::class.java) | ||
val findings = mutableListOf<Destination>() | ||
this.totalFindings = sin.readOptionalInt() | ||
var currentSize = sin.readInt() | ||
for (i in 0 until currentSize) { | ||
findings.add(Destination.readFrom(sin)) | ||
} | ||
this.findings = findings | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeEnum(status) | ||
out.writeOptionalInt(totalFindings) | ||
out.writeInt(findings.size) | ||
for (finding in findings) { | ||
finding.writeTo(out) | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
builder.startObject() | ||
.field("totalFindings", totalFindings) | ||
.field("findings", findings) | ||
|
||
return builder.endObject() | ||
} | ||
} |