Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ class TransportDeleteWorkflowAction @Inject constructor(
if (canDelete) {
val delegateMonitorIds = (workflow.inputs[0] as CompositeInput).getMonitorIds()
var deletableMonitors = listOf<Monitor>()
val delegateMonitors = getDeletableDelegates(workflowId, delegateMonitorIds, user)
// User can only delete the delegate monitors only in the case if all monitors can be deleted
// if there are monitors in this workflow that are referenced in other workflows, we cannot delete the monitors.
// We will not partially delete monitors. we delete them all or fail the request.
if (deleteDelegateMonitors == true) {
deletableMonitors = getDeletableDelegates(workflowId, delegateMonitorIds, user)
deletableMonitors = delegateMonitors
val monitorsDiff = delegateMonitorIds.toMutableList()
monitorsDiff.removeAll(deletableMonitors.map { it.id })

Expand All @@ -168,10 +169,11 @@ class TransportDeleteWorkflowAction @Inject constructor(
val failedMonitorIds = tryDeletingMonitors(deletableMonitors, RefreshPolicy.IMMEDIATE)
// Update delete workflow response
deleteWorkflowResponse.nonDeletedMonitors = failedMonitorIds
// Delete monitors workflow metadata
// Monitor metadata will be in workflowId-monitorId-metadata format
metadataIdsToDelete.addAll(deletableMonitors.map { MonitorMetadata.getId(it, workflowMetadataId) })
}

// Delete monitors workflow metadata
// Monitor metadata will be in workflowId-metadata-monitorId-metadata format
metadataIdsToDelete.addAll(delegateMonitors.map { MonitorMetadata.getId(it, workflowMetadataId) })
try {
// Delete the monitors workflow metadata
val deleteMonitorWorkflowMetadataResponse: BulkByScrollResponse = client.suspendUntil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5055,6 +5055,9 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
assertNotNull(getWorkflowResponse)
assertEquals(workflowId, getWorkflowResponse.id)

// Verify that monitor workflow metadata exists
assertNotNull(searchMonitorMetadata("${workflowResponse.id}-metadata-${monitorResponse.id}-metadata"))

deleteWorkflow(workflowId, false)
// Verify that the workflow is deleted
try {
Expand All @@ -5070,6 +5073,19 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
// Verify that the monitor is not deleted
val existingDelegate = getMonitorResponse(monitorResponse.id)
assertNotNull(existingDelegate)

// Verify that the monitor workflow metadata is deleted
try {
searchMonitorMetadata("${workflowResponse.id}-metadata-${monitorResponse.id}-metadata")
fail("expected searchMonitorMetadata method to throw exception")
} catch (e: Exception) {
e.message?.let {
assertTrue(
"Expected 0 hits for searchMonitorMetadata, got non-0 results.",
it.contains("List is empty")
)
}
}
}

fun `test delete workflow delegate monitor deleted`() {
Expand All @@ -5095,6 +5111,9 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
assertNotNull(getWorkflowResponse)
assertEquals(workflowId, getWorkflowResponse.id)

// Verify that monitor workflow metadata exists
assertNotNull(searchMonitorMetadata("${workflowResponse.id}-metadata-${monitorResponse.id}-metadata"))

deleteWorkflow(workflowId, true)
// Verify that the workflow is deleted
try {
Expand All @@ -5118,6 +5137,18 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
)
}
}
// Verify that the monitor workflow metadata is deleted
try {
searchMonitorMetadata("${workflowResponse.id}-metadata-${monitorResponse.id}-metadata")
fail("expected searchMonitorMetadata method to throw exception")
} catch (e: Exception) {
e.message?.let {
assertTrue(
"Expected 0 hits for searchMonitorMetadata, got non-0 results.",
it.contains("List is empty")
)
}
}
}

fun `test delete executed workflow with metadata deleted`() {
Expand Down
Loading