Skip to content

Commit

Permalink
Don't attempt to parse workflow if it doesn't exist (#1346)
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Engelbrecht <[email protected]>
(cherry picked from commit 733fd4e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 3, 2024
1 parent 570405a commit 8957794
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 8957794

Please sign in to comment.