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.
Finding Search API (opensearch-project#385)
* Findings search API based on Annie's work Signed-off-by: Annie Lee <leeyun@amazon.com> * Fix Search API and add IT tests Signed-off-by: Ashish Agrawal <ashisagr@amazon.com> Co-authored-by: Annie Lee <leeyun@amazon.com>
- Loading branch information
Showing
19 changed files
with
778 additions
and
107 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
15 changes: 15 additions & 0 deletions
15
alerting/src/main/kotlin/org/opensearch/alerting/action/GetFindingsAction.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 GetFindingsAction private constructor() : ActionType<GetFindingsResponse>(NAME, ::GetFindingsResponse) { | ||
companion object { | ||
val INSTANCE = GetFindingsAction() | ||
val NAME = "cluster:admin/opendistro/alerting/findings/get" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
alerting/src/main/kotlin/org/opensearch/alerting/action/GetFindingsRequest.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,42 @@ | ||
/* | ||
* 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 java.io.IOException | ||
|
||
class GetFindingsRequest : ActionRequest { | ||
val findingId: String? | ||
val table: Table | ||
|
||
constructor( | ||
findingId: String?, | ||
table: Table | ||
) : super() { | ||
this.findingId = findingId | ||
this.table = table | ||
} | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
findingId = sin.readOptionalString(), | ||
table = Table.readFrom(sin) | ||
) | ||
|
||
override fun validate(): ActionRequestValidationException? { | ||
return null | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeOptionalString(findingId) | ||
table.writeTo(out) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
alerting/src/main/kotlin/org/opensearch/alerting/action/GetFindingsResponse.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.FindingWithDocs | ||
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 GetFindingsResponse : ActionResponse, ToXContentObject { | ||
var status: RestStatus | ||
var totalFindings: Int? | ||
var findings: List<FindingWithDocs> | ||
|
||
constructor( | ||
status: RestStatus, | ||
totalFindings: Int?, | ||
findings: List<FindingWithDocs> | ||
) : 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<FindingWithDocs>() | ||
this.totalFindings = sin.readOptionalInt() | ||
var currentSize = sin.readInt() | ||
for (i in 0 until currentSize) { | ||
findings.add(FindingWithDocs.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("total_findings", totalFindings) | ||
.field("findings", findings) | ||
|
||
return builder.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
Oops, something went wrong.