Skip to content

Commit

Permalink
Add more findings related classes
Browse files Browse the repository at this point in the history
Signed-off-by: Annie Lee <[email protected]>
  • Loading branch information
Annie Lee committed Mar 10, 2022
1 parent b9104f1 commit 043fd22
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
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"
}
}
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)
}
}
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()
}
}

0 comments on commit 043fd22

Please sign in to comment.