Skip to content

Commit

Permalink
added GetSuggestion action classes
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Toepker <toepkerd@amazon.com>
  • Loading branch information
toepkerd-zz committed Aug 19, 2022
1 parent 7d77eb7 commit a48d1f4
Show file tree
Hide file tree
Showing 3 changed files with 103 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 GetSuggestionsAction private constructor() : ActionType<GetSuggestionsResponse>(NAME, ::GetSuggestionsResponse) {
companion object {
val INSTANCE = GetSuggestionsAction()
const val NAME = "cluster:admin/opensearch/alerting/suggestions/get" // TODO: is this an ok name to use?
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.opensearch.alerting.action

import org.opensearch.action.ActionRequest
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.alerting.model.Monitor
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import java.io.IOException

class GetSuggestionsRequest : ActionRequest {
val monitorId: String?
val monitor: Monitor?

constructor(
monitorId: String?,
monitor: Monitor?
) : super() {
this.monitorId = monitorId
this.monitor = monitor
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
sin.readOptionalString(), // monitorId
if (sin.readBoolean()) {
Monitor.readFrom(sin) // monitor
} else null
)

override fun validate(): ActionRequestValidationException? {
return null
}

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeOptionalString(monitorId)
if (monitor != null) {
out.writeBoolean(true)
monitor.writeTo(out)
} else {
out.writeBoolean(false)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.opensearch.alerting.action

import org.opensearch.action.ActionResponse
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 GetSuggestionsResponse : ActionResponse, ToXContentObject {
var suggestions: List<String>
var status: RestStatus
// TODO: do we need id, primaryTerm, seqNo, etc, what are they used for?

constructor(
suggestions: List<String>,
status: RestStatus,
) : super() {
this.suggestions = suggestions
this.status = status
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
sin.readStringList(), // suggestions
sin.readEnum(RestStatus::class.java), // RestStatus
)

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeStringCollection(this.suggestions)
out.writeEnum(this.status)
}

@Throws(IOException::class)
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder.startObject()
.field("suggestions", this.suggestions)

return builder.endObject()
}
}

0 comments on commit a48d1f4

Please sign in to comment.