Skip to content

Commit

Permalink
Recreate request object from writeable for Get alerts and get findings (
Browse files Browse the repository at this point in the history
#577)

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
  • Loading branch information
eirsep committed Sep 28, 2022
1 parent 6c7866d commit 860d0b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -60,7 +62,7 @@ class TransportGetAlertsAction @Inject constructor(
val settings: Settings,
val xContentRegistry: NamedXContentRegistry,
val transportGetMonitorAction: TransportGetMonitorAction
) : HandledTransportAction<GetAlertsRequest, GetAlertsResponse>(
) : HandledTransportAction<ActionRequest, GetAlertsResponse>(
AlertingActions.GET_ALERTS_ACTION_NAME, transportService, actionFilters, ::GetAlertsRequest
),
SecureTransportAction {
Expand All @@ -74,9 +76,11 @@ class TransportGetAlertsAction @Inject constructor(

override fun doExecute(
task: Task,
getAlertsRequest: GetAlertsRequest,
request: ActionRequest,
actionListener: ActionListener<GetAlertsResponse>
) {
val getAlertsRequest = request as? GetAlertsRequest
?: recreateObject(request) { GetAlertsRequest(it) }
val user = readUserFromThreadContext(client)

val tableProp = getAlertsRequest.table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -62,7 +64,7 @@ class TransportGetFindingsSearchAction @Inject constructor(
actionFilters: ActionFilters,
val settings: Settings,
val xContentRegistry: NamedXContentRegistry
) : HandledTransportAction<GetFindingsRequest, GetFindingsResponse> (
) : HandledTransportAction<ActionRequest, GetFindingsResponse> (
AlertingActions.GET_FINDINGS_ACTION_NAME, transportService, actionFilters, ::GetFindingsRequest
),
SecureTransportAction {
Expand All @@ -75,9 +77,11 @@ class TransportGetFindingsSearchAction @Inject constructor(

override fun doExecute(
task: Task,
getFindingsRequest: GetFindingsRequest,
request: ActionRequest,
actionListener: ActionListener<GetFindingsResponse>
) {
val getFindingsRequest = request as? GetFindingsRequest
?: recreateObject(request) { GetFindingsRequest(it) }
val tableProp = getFindingsRequest.table

val sortBuilder = SortBuilders
Expand Down

0 comments on commit 860d0b7

Please sign in to comment.