From 762efda391453291edc18db99a76fb02d1e9f62c Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Tue, 21 Nov 2023 17:55:46 +0000 Subject: [PATCH] Clean up remaining references Signed-off-by: Tyler Ohlsen --- .../alerting/action/GetMonitorAction.kt | 15 -- .../alerting/action/GetMonitorRequest.kt | 56 -------- .../alerting/action/GetMonitorResponse.kt | 133 ------------------ .../TransportAcknowledgeAlertAction.kt | 7 +- .../transport/TransportGetFindingsAction.kt | 7 +- .../transport/AlertingSingleNodeTestCase.kt | 5 +- 6 files changed, 8 insertions(+), 215 deletions(-) delete mode 100644 alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorAction.kt delete mode 100644 alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorRequest.kt delete mode 100644 alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorResponse.kt diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorAction.kt deleted file mode 100644 index da209b983..000000000 --- a/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorAction.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.alerting.action - -import org.opensearch.action.ActionType - -class GetMonitorAction private constructor() : ActionType(NAME, ::GetMonitorResponse) { - companion object { - val INSTANCE = GetMonitorAction() - const val NAME = "cluster:admin/opendistro/alerting/monitor/get" - } -} diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorRequest.kt b/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorRequest.kt deleted file mode 100644 index 365a31f8f..000000000 --- a/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorRequest.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.core.common.io.stream.StreamInput -import org.opensearch.core.common.io.stream.StreamOutput -import org.opensearch.rest.RestRequest -import org.opensearch.search.fetch.subphase.FetchSourceContext -import java.io.IOException - -class GetMonitorRequest : ActionRequest { - val monitorId: String - val version: Long - val method: RestRequest.Method - val srcContext: FetchSourceContext? - - constructor( - monitorId: String, - version: Long, - method: RestRequest.Method, - srcContext: FetchSourceContext? - ) : super() { - this.monitorId = monitorId - this.version = version - this.method = method - this.srcContext = srcContext - } - - @Throws(IOException::class) - constructor(sin: StreamInput) : this( - sin.readString(), // monitorId - sin.readLong(), // version - sin.readEnum(RestRequest.Method::class.java), // method - if (sin.readBoolean()) { - FetchSourceContext(sin) // srcContext - } else null - ) - - override fun validate(): ActionRequestValidationException? { - return null - } - - @Throws(IOException::class) - override fun writeTo(out: StreamOutput) { - out.writeString(monitorId) - out.writeLong(version) - out.writeEnum(method) - out.writeBoolean(srcContext != null) - srcContext?.writeTo(out) - } -} diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorResponse.kt b/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorResponse.kt deleted file mode 100644 index ab69a1582..000000000 --- a/alerting/src/main/kotlin/org/opensearch/alerting/action/GetMonitorResponse.kt +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.alerting.action - -import org.opensearch.commons.alerting.model.Monitor -import org.opensearch.commons.alerting.util.IndexUtils.Companion._ID -import org.opensearch.commons.alerting.util.IndexUtils.Companion._PRIMARY_TERM -import org.opensearch.commons.alerting.util.IndexUtils.Companion._SEQ_NO -import org.opensearch.commons.alerting.util.IndexUtils.Companion._VERSION -import org.opensearch.core.action.ActionResponse -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.common.io.stream.StreamOutput -import org.opensearch.core.rest.RestStatus -import org.opensearch.core.xcontent.ToXContent -import org.opensearch.core.xcontent.ToXContentFragment -import org.opensearch.core.xcontent.ToXContentObject -import org.opensearch.core.xcontent.XContentBuilder -import java.io.IOException - -class GetMonitorResponse : ActionResponse, ToXContentObject { - var id: String - var version: Long - var seqNo: Long - var primaryTerm: Long - var status: RestStatus - var monitor: Monitor? - var associatedWorkflows: List? - - constructor( - id: String, - version: Long, - seqNo: Long, - primaryTerm: Long, - status: RestStatus, - monitor: Monitor?, - associatedCompositeMonitors: List?, - ) : super() { - this.id = id - this.version = version - this.seqNo = seqNo - this.primaryTerm = primaryTerm - this.status = status - this.monitor = monitor - this.associatedWorkflows = associatedCompositeMonitors ?: emptyList() - } - - @Throws(IOException::class) - constructor(sin: StreamInput) : this( - id = sin.readString(), // id - version = sin.readLong(), // version - seqNo = sin.readLong(), // seqNo - primaryTerm = sin.readLong(), // primaryTerm - status = sin.readEnum(RestStatus::class.java), // RestStatus - monitor = if (sin.readBoolean()) { - Monitor.readFrom(sin) // monitor - } else null, - associatedCompositeMonitors = sin.readList((AssociatedWorkflow)::readFrom), - ) - - @Throws(IOException::class) - override fun writeTo(out: StreamOutput) { - out.writeString(id) - out.writeLong(version) - out.writeLong(seqNo) - out.writeLong(primaryTerm) - out.writeEnum(status) - if (monitor != null) { - out.writeBoolean(true) - monitor?.writeTo(out) - } else { - out.writeBoolean(false) - } - associatedWorkflows?.forEach { - it.writeTo(out) - } - } - - @Throws(IOException::class) - override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { - builder.startObject() - .field(_ID, id) - .field(_VERSION, version) - .field(_SEQ_NO, seqNo) - .field(_PRIMARY_TERM, primaryTerm) - if (monitor != null) { - builder.field("monitor", monitor) - } - if (associatedWorkflows != null) { - builder.field("associated_workflows", associatedWorkflows!!.toTypedArray()) - } - return builder.endObject() - } - - class AssociatedWorkflow : ToXContentFragment { - val id: String - val name: String - - constructor(id: String, name: String) { - this.id = id - this.name = name - } - - override fun toXContent(builder: XContentBuilder, params: ToXContent.Params?): XContentBuilder { - builder.startObject() - .field("id", id) - .field("name", name) - .endObject() - return builder - } - - fun writeTo(out: StreamOutput) { - out.writeString(id) - out.writeString(name) - } - - @Throws(IOException::class) - constructor(sin: StreamInput) : this( - sin.readString(), - sin.readString() - ) - - companion object { - @JvmStatic - @Throws(IOException::class) - fun readFrom(sin: StreamInput): AssociatedWorkflow { - return AssociatedWorkflow(sin) - } - } - } -} diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportAcknowledgeAlertAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportAcknowledgeAlertAction.kt index f2399984b..aa65c6826 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportAcknowledgeAlertAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportAcknowledgeAlertAction.kt @@ -20,9 +20,6 @@ import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.HandledTransportAction import org.opensearch.action.update.UpdateRequest -import org.opensearch.alerting.action.GetMonitorAction -import org.opensearch.alerting.action.GetMonitorRequest -import org.opensearch.alerting.action.GetMonitorResponse import org.opensearch.alerting.opensearchapi.suspendUntil import org.opensearch.alerting.settings.AlertingSettings import org.opensearch.alerting.util.AlertingException @@ -38,6 +35,8 @@ import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.alerting.action.AcknowledgeAlertRequest import org.opensearch.commons.alerting.action.AcknowledgeAlertResponse import org.opensearch.commons.alerting.action.AlertingActions +import org.opensearch.commons.alerting.action.GetMonitorRequest +import org.opensearch.commons.alerting.action.GetMonitorResponse import org.opensearch.commons.alerting.model.Alert import org.opensearch.commons.alerting.model.Monitor import org.opensearch.commons.alerting.util.optionalTimeField @@ -94,7 +93,7 @@ class TransportAcknowledgeAlertAction @Inject constructor( RestRequest.Method.GET, FetchSourceContext.FETCH_SOURCE ) - execute(GetMonitorAction.INSTANCE, getMonitorRequest, it) + execute(AlertingActions.GET_MONITOR_ACTION_TYPE, getMonitorRequest, it) } if (getMonitorResponse.monitor == null) { actionListener.onFailure( diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt index 16ce7fb17..07186bca6 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt @@ -18,9 +18,6 @@ import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters import org.opensearch.action.support.HandledTransportAction -import org.opensearch.alerting.action.GetMonitorAction -import org.opensearch.alerting.action.GetMonitorRequest -import org.opensearch.alerting.action.GetMonitorResponse import org.opensearch.alerting.alerts.AlertIndices.Companion.ALL_FINDING_INDEX_PATTERN import org.opensearch.alerting.opensearchapi.suspendUntil import org.opensearch.alerting.settings.AlertingSettings @@ -35,6 +32,8 @@ import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.alerting.action.AlertingActions import org.opensearch.commons.alerting.action.GetFindingsRequest import org.opensearch.commons.alerting.action.GetFindingsResponse +import org.opensearch.commons.alerting.action.GetMonitorRequest +import org.opensearch.commons.alerting.action.GetMonitorResponse import org.opensearch.commons.alerting.model.Finding import org.opensearch.commons.alerting.model.FindingDocument import org.opensearch.commons.alerting.model.FindingWithDocs @@ -167,7 +166,7 @@ class TransportGetFindingsSearchAction @Inject constructor( ) val getMonitorResponse: GetMonitorResponse = this@TransportGetFindingsSearchAction.client.suspendUntil { - execute(GetMonitorAction.INSTANCE, getMonitorRequest, it) + execute(AlertingActions.GET_MONITOR_ACTION_TYPE, getMonitorRequest, it) } indexName = getMonitorResponse.monitor?.dataSources?.findingsIndex ?: ALL_FINDING_INDEX_PATTERN } diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/transport/AlertingSingleNodeTestCase.kt b/alerting/src/test/kotlin/org/opensearch/alerting/transport/AlertingSingleNodeTestCase.kt index d202d77d8..526adaa34 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/transport/AlertingSingleNodeTestCase.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/transport/AlertingSingleNodeTestCase.kt @@ -22,8 +22,6 @@ import org.opensearch.alerting.action.ExecuteMonitorResponse import org.opensearch.alerting.action.ExecuteWorkflowAction import org.opensearch.alerting.action.ExecuteWorkflowRequest import org.opensearch.alerting.action.ExecuteWorkflowResponse -import org.opensearch.alerting.action.GetMonitorAction -import org.opensearch.alerting.action.GetMonitorRequest import org.opensearch.alerting.alerts.AlertIndices import org.opensearch.alerting.model.MonitorMetadata import org.opensearch.alerting.model.WorkflowMetadata @@ -37,6 +35,7 @@ import org.opensearch.commons.alerting.action.DeleteMonitorRequest import org.opensearch.commons.alerting.action.DeleteWorkflowRequest import org.opensearch.commons.alerting.action.GetFindingsRequest import org.opensearch.commons.alerting.action.GetFindingsResponse +import org.opensearch.commons.alerting.action.GetMonitorRequest import org.opensearch.commons.alerting.action.GetWorkflowAlertsRequest import org.opensearch.commons.alerting.action.GetWorkflowAlertsResponse import org.opensearch.commons.alerting.action.GetWorkflowRequest @@ -346,7 +345,7 @@ abstract class AlertingSingleNodeTestCase : OpenSearchSingleNodeTestCase() { version: Long = 1L, fetchSourceContext: FetchSourceContext = FetchSourceContext.FETCH_SOURCE, ) = client().execute( - GetMonitorAction.INSTANCE, + AlertingActions.GET_MONITOR_ACTION_TYPE, GetMonitorRequest(monitorId, version, RestRequest.Method.GET, fetchSourceContext) ).get()