-
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 3 commits
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 |
---|---|---|
|
@@ -5,9 +5,8 @@ | |
|
||
package org.opensearch.alerting.transport | ||
|
||
import kotlinx.coroutines.CoroutineName | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import org.apache.logging.log4j.LogManager | ||
import org.apache.lucene.search.join.ScoreMode | ||
|
@@ -55,6 +54,7 @@ import org.opensearch.search.builder.SearchSourceBuilder | |
import org.opensearch.tasks.Task | ||
import org.opensearch.transport.TransportService | ||
|
||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO) | ||
/** | ||
* 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 | ||
|
@@ -91,7 +91,7 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
return | ||
} | ||
|
||
GlobalScope.launch(Dispatchers.IO + CoroutineName("DeleteWorkflowAction")) { | ||
scope.launch { | ||
DeleteWorkflowHandler( | ||
client, | ||
actionListener, | ||
|
@@ -126,18 +126,31 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
) | ||
|
||
if (canDelete) { | ||
val deleteResponse = deleteWorkflow(workflow) | ||
// TODO - uncomment once the metadata are introduced | ||
// deleteMetadata(workflow) | ||
val delegateMonitorIds = (workflow.inputs[0] as CompositeInput).getMonitorIds() | ||
|
||
// User can only delete the delegate monitors only in the case if all monitors can be deleted | ||
// Partial monitor deletion is not available | ||
if (deleteDelegateMonitors == true) { | ||
val delegateMonitorIds = (workflow.inputs[0] as CompositeInput).getMonitorIds() | ||
val monitorIdsToBeDeleted = getDeletableDelegates(workflowId, delegateMonitorIds, user) | ||
|
||
// Delete the monitor ids | ||
if (monitorIdsToBeDeleted.isNotEmpty()) { | ||
deleteMonitors(monitorIdsToBeDeleted, RefreshPolicy.IMMEDIATE) | ||
if ( | ||
delegateMonitorIds.size != monitorIdsToBeDeleted.size || delegateMonitorIds.toSet() != monitorIdsToBeDeleted.toSet() | ||
) { | ||
actionListener.onFailure( | ||
AlertingException( | ||
"Not allowed to delete ${delegateMonitorIds.joinToString()} monitors", | ||
RestStatus.FORBIDDEN, | ||
IllegalStateException() | ||
) | ||
) | ||
return | ||
} | ||
} | ||
|
||
val deleteResponse = deleteWorkflow(workflow) | ||
if (deleteDelegateMonitors == true) { | ||
deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE) | ||
} | ||
actionListener.onResponse(DeleteWorkflowResponse(deleteResponse.id, deleteResponse.version)) | ||
} else { | ||
actionListener.onFailure( | ||
|
@@ -198,7 +211,7 @@ class TransportDeleteWorkflowAction @Inject constructor( | |
.indices(ScheduledJob.SCHEDULED_JOBS_INDEX) | ||
.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) | ||
// 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) | ||
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 |
||
|
|
|
This file was deleted.
|
This file was deleted.
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.
Lets remove the monitors from this list that can be deleted from
monitorIdsToBeDeleted