Skip to content
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

[Backport 2.10] Don't attempt to parse workflow if it doesn't exist #1361

Merged
merged 1 commit into from
Mar 11, 2024
Merged
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 @@ -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
Loading