-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added transport layer classes for getting and deleting the workflow #835
Changes from 1 commit
21669c3
4566de0
0ab964a
691824c
ca264ee
e70fccd
a98a8c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import org.opensearch.action.search.SearchResponse | |
import org.opensearch.action.support.ActionFilters | ||
import org.opensearch.action.support.HandledTransportAction | ||
import org.opensearch.action.support.WriteRequest.RefreshPolicy | ||
import org.opensearch.alerting.opensearchapi.addFilter | ||
import org.opensearch.alerting.opensearchapi.suspendUntil | ||
import org.opensearch.alerting.settings.AlertingSettings | ||
import org.opensearch.alerting.util.AlertingException | ||
|
@@ -54,8 +55,6 @@ import org.opensearch.search.builder.SearchSourceBuilder | |
import org.opensearch.tasks.Task | ||
import org.opensearch.transport.TransportService | ||
|
||
private val log = LogManager.getLogger(TransportIndexMonitorAction::class.java) | ||
|
||
/** | ||
* Transport class that deletes the workflow. | ||
* If the deleteDelegateMonitor flag is set to true, deletes the workflow delegates that are not part of another workflow | ||
|
@@ -72,6 +71,8 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
), | ||
SecureTransportAction { | ||
|
||
private val log = LogManager.getLogger(javaClass) | ||
|
||
@Volatile override var filterByEnabled = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings) | ||
|
||
init { | ||
|
@@ -126,10 +127,11 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
|
||
if (canDelete) { | ||
val deleteResponse = deleteWorkflow(workflow) | ||
deleteMetadata(workflow) | ||
// TODO - uncomment once the metadata are introduced | ||
// deleteMetadata(workflow) | ||
if (deleteDelegateMonitors == true) { | ||
val delegateMonitorIds = (workflow.inputs[0] as CompositeInput).getMonitorIds() | ||
val monitorIdsToBeDeleted = getDeletableDelegates(workflowId, delegateMonitorIds) | ||
val monitorIdsToBeDeleted = getDeletableDelegates(workflowId, delegateMonitorIds, user) | ||
|
||
// Delete the monitor ids | ||
if (monitorIdsToBeDeleted.isNotEmpty()) { | ||
|
@@ -177,7 +179,7 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
* @param workflowIdToBeDeleted Id of the workflow that should be deleted | ||
* @param monitorIds List of delegate monitor ids (underlying monitor ids) | ||
*/ | ||
private suspend fun getDeletableDelegates(workflowIdToBeDeleted: String, monitorIds: List<String>): List<String> { | ||
private suspend fun getDeletableDelegates(workflowIdToBeDeleted: String, monitorIds: List<String>, user: User?): List<String> { | ||
// Retrieve monitors belonging to another workflows | ||
val queryBuilder = QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("_id", workflowIdToBeDeleted)).filter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to check if the user has permissions to these monitor with the backend roles too as the monitors could get modified later and the user might not have the backend roles to access those monitors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaahh got it! Good point |
||
QueryBuilders.nestedQuery( | ||
|
@@ -194,7 +196,12 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
|
||
val searchRequest = SearchRequest() | ||
.indices(ScheduledJob.SCHEDULED_JOBS_INDEX) | ||
.source(SearchSourceBuilder().query(queryBuilder).fetchSource(true)) | ||
.source(SearchSourceBuilder().query(queryBuilder)) | ||
|
||
// Check if user can access the monitors (since the monitors could get modified later and the user might not have the backend roles to access the monitors) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: remove extra space ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
if (user != null && filterByEnabled) { | ||
addFilter(user, searchRequest.source(), "monitor.user.backend_roles.keyword") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a |
||
|
||
val searchResponse: SearchResponse = client.suspendUntil { search(searchRequest, it) } | ||
|
||
|
@@ -239,7 +246,7 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
log.debug("Deleting the workflow with id ${deleteRequest.id()}") | ||
return client.suspendUntil { delete(deleteRequest, it) } | ||
} | ||
|
||
// TODO - use once the workflow metadata concept is introduced | ||
private suspend fun deleteMetadata(workflow: Workflow) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz add debug logs like "deleting metadata", There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok this part is copy pasted - even we don't have workflow metada. will comment out the call and add TODO - since we are going to introduce the metadata with workflow execution. Tnx! |
||
val deleteRequest = DeleteRequest(ScheduledJob.SCHEDULED_JOBS_INDEX, "${workflow.id}-metadata") | ||
val deleteResponse: DeleteResponse = client.suspendUntil { delete(deleteRequest, it) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add try catch for failure in deletion and log error and re-throw wrapped exception |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
package org.opensearch.alerting.transport | ||
|
||
import org.apache.logging.log4j.LogManager | ||
import org.opensearch.OpenSearchStatusException | ||
import org.opensearch.action.ActionListener | ||
import org.opensearch.action.get.GetRequest | ||
|
@@ -43,6 +44,8 @@ class TransportGetWorkflowAction @Inject constructor( | |
), | ||
SecureTransportAction { | ||
|
||
private val log = LogManager.getLogger(javaClass) | ||
|
||
@Volatile override var filterByEnabled = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings) | ||
|
||
init { | ||
|
@@ -64,6 +67,7 @@ class TransportGetWorkflowAction @Inject constructor( | |
object : ActionListener<GetResponse> { | ||
override fun onResponse(response: GetResponse) { | ||
if (!response.isExists) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error log |
||
log.error("Workflow with ${getWorkflowRequest.workflowId} not found") | ||
actionListener.onFailure( | ||
AlertingException.wrap( | ||
OpenSearchStatusException( | ||
|
@@ -110,6 +114,8 @@ class TransportGetWorkflowAction @Inject constructor( | |
} | ||
|
||
override fun onFailure(t: Exception) { | ||
log.error("Getting the workflow failed", t) | ||
|
||
if (t is IndexNotFoundException) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error log |
||
actionListener.onFailure( | ||
OpenSearchStatusException( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we attempt to delete monitors first and then delete the workflow? And only delete everything if the user has permission to delete everything?