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 eb38cc6c0c Adding the api to monitor task status
eb38cc6c0c is described below

commit eb38cc6c0c220021158f0757c34e9791d95e200e
Author: DImuthuUpe <[email protected]>
AuthorDate: Fri Nov 6 17:27:50 2026 -0500

    Adding the api to monitor task status
---
 api/process/controller/task_status.go     | 65 ++++++++++++++++++++++
 api/process/dto/task_status.go            | 58 +++++++++++++++++++
 api/process/repository/task_status.go     | 12 ++++
 api/process/service/task_status.go        | 92 +++++++++++++++++++++++++++++++
 dashboard/src/app/processes/view/page.tsx | 57 ++++++++++++++++---
 dashboard/src/components/ui.tsx           |  3 +
 dashboard/src/lib/types.ts                | 14 +++++
 internal/app/app.go                       |  2 +
 internal/server/server.go                 |  1 +
 internal/server/server_test.go            | 57 +++++++++++++++++++
 10 files changed, 352 insertions(+), 9 deletions(-)

diff --git a/api/process/controller/task_status.go 
b/api/process/controller/task_status.go
new file mode 100644
index 0000000000..6a98db3829
--- /dev/null
+++ b/api/process/controller/task_status.go
@@ -0,0 +1,65 @@
+/**
+*
+* 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 controller
+
+import (
+       "net/http"
+
+       "github.com/apache/airavata/internal/httpx"
+
+       "github.com/apache/airavata/api/process/service"
+)
+
+// TaskStatusController serves read-only access to the status history of a 
process's
+// tasks, nested under /api/v1/processes/{processId}.
+//
+// One route covers all four task kinds: a status names its kind, so a client 
reads the
+// whole run's task history in one call rather than one per kind.
+type TaskStatusController struct{ svc *service.TaskStatusService }
+
+// NewTaskStatusController returns a handler delegating to svc.
+func NewTaskStatusController(svc *service.TaskStatusService) 
*TaskStatusController {
+       return &TaskStatusController{svc: svc}
+}
+
+// Register mounts the read-only task status routes.
+func (h *TaskStatusController) Register(mux *http.ServeMux) {
+       mux.HandleFunc("GET /api/v1/processes/{processId}/task-statuses", 
h.list)
+       mux.HandleFunc("GET 
/api/v1/processes/{processId}/tasks/{taskId}/statuses", h.listForTask)
+}
+
+func (h *TaskStatusController) list(w http.ResponseWriter, r *http.Request) {
+       statuses, err := h.svc.ListForProcess(r.Context(), 
r.PathValue("processId"))
+       if err != nil {
+               httpx.WriteError(w, r, err)
+               return
+       }
+       httpx.WriteJSON(w, http.StatusOK, statuses)
+}
+
+func (h *TaskStatusController) listForTask(w http.ResponseWriter, r 
*http.Request) {
+       statuses, err := h.svc.ListForTask(r.Context(), 
r.PathValue("processId"), r.PathValue("taskId"))
+       if err != nil {
+               httpx.WriteError(w, r, err)
+               return
+       }
+       httpx.WriteJSON(w, http.StatusOK, statuses)
+}
diff --git a/api/process/dto/task_status.go b/api/process/dto/task_status.go
new file mode 100644
index 0000000000..a04ccb165b
--- /dev/null
+++ b/api/process/dto/task_status.go
@@ -0,0 +1,58 @@
+/**
+*
+* 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 dto
+
+import (
+       model "github.com/apache/airavata/api/process/model"
+)
+
+// TaskStatusResponse is the read model for one recorded task status. Like
+// StatusResponse it has no request counterpart: task statuses are recorded by 
the
+// orchestration engine as it runs a task, never accepted from a client.
+type TaskStatusResponse struct {
+       TaskStatusID string                `json:"taskStatusId"`
+       TaskID       string                `json:"taskId"`
+       TaskType     model.TaskType        `json:"taskType"`
+       ProcessID    *string               `json:"processId"`
+       Status       *model.TaskStatusType `json:"status"`
+       Log          *string               `json:"log"`
+       Timestamp    *int64                `json:"timestamp"`
+}
+
+func ToTaskStatusResponse(s *model.TaskStatus) TaskStatusResponse {
+       return TaskStatusResponse{
+               TaskStatusID: s.ID,
+               TaskID:       s.TaskID,
+               TaskType:     s.TaskType,
+               ProcessID:    s.ProcessID,
+               Status:       s.Status,
+               Log:          s.Log,
+               Timestamp:    s.Timestamp,
+       }
+}
+
+func ToTaskStatusResponses(in []model.TaskStatus) []TaskStatusResponse {
+       out := make([]TaskStatusResponse, 0, len(in))
+       for i := range in {
+               out = append(out, ToTaskStatusResponse(&in[i]))
+       }
+       return out
+}
diff --git a/api/process/repository/task_status.go 
b/api/process/repository/task_status.go
index 383e4a300e..9992ea4064 100644
--- a/api/process/repository/task_status.go
+++ b/api/process/repository/task_status.go
@@ -53,6 +53,18 @@ func (r *TaskStatusRepository) FindByTaskID(ctx 
context.Context, taskID string)
        return out, err
 }
 
+// FindByTaskIDAndProcessID returns every status recorded for one task of one 
process,
+// oldest first. Scoping by process as well stops a task id from one process 
reading
+// another's history.
+func (r *TaskStatusRepository) FindByTaskIDAndProcessID(ctx context.Context, 
taskID, processID string) ([]model.TaskStatus, error) {
+       var out []model.TaskStatus
+       err := r.db.WithContext(ctx).
+               Where("task_id = ? AND process_id = ?", taskID, processID).
+               Order("timestamp").
+               Find(&out).Error
+       return out, err
+}
+
 // FindByProcessID returns every status recorded for the tasks of one process, 
oldest
 // first.
 func (r *TaskStatusRepository) FindByProcessID(ctx context.Context, processID 
string) ([]model.TaskStatus, error) {
diff --git a/api/process/service/task_status.go 
b/api/process/service/task_status.go
new file mode 100644
index 0000000000..68840336c1
--- /dev/null
+++ b/api/process/service/task_status.go
@@ -0,0 +1,92 @@
+/**
+*
+* 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"
+
+       "github.com/apache/airavata/internal/auth"
+       "github.com/apache/airavata/internal/httpx"
+
+       dto "github.com/apache/airavata/api/process/dto"
+       "github.com/apache/airavata/api/process/repository"
+)
+
+// TaskStatusService reads the status history of a process's tasks.
+//
+// There is nothing to write here: the orchestration engine records task 
statuses as it
+// runs each task. Reads are owner-scoped like TaskService's, since a failed 
task's log
+// carries the error it failed with — remote paths and command output included.
+type TaskStatusService struct {
+       statuses  *repository.TaskStatusRepository
+       processes *repository.ProcessRepository
+}
+
+// NewTaskStatusService returns a task status service.
+func NewTaskStatusService(statuses *repository.TaskStatusRepository, processes 
*repository.ProcessRepository) *TaskStatusService {
+       return &TaskStatusService{statuses: statuses, processes: processes}
+}
+
+// ListForProcess returns every status recorded for any task of a process, 
oldest first.
+func (s *TaskStatusService) ListForProcess(ctx context.Context, processID 
string) ([]dto.TaskStatusResponse, error) {
+       if err := s.requireProcess(ctx, processID); err != nil {
+               return nil, err
+       }
+       found, err := s.statuses.FindByProcessID(ctx, processID)
+       if err != nil {
+               return nil, err
+       }
+       return dto.ToTaskStatusResponses(found), nil
+}
+
+// ListForTask returns every status recorded for one task, oldest first.
+//
+// The task is matched on both ids, so a task of another process yields an 
empty list
+// rather than that process's history. An unknown task id is an empty list 
too, not a
+// 404: the id may name a row in any of the four task tables, and a task the 
engine has
+// not reached yet has no history to show.
+func (s *TaskStatusService) ListForTask(ctx context.Context, processID, taskID 
string) ([]dto.TaskStatusResponse, error) {
+       if err := s.requireProcess(ctx, processID); err != nil {
+               return nil, err
+       }
+       found, err := s.statuses.FindByTaskIDAndProcessID(ctx, taskID, 
processID)
+       if err != nil {
+               return nil, err
+       }
+       return dto.ToTaskStatusResponses(found), nil
+}
+
+// requireProcess checks the process exists and the caller may see its tasks: 
its
+// owner, or an admin.
+func (s *TaskStatusService) requireProcess(ctx context.Context, processID 
string) error {
+       principal, err := auth.RequireAuthenticated(ctx)
+       if err != nil {
+               return err
+       }
+       proc, err := s.processes.FindByID(ctx, processID)
+       if err != nil {
+               return notFoundAs(err, "Process not found: %s", processID)
+       }
+       if !proc.OwnedBy(principal.Name) && !principal.IsAdmin() {
+               return httpx.Forbidden("Access denied: you may only work with 
tasks of your own processes")
+       }
+       return nil
+}
diff --git a/dashboard/src/app/processes/view/page.tsx 
b/dashboard/src/app/processes/view/page.tsx
index 54952e4d69..0402187f3d 100644
--- a/dashboard/src/app/processes/view/page.tsx
+++ b/dashboard/src/app/processes/view/page.tsx
@@ -7,17 +7,17 @@ import { Alert, Card, formatTime, Id, PageHead, StatusBadge, 
Table } from "@/com
 import { api, errorText, tryGet } from "@/lib/api";
 import { useDeploymentNames } from "@/lib/catalog";
 import { useResource } from "@/lib/hooks";
-import { isFileType, type DataProduct, type Process, type ProcessStatus, type 
Task } from "@/lib/types";
+import { isFileType, type DataProduct, type Process, type ProcessStatus, type 
Task, type TaskStatus, type TaskType } from "@/lib/types";
 
 const TERMINAL = new Set(["COMPLETED", "FAILED"]);
 const POLL_MS = 5000;
 
-const TASK_KINDS = [
-  { path: "data-staging-tasks", label: "Data staging" },
-  { path: "job-submission-tasks", label: "Job submission" },
-  { path: "job-monitoring-tasks", label: "Job monitoring" },
-  { path: "interactive-command-tasks", label: "Interactive commands" },
-] as const;
+const TASK_KINDS: readonly { path: string; label: string; type: TaskType }[] = 
[
+  { path: "data-staging-tasks", label: "Data staging", type: "DATA_STAGING" },
+  { path: "job-submission-tasks", label: "Job submission", type: 
"JOB_SUBMISSION" },
+  { path: "job-monitoring-tasks", label: "Job monitoring", type: 
"JOB_MONITORING" },
+  { path: "interactive-command-tasks", label: "Interactive commands", type: 
"INTERACTIVE_COMMAND" },
+];
 
 // 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"]);
@@ -41,10 +41,13 @@ function ProcessView() {
         api.get<ProcessStatus[]>(`/api/v1/processes/${id}/statuses`),
       ]);
       // Tasks are owner-scoped: a viewer who is neither owner nor admin sees 
none.
-      const tasks = await Promise.all(TASK_KINDS.map((k) => 
tryGet<Task[]>(`/api/v1/processes/${id}/${k.path}`)));
+      const [tasks, taskStatuses] = await Promise.all([
+        Promise.all(TASK_KINDS.map((k) => 
tryGet<Task[]>(`/api/v1/processes/${id}/${k.path}`))),
+        tryGet<TaskStatus[]>(`/api/v1/processes/${id}/task-statuses`),
+      ]);
       const done = TERMINAL.has(statuses[statuses.length - 1]?.status ?? "");
       if (done) setLive(false);
-      return { process, statuses, tasks };
+      return { process, statuses, tasks, taskStatuses: taskStatuses ?? [] };
     },
     [id],
     live ? POLL_MS : undefined,
@@ -57,6 +60,11 @@ function ProcessView() {
   const bp = d?.process.batchProcess;
   const latest = d?.statuses[d.statuses.length - 1];
   const template = 
names.template(names.deployment(bp?.deploymentId)?.templateId);
+  // Statuses arrive oldest first, so the last one seen for a task is its 
current one.
+  const latestTaskStatus = new Map<string, TaskStatus>();
+  for (const s of d?.taskStatuses ?? []) latestTaskStatus.set(s.taskId, s);
+  const taskOrder = new Map<string, number | null>();
+  d?.tasks.forEach((list) => list?.forEach((t) => taskOrder.set(t.taskId, 
t.taskOrder)));
 
   const launch = async () => {
     setBusy(true);
@@ -166,6 +174,32 @@ function ProcessView() {
             )}
           </Card>
 
+          {d.taskStatuses.length > 0 && (
+            <Card title="Task history">
+              <ul className="timeline">
+                {d.taskStatuses.map((s) => {
+                  const order = taskOrder.get(s.taskId);
+                  return (
+                    <li key={s.taskStatusId}>
+                      <span>
+                        <StatusBadge status={s.status} />
+                      </span>
+                      <span className="small 
muted">{formatTime(s.timestamp)}</span>
+                      <span>
+                        <span className="row">
+                          <strong>{TASK_KINDS.find((k) => k.type === 
s.taskType)?.label ?? s.taskType}</strong>
+                          {order !== undefined && order !== null && <span 
className="small muted">step {order}</span>}
+                          <Id value={s.taskId} />
+                        </span>
+                        {s.log && <pre className="block">{s.log}</pre>}
+                      </span>
+                    </li>
+                  );
+                })}
+              </ul>
+            </Card>
+          )}
+
           {bp && (
             <Card title="Run">
               <dl className="kv">
@@ -223,6 +257,11 @@ function ProcessView() {
                   empty=""
                   columns={[
                     { header: "Order", cell: (t) => t.taskOrder ?? "—" },
+                    { header: "Status", cell: (t) => <StatusBadge 
status={latestTaskStatus.get(t.taskId)?.status} /> },
+                    {
+                      header: "Updated",
+                      cell: (t) => <span 
className="small">{formatTime(latestTaskStatus.get(t.taskId)?.timestamp)}</span>,
+                    },
                     ...extra.map((f) => ({
                       header: f,
                       cell: (t: Task) => {
diff --git a/dashboard/src/components/ui.tsx b/dashboard/src/components/ui.tsx
index a2846998d6..b0ae32d590 100644
--- a/dashboard/src/components/ui.tsx
+++ b/dashboard/src/components/ui.tsx
@@ -222,6 +222,7 @@ const STATUS_TONE: Record<string, string> = {
   PROVISIONED: "ok",
   END: "ok",
   RUNNING: "info",
+  EXECUTING: "info",
   SUBMITTED: "info",
   BEGIN: "info",
   PROVISIONING: "info",
@@ -230,6 +231,8 @@ const STATUS_TONE: Record<string, string> = {
   FAIL: "danger",
   SUBMISSION_FAILED: "danger",
   CANCELLED: "warn",
+  CANCELED: "warn",
+  PAUSED: "warn",
   CANCELLING: "warn",
   TIME_LIMIT: "danger",
   READ: "",
diff --git a/dashboard/src/lib/types.ts b/dashboard/src/lib/types.ts
index 1aabcac440..2418e1d8d6 100644
--- a/dashboard/src/lib/types.ts
+++ b/dashboard/src/lib/types.ts
@@ -261,6 +261,20 @@ export interface ProcessStatus {
   timestamp: number | null;
 }
 
+export type TaskType = "DATA_STAGING" | "JOB_SUBMISSION" | "JOB_MONITORING" | 
"INTERACTIVE_COMMAND";
+
+export type TaskStatusType = "CREATED" | "EXECUTING" | "PAUSED" | "COMPLETED" 
| "FAILED" | "CANCELED";
+
+export interface TaskStatus {
+  taskStatusId: string;
+  taskId: string;
+  taskType: TaskType;
+  processId: string | null;
+  status: TaskStatusType | null;
+  log: string | null;
+  timestamp: number | null;
+}
+
 export interface Task {
   taskId: string;
   processId: string | null;
diff --git a/internal/app/app.go b/internal/app/app.go
index ef4ec0d953..615cb8eedc 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -97,6 +97,7 @@ type Services struct {
        // the process that owns it, written and read through ProcessService.
        Process                *processsvc.ProcessService
        ProcessStatus          *processsvc.StatusService
+       TaskStatus             *processsvc.TaskStatusService
        DataStagingTask        *processsvc.DataStagingTaskService
        JobSubmissionTask      *processsvc.JobSubmissionTaskService
        JobMonitoringTask      *processsvc.JobMonitoringTaskService
@@ -250,6 +251,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos 
*Repositories, workflowBa
 
                Process:                processSvs,
                ProcessStatus:          statusSvc,
+               TaskStatus:             
processsvc.NewTaskStatusService(repos.TaskStatuses, processes),
                DataStagingTask:        
processsvc.NewDataStagingTaskService(db, stagingTasks, processes),
                JobSubmissionTask:      
processsvc.NewJobSubmissionTaskService(db, submissionTasks, processes),
                JobMonitoringTask:      
processsvc.NewJobMonitoringTaskService(db, monitoringTasks, processes),
diff --git a/internal/server/server.go b/internal/server/server.go
index d7aadecc81..b3e4a36f5a 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -72,6 +72,7 @@ func New(cfg config.Config, svcs *app.Services, introspector 
auth.Introspector)
        processctl.NewProcessController(svcs.Process).Register(mux)
        processctl.NewLaunchController(svcs.Launch).Register(mux)
        processctl.NewStatusController(svcs.ProcessStatus).Register(mux)
+       processctl.NewTaskStatusController(svcs.TaskStatus).Register(mux)
        
processctl.NewDataStagingTaskController(svcs.DataStagingTask).Register(mux)
        
processctl.NewJobSubmissionTaskController(svcs.JobSubmissionTask).Register(mux)
        
processctl.NewJobMonitoringTaskController(svcs.JobMonitoringTask).Register(mux)
diff --git a/internal/server/server_test.go b/internal/server/server_test.go
index ca1ddb8cab..d1c86c7448 100644
--- a/internal/server/server_test.go
+++ b/internal/server/server_test.go
@@ -2541,3 +2541,60 @@ func TestDiscoverAllocations(t *testing.T) {
                t.Errorf("fallback allocations = %v, want proj3 from sshare", 
allocs)
        }
 }
+
+// Task statuses are written by the engine, read through the process they 
belong to, and
+// owner-scoped like the tasks themselves.
+func TestTaskStatusesAreReadThroughTheirProcess(t *testing.T) {
+       h := newHarness(t)
+       processID := h.seedProcess("task-statuses", tokenAlice)
+       other := h.seedProcess("other-task-statuses", tokenAlice)
+
+       task := h.mustDo(http.MethodPost, 
"/api/v1/processes/"+processID+"/data-staging-tasks", tokenAlice,
+               map[string]any{"sourcePath": "/in", "destinationPath": "/out", 
"taskOrder": 1}, http.StatusCreated)
+       taskID := task["taskId"].(string)
+
+       for i, status := range []string{"EXECUTING", "FAILED"} {
+               if err := h.db.Exec(`INSERT INTO task_statuses (task_status_id, 
task_id, task_type, process_id, status, log, timestamp)
+                       VALUES (?, ?, 'DATA_STAGING', ?, ?, ?, ?)`,
+                       status+"-"+taskID, taskID, processID, status, 
"attempt", 1_700_000_000_000+int64(i)).Error; err != nil {
+                       t.Fatalf("seed task status: %v", err)
+               }
+       }
+
+       all := h.list("/api/v1/processes/"+processID+"/task-statuses", 
tokenAlice)
+       if len(all) != 2 || all[0]["status"] != "EXECUTING" || all[1]["status"] 
!= "FAILED" {
+               t.Fatalf("task statuses = %v, want EXECUTING then FAILED", all)
+       }
+       if all[1]["taskId"] != taskID || all[1]["taskType"] != "DATA_STAGING" {
+               t.Errorf("status = %v, want it to name the task and its kind", 
all[1])
+       }
+
+       if one := 
h.list("/api/v1/processes/"+processID+"/tasks/"+taskID+"/statuses", 
tokenAlice); len(one) != 2 {
+               t.Errorf("per-task statuses = %d, want 2", len(one))
+       }
+
+       // A task id from one process reads nothing through another's path.
+       if leaked := 
h.list("/api/v1/processes/"+other+"/tasks/"+taskID+"/statuses", tokenAlice); 
len(leaked) != 0 {
+               t.Errorf("cross-process statuses = %d, want 0", len(leaked))
+       }
+
+       for _, path := range []string{
+               "/api/v1/processes/" + processID + "/task-statuses",
+               "/api/v1/processes/" + processID + "/tasks/" + taskID + 
"/statuses",
+       } {
+               if rec := h.do(http.MethodGet, path, tokenBob, nil); rec.Code 
!= http.StatusForbidden {
+                       t.Errorf("GET %s as another user: status = %d, want 
403", path, rec.Code)
+               }
+               if rec := h.do(http.MethodGet, path, "", nil); rec.Code != 
http.StatusUnauthorized {
+                       t.Errorf("GET %s anonymously: status = %d, want 401", 
path, rec.Code)
+               }
+               h.mustDo(http.MethodGet, path, tokenAdmin, nil, http.StatusOK)
+       }
+
+       if rec := h.do(http.MethodGet, 
"/api/v1/processes/no-such-process/task-statuses", tokenAlice, nil); rec.Code 
!= http.StatusNotFound {
+               t.Errorf("unknown process: status = %d, want 404", rec.Code)
+       }
+       if rec := h.do(http.MethodPost, 
"/api/v1/processes/"+processID+"/task-statuses", tokenAlice, map[string]any{}); 
rec.Code != http.StatusMethodNotAllowed {
+               t.Errorf("POST task-statuses: status = %d, want 405", rec.Code)
+       }
+}

Reply via email to