From 860d0b78101d88109f59406af1db9f15a28e8f3f Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Wed, 28 Sep 2022 16:55:21 -0700 Subject: [PATCH] Recreate request object from writeable for Get alerts and get findings (#577) Signed-off-by: Surya Sashank Nistala --- .../alerting/transport/TransportGetAlertsAction.kt | 8 ++++++-- .../alerting/transport/TransportGetFindingsAction.kt | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt index 9b2bda539..aca172a46 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.apache.logging.log4j.LogManager import org.opensearch.action.ActionListener +import org.opensearch.action.ActionRequest import org.opensearch.action.search.SearchRequest import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.ActionFilters @@ -38,6 +39,7 @@ import org.opensearch.commons.alerting.action.GetAlertsRequest import org.opensearch.commons.alerting.action.GetAlertsResponse import org.opensearch.commons.alerting.model.Alert import org.opensearch.commons.authuser.User +import org.opensearch.commons.utils.recreateObject import org.opensearch.index.query.Operator import org.opensearch.index.query.QueryBuilders import org.opensearch.rest.RestRequest @@ -60,7 +62,7 @@ class TransportGetAlertsAction @Inject constructor( val settings: Settings, val xContentRegistry: NamedXContentRegistry, val transportGetMonitorAction: TransportGetMonitorAction -) : HandledTransportAction( +) : HandledTransportAction( AlertingActions.GET_ALERTS_ACTION_NAME, transportService, actionFilters, ::GetAlertsRequest ), SecureTransportAction { @@ -74,9 +76,11 @@ class TransportGetAlertsAction @Inject constructor( override fun doExecute( task: Task, - getAlertsRequest: GetAlertsRequest, + request: ActionRequest, actionListener: ActionListener ) { + val getAlertsRequest = request as? GetAlertsRequest + ?: recreateObject(request) { GetAlertsRequest(it) } val user = readUserFromThreadContext(client) val tableProp = getAlertsRequest.table 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 4c825dde4..9b49968bc 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.withContext import org.apache.logging.log4j.LogManager import org.apache.lucene.search.join.ScoreMode import org.opensearch.action.ActionListener +import org.opensearch.action.ActionRequest import org.opensearch.action.get.MultiGetRequest import org.opensearch.action.get.MultiGetResponse import org.opensearch.action.search.SearchRequest @@ -42,6 +43,7 @@ import org.opensearch.commons.alerting.action.GetFindingsResponse import org.opensearch.commons.alerting.model.Finding import org.opensearch.commons.alerting.model.FindingDocument import org.opensearch.commons.alerting.model.FindingWithDocs +import org.opensearch.commons.utils.recreateObject import org.opensearch.index.query.Operator import org.opensearch.index.query.QueryBuilders import org.opensearch.rest.RestRequest @@ -62,7 +64,7 @@ class TransportGetFindingsSearchAction @Inject constructor( actionFilters: ActionFilters, val settings: Settings, val xContentRegistry: NamedXContentRegistry -) : HandledTransportAction ( +) : HandledTransportAction ( AlertingActions.GET_FINDINGS_ACTION_NAME, transportService, actionFilters, ::GetFindingsRequest ), SecureTransportAction { @@ -75,9 +77,11 @@ class TransportGetFindingsSearchAction @Inject constructor( override fun doExecute( task: Task, - getFindingsRequest: GetFindingsRequest, + request: ActionRequest, actionListener: ActionListener ) { + val getFindingsRequest = request as? GetFindingsRequest + ?: recreateObject(request) { GetFindingsRequest(it) } val tableProp = getFindingsRequest.table val sortBuilder = SortBuilders