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: Dennis Toepker <toepkerd@amazon.com>
- Loading branch information
1 parent
7d77eb7
commit a48d1f4
Showing
3 changed files
with
103 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/GetSuggestionsAction.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 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? | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
alerting/src/main/kotlin/org/opensearch/alerting/action/GetSuggestionsRequest.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,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) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
alerting/src/main/kotlin/org/opensearch/alerting/action/GetSuggestionsResponse.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,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() | ||
} | ||
} |