This is an automated email from the ASF dual-hosted git repository.

DImuthuUpe pushed a commit to branch workflow-pause-on-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/workflow-pause-on-auth by this 
push:
     new abfa0ca12d Adding workflow retry support
abfa0ca12d is described below

commit abfa0ca12d124023449919f5f1d0f7636bd3fc0c
Author: DImuthuUpe <[email protected]>
AuthorDate: Sat Nov 7 07:58:50 2026 -0500

    Adding workflow retry support
---
 api/process/controller/launch.go          |  16 +++-
 api/process/service/retry.go              | 123 ++++++++++++++++++++++++++++++
 api/process/service/retry_test.go         |  74 ++++++++++++++++++
 dashboard/src/app/processes/view/page.tsx |  28 ++++++-
 docs/api.md                               |  41 ++++++++++
 docs/openapi.yaml                         |  26 +++++++
 6 files changed, 303 insertions(+), 5 deletions(-)

diff --git a/api/process/controller/launch.go b/api/process/controller/launch.go
index 1d0c0df078..bc065fa3ab 100644
--- a/api/process/controller/launch.go
+++ b/api/process/controller/launch.go
@@ -40,10 +40,11 @@ func NewLaunchController(svc *service.LaunchService) 
*LaunchController {
        return &LaunchController{svc: svc}
 }
 
-// Register mounts the launch route. The literal /launch segment cannot 
collide with
-// the task collections beside it, so no ordering is implied.
+// Register mounts the launch and retry routes. Their literal segments cannot 
collide
+// with the task collections beside them, so no ordering is implied.
 func (h *LaunchController) Register(mux *http.ServeMux) {
        mux.HandleFunc("POST /api/v1/processes/{processId}/launch", h.launch)
+       mux.HandleFunc("POST /api/v1/processes/{processId}/retry", h.retry)
 }
 
 // launch answers 202 rather than 200: the tasks are recorded here, and 
carrying them
@@ -57,3 +58,14 @@ func (h *LaunchController) launch(w http.ResponseWriter, r 
*http.Request) {
        }
        httpx.WriteJSON(w, http.StatusAccepted, proc)
 }
+
+// retry answers 202 for the same reason launch does: it starts the failed 
workflow
+// again, and carrying it out is later work.
+func (h *LaunchController) retry(w http.ResponseWriter, r *http.Request) {
+       proc, err := h.svc.RetryProcess(r.Context(), r.PathValue("processId"))
+       if err != nil {
+               httpx.WriteError(w, r, err)
+               return
+       }
+       httpx.WriteJSON(w, http.StatusAccepted, proc)
+}
diff --git a/api/process/service/retry.go b/api/process/service/retry.go
new file mode 100644
index 0000000000..fded205fd4
--- /dev/null
+++ b/api/process/service/retry.go
@@ -0,0 +1,123 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+ */
+
+package service
+
+import (
+       "context"
+       "log/slog"
+
+       "github.com/google/uuid"
+
+       "github.com/apache/airavata/internal/httpx"
+       "github.com/apache/airavata/internal/ptr"
+
+       "github.com/apache/airavata/api/process/dto"
+       procmodel "github.com/apache/airavata/api/process/model"
+)
+
+// RetryProcess starts again the workflow of a launched process that failed.
+//
+// Only the failed workflow is run again: a process whose job was submitted 
but whose
+// completion failed runs its completion workflow, not a second submission. 
Inside it,
+// each task that already completed is passed over rather than repeated (see
+// execution.TaskTracker.Track), so a retry picks up at the step that failed.
+//
+// Owner-scoped like LaunchProcess, for the same reason. A process with a 
workflow still
+// running, or none that failed, is refused with a conflict rather than 
started twice.
+func (s *LaunchService) RetryProcess(ctx context.Context, processID string) 
(*dto.Response, error) {
+       proc, err := s.processService.Get(ctx, processID)
+       if err != nil {
+               return nil, notFoundAs(err, "Process not found: %s", processID)
+       }
+       if err := s.requireOwnership(ctx, proc); err != nil {
+               return nil, err
+       }
+
+       recorded, err := s.processWorkflows.FindByProcessID(ctx, processID)
+       if err != nil {
+               return nil, err
+       }
+       workflowType, err := workflowToRetry(processID, recorded)
+       if err != nil {
+               return nil, err
+       }
+
+       // The new workflow is recorded RUNNING before it starts, so a second 
retry arriving
+       // meanwhile sees it running and is refused. The workflow records 
RUNNING again when
+       // it begins, which changes nothing, and then its outcome.
+       workflowID := uuid.NewString()
+       if _, err := s.processWorkflows.Record(ctx, processID, workflowID, 
workflowType,
+               procmodel.ProcessWorkflowStatusTypeRunning); err != nil {
+               return nil, err
+       }
+       if err := s.executionEngine.LaunchWorkflow(ctx, workflowID, processID, 
workflowType); err != nil {
+               slog.Error("Failed to start retried workflow", "processId", 
processID, "workflowId", workflowID, "error", err)
+               if _, recErr := s.processWorkflows.Record(ctx, processID, 
workflowID, workflowType,
+                       procmodel.ProcessWorkflowStatusTypeFailed); recErr != 
nil {
+                       slog.Error("Failed to record process workflow", 
"processId", processID, "workflowId", workflowID, "error", recErr)
+               }
+               return nil, err
+       }
+       slog.Info("Retried process workflow", "processId", processID, 
"workflowId", workflowID, "workflowType", workflowType)
+
+       status, log := procmodel.ProcessStatusTypeSubmitted, "Retrying the 
failed job submission"
+       if workflowType == procmodel.ProcessWorkflowTypeJobCompletion {
+               status, log = procmodel.ProcessStatusTypeRunning, "Retrying the 
failed job completion"
+       }
+       if _, err := s.statusService.Record(ctx, processID, status, 
ptr.To(log)); err != nil {
+               return nil, err
+       }
+       return proc, nil
+}
+
+// workflowToRetry picks the workflow a retry runs again from the workflows 
recorded for
+// a process, oldest first. Each workflow type is judged by its latest run, 
since an
+// earlier failure that a later run of the same type got past needs nothing.
+//
+// Submission comes first: until a job is submitted there is nothing to 
complete. A
+// completion is retried only once the submission succeeded, so the job is 
never
+// submitted twice.
+// TODO: Closely review later to generalize for other workflow types beyond 
submission and completion.
+func workflowToRetry(processID string, recorded []procmodel.ProcessWorkflow) 
(procmodel.ProcessWorkflowType, error) {
+       latest := 
map[procmodel.ProcessWorkflowType]procmodel.ProcessWorkflowStatusType{}
+       for _, w := range recorded {
+               if w.WorkflowType == nil || w.Status == nil {
+                       continue
+               }
+               latest[*w.WorkflowType] = *w.Status
+       }
+       for _, status := range latest {
+               if status == procmodel.ProcessWorkflowStatusTypeRunning {
+                       return "", httpx.Conflict("Process %s has a workflow 
still running", processID)
+               }
+       }
+
+       submission, launched := 
latest[procmodel.ProcessWorkflowTypeBatchJobSubmission]
+       switch {
+       case !launched:
+               return "", httpx.Conflict("Process %s has not been launched", 
processID)
+       case submission == procmodel.ProcessWorkflowStatusTypeFailed:
+               return procmodel.ProcessWorkflowTypeBatchJobSubmission, nil
+       case latest[procmodel.ProcessWorkflowTypeJobCompletion] == 
procmodel.ProcessWorkflowStatusTypeFailed:
+               return procmodel.ProcessWorkflowTypeJobCompletion, nil
+       }
+       return "", httpx.Conflict("Process %s has no failed workflow to retry", 
processID)
+}
diff --git a/api/process/service/retry_test.go 
b/api/process/service/retry_test.go
new file mode 100644
index 0000000000..2ceeda17ee
--- /dev/null
+++ b/api/process/service/retry_test.go
@@ -0,0 +1,74 @@
+/**
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+ */
+
+package service
+
+import (
+       "errors"
+       "net/http"
+       "testing"
+
+       "github.com/apache/airavata/internal/httpx"
+
+       procmodel "github.com/apache/airavata/api/process/model"
+)
+
+func TestWorkflowToRetry(t *testing.T) {
+       const (
+               sub  = procmodel.ProcessWorkflowTypeBatchJobSubmission
+               comp = procmodel.ProcessWorkflowTypeJobCompletion
+
+               running   = procmodel.ProcessWorkflowStatusTypeRunning
+               succeeded = procmodel.ProcessWorkflowStatusTypeSucceeded
+               failed    = procmodel.ProcessWorkflowStatusTypeFailed
+       )
+       run := func(wt procmodel.ProcessWorkflowType, st 
procmodel.ProcessWorkflowStatusType) procmodel.ProcessWorkflow {
+               return procmodel.ProcessWorkflow{WorkflowType: &wt, Status: &st}
+       }
+
+       for _, tc := range []struct {
+               name     string
+               recorded []procmodel.ProcessWorkflow
+               want     procmodel.ProcessWorkflowType // empty: refused with a 
conflict
+       }{
+               {"never launched", nil, ""},
+               {"submission failed", []procmodel.ProcessWorkflow{run(sub, 
failed)}, sub},
+               {"submission still running", 
[]procmodel.ProcessWorkflow{run(sub, running)}, ""},
+               {"submission succeeded, nothing failed", 
[]procmodel.ProcessWorkflow{run(sub, succeeded)}, ""},
+               {"completion failed", []procmodel.ProcessWorkflow{run(sub, 
succeeded), run(comp, failed)}, comp},
+               {"completion retried and running", 
[]procmodel.ProcessWorkflow{run(sub, succeeded), run(comp, failed), run(comp, 
running)}, ""},
+               {"earlier failure already got past", 
[]procmodel.ProcessWorkflow{run(sub, failed), run(sub, succeeded)}, ""},
+               {"submission retried and failed again", 
[]procmodel.ProcessWorkflow{run(sub, failed), run(sub, failed)}, sub},
+       } {
+               t.Run(tc.name, func(t *testing.T) {
+                       got, err := workflowToRetry("proc-1", tc.recorded)
+                       if tc.want == "" {
+                               var he *httpx.Error
+                               if !errors.As(err, &he) || he.Status != 
http.StatusConflict {
+                                       t.Fatalf("workflowToRetry = %q, %v; 
want a conflict", got, err)
+                               }
+                               return
+                       }
+                       if err != nil || got != tc.want {
+                               t.Fatalf("workflowToRetry = %q, %v; want %q", 
got, err, tc.want)
+                       }
+               })
+       }
+}
diff --git a/dashboard/src/app/processes/view/page.tsx 
b/dashboard/src/app/processes/view/page.tsx
index da9c075ca2..aee00a5b7f 100644
--- a/dashboard/src/app/processes/view/page.tsx
+++ b/dashboard/src/app/processes/view/page.tsx
@@ -35,6 +35,18 @@ const WORKFLOW_LABELS: Record<ProcessWorkflowType, string> = 
{
   BATCH_JOB_COMPLETION: "Job completion",
 };
 
+// Whether a retry would be accepted, by the same rule the server applies: no 
workflow
+// is running, and the latest submission failed, or it succeeded and the latest
+// completion failed. The server decides; this only chooses whether to offer 
it.
+function canRetry(workflows: ProcessWorkflow[] | null | undefined): boolean {
+  const latest = new Map<string, string | null>();
+  for (const w of workflows ?? []) if (w.workflowType) 
latest.set(w.workflowType, w.status);
+  if ([...latest.values()].includes("RUNNING")) return false;
+  const submission = latest.get("BATCH_JOB_SUBMISSION");
+  if (submission === undefined) return false;
+  return submission === "FAILED" || latest.get("BATCH_JOB_COMPLETION") === 
"FAILED";
+}
+
 // Fields every task carries; the rest are kind-specific and shown as they 
come.
 const COMMON_TASK_FIELDS = new Set(["taskId", "processId", "onFailure", 
"retryCount", "taskOrder"]);
 
@@ -88,11 +100,11 @@ function ProcessView() {
   const taskOrder = new Map<string, number | null>();
   d?.tasks.forEach((list) => list?.forEach((t) => taskOrder.set(t.taskId, 
t.taskOrder)));
 
-  const launch = async () => {
+  const act = async (action: "launch" | "retry") => {
     setBusy(true);
     setError(null);
     try {
-      await api.post(`/api/v1/processes/${id}/launch`);
+      await api.post(`/api/v1/processes/${id}/${action}`);
       setLive(true);
       await detail.reload();
     } catch (e) {
@@ -130,10 +142,20 @@ function ProcessView() {
           <button onClick={() => setLive(true)}>Resume live updates</button>
         )}
         {latest?.status === "CREATED" && (
-          <button className="primary" disabled={busy} onClick={() => void 
launch()}>
+          <button className="primary" disabled={busy} onClick={() => void 
act("launch")}>
             {busy ? "Launching…" : "Launch"}
           </button>
         )}
+        {canRetry(d?.workflows) && (
+          <button
+            className="primary"
+            disabled={busy}
+            title="Run the failed workflow again, skipping tasks that already 
completed"
+            onClick={() => void act("retry")}
+          >
+            {busy ? "Retrying…" : "Retry"}
+          </button>
+        )}
       </PageHead>
       <Alert>{detail.error || error}</Alert>
 
diff --git a/docs/api.md b/docs/api.md
index b95621e713..c285a4aa3d 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -2000,6 +2000,47 @@ refused with `409` rather than doubling the work. Only 
`FILE` declarations are s
 today: the `FILE_LIST` and `DIRECTORY` branches are stubs, so a run carrying 
those is
 launched without staging tasks for them.
 
+### Retry a Process
+
+```
+POST /api/v1/processes/{processId}/retry
+```
+
+Starts again the [workflow](#process-workflows) of a launched run that failed,
+**skipping what already completed**. Owner-scoped like launching, and takes no 
body.
+
+Only the failed workflow runs again. Each workflow type is judged by its 
latest run:
+
+- if the latest job submission workflow failed, a new one is started;
+- if the submission succeeded and the latest job completion workflow failed, 
only the
+  completion workflow is started — the job is never submitted twice.
+
+Inside the new workflow, every [task](#process-tasks) that has already 
recorded a
+`COMPLETED` status is passed over rather than run again, so the retry picks up 
at the
+step that failed: staged inputs are not copied again, and a job that was 
submitted is
+not resubmitted.
+
+The new workflow appears straight away in the process's workflows as 
`RUNNING`, and the
+process records a new status — `SUBMITTED` when the submission is retried, 
`RUNNING`
+when the completion is — with a log saying what was retried.
+
+```bash
+curl -s -X POST localhost:9095/api/v1/processes/"$PROCESS_ID"/retry \
+  -H "Authorization: Bearer $TOKEN"
+```
+
+**Response — `202 Accepted`**, with the process as its body, for the same 
reason as
+[launching](#launch-a-process).
+
+**Errors**
+
+| Status | Cause |
+|---|---|
+| `401 Unauthorized` | no token |
+| `403 Forbidden` | the run belongs to another user |
+| `404 Not Found` | no such process |
+| `409 Conflict` | a workflow of the run is still running; the run has not 
been launched; or no workflow's latest run failed |
+
 ## Process Statuses
 
 A run's status history, read-only and nested under the process:
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index d1974bb029..bb8626e629 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1842,6 +1842,32 @@ paths:
         "502": { $ref: "#/components/responses/BadGateway" }
         "500": { $ref: "#/components/responses/InternalError" }
 
+  /api/v1/processes/{processId}/retry:
+    parameters:
+      - $ref: "#/components/parameters/ProcessId"
+    post:
+      tags: [Processes]
+      summary: Retry a process's failed workflow
+      description: |
+        Owner only. Takes no body. Starts again the workflow whose latest run 
failed —
+        the job submission, or, once that succeeded, the job completion — and 
skips
+        every task that has already completed, so the run picks up at the step 
that
+        failed. Refused with `409` while a workflow is still running, before 
the
+        process is launched, or when no workflow's latest run failed. Answers 
`202`
+        with the process as it now stands.
+      operationId: retryProcess
+      responses:
+        "202":
+          description: The retry was accepted; the process is returned as it 
now stands.
+          content:
+            application/json:
+              schema: { $ref: "#/components/schemas/ProcessResponse" }
+        "401": { $ref: "#/components/responses/Unauthorized" }
+        "403": { $ref: "#/components/responses/Forbidden" }
+        "404": { $ref: "#/components/responses/NotFound" }
+        "409": { $ref: "#/components/responses/Conflict" }
+        "500": { $ref: "#/components/responses/InternalError" }
+
   /api/v1/processes/{processId}/statuses:
     parameters:
       - $ref: "#/components/parameters/ProcessId"

Reply via email to