Skip to content

Commit

Permalink
Don't attempt to parse workflow if it doesn't exist (#1346) (#1361)
Browse files Browse the repository at this point in the history
(cherry picked from commit 733fd4e)

Signed-off-by: Chase Engelbrecht <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent abf0c51 commit e7505da
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class TransportDeleteWorkflowAction @Inject constructor(
) {
suspend fun resolveUserAndStart() {
try {
val workflow = getWorkflow()
val workflow: Workflow = getWorkflow() ?: return

val canDelete = user == null ||
!doFilterForUser(user) ||
Expand Down Expand Up @@ -296,17 +296,27 @@ class TransportDeleteWorkflowAction @Inject constructor(
return deletableMonitors
}

private suspend fun getWorkflow(): Workflow {
private suspend fun getWorkflow(): Workflow? {
val getRequest = GetRequest(ScheduledJob.SCHEDULED_JOBS_INDEX, workflowId)

val getResponse: GetResponse = client.suspendUntil { get(getRequest, it) }
if (getResponse.isExists == false) {
actionListener.onFailure(
AlertingException.wrap(
OpenSearchStatusException("Workflow not found.", RestStatus.NOT_FOUND)
)
)
if (!getResponse.isExists) {
handleWorkflowMissing()
return null
}

return parseWorkflow(getResponse)
}

private fun handleWorkflowMissing() {
actionListener.onFailure(
AlertingException.wrap(
OpenSearchStatusException("Workflow not found.", RestStatus.NOT_FOUND)
)
)
}

private fun parseWorkflow(getResponse: GetResponse): Workflow {
val xcp = XContentHelper.createParser(
xContentRegistry, LoggingDeprecationHandler.INSTANCE,
getResponse.sourceAsBytesRef, XContentType.JSON
Expand Down

0 comments on commit e7505da

Please sign in to comment.