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 3c6c099b3d Added process execution entries
3c6c099b3d is described below
commit 3c6c099b3d48a923110b8691d3b49e50c7dad746
Author: DImuthuUpe <[email protected]>
AuthorDate: Fri Nov 6 20:52:06 2026 -0500
Added process execution entries
---
api/process/controller/execution.go | 66 ++++++++++
api/process/dto/execution.go | 54 +++++++++
api/process/dto/process.go | 20 +--
api/process/model/process.go | 59 ++++++++-
api/process/repository/execution.go | 73 +++++++++++
api/process/service/execution.go | 135 +++++++++++++++++++++
api/process/service/launch.go | 9 +-
dashboard/src/lib/types.ts | 1 +
internal/app/app.go | 4 +
internal/db/foreignkey_test.go | 3 +-
internal/db/migrate.go | 4 +
internal/db/migrate_test.go | 2 +-
internal/db/migrations/0005_process_executions.sql | 18 +++
internal/server/server.go | 1 +
internal/server/server_test.go | 75 ++++++++++++
15 files changed, 508 insertions(+), 16 deletions(-)
diff --git a/api/process/controller/execution.go
b/api/process/controller/execution.go
new file mode 100644
index 0000000000..ecec62e31a
--- /dev/null
+++ b/api/process/controller/execution.go
@@ -0,0 +1,66 @@
+/**
+*
+* 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"
+)
+
+// ExecutionController serves read-only access to the workflow executions
started for a
+// process, nested under /api/v1/processes/{processId}.
+//
+// There is deliberately no POST or PUT: executions are recorded by
+// service.ExecutionService when a workflow is started, never accepted as a
request
+// body from a client.
+type ExecutionController struct{ svc *service.ExecutionService }
+
+// NewExecutionController returns a handler delegating to svc.
+func NewExecutionController(svc *service.ExecutionService)
*ExecutionController {
+ return &ExecutionController{svc: svc}
+}
+
+// Register mounts the read-only execution routes.
+func (h *ExecutionController) Register(mux *http.ServeMux) {
+ mux.HandleFunc("GET /api/v1/processes/{processId}/executions", h.list)
+ mux.HandleFunc("GET
/api/v1/processes/{processId}/executions/{executionId}", h.get)
+}
+
+func (h *ExecutionController) list(w http.ResponseWriter, r *http.Request) {
+ executions, err := h.svc.ListForProcess(r.Context(),
r.PathValue("processId"))
+ if err != nil {
+ httpx.WriteError(w, r, err)
+ return
+ }
+ httpx.WriteJSON(w, http.StatusOK, executions)
+}
+
+func (h *ExecutionController) get(w http.ResponseWriter, r *http.Request) {
+ execution, err := h.svc.Get(r.Context(), r.PathValue("processId"),
r.PathValue("executionId"))
+ if err != nil {
+ httpx.WriteError(w, r, err)
+ return
+ }
+ httpx.WriteJSON(w, http.StatusOK, execution)
+}
diff --git a/api/process/dto/execution.go b/api/process/dto/execution.go
new file mode 100644
index 0000000000..5e15e2947f
--- /dev/null
+++ b/api/process/dto/execution.go
@@ -0,0 +1,54 @@
+/**
+*
+* 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"
+)
+
+// ExecutionResponse is the read model for one recorded process execution. Like
+// StatusResponse it has no request counterpart: executions are recorded when a
+// workflow is started for a process, never accepted from a client.
+type ExecutionResponse struct {
+ ProcessExecutionID string
`json:"processExecutionId"`
+ ProcessID *string `json:"processId"`
+ ExecutionID string `json:"executionId"`
+ ExecutionType *model.ProcessExecutionType `json:"executionType"`
+ Timestamp *int64 `json:"timestamp"`
+}
+
+func ToExecutionResponse(e *model.ProcessExecution) ExecutionResponse {
+ return ExecutionResponse{
+ ProcessExecutionID: e.ID,
+ ProcessID: e.ProcessID,
+ ExecutionID: e.ExecutionID,
+ ExecutionType: e.ExecutionType,
+ Timestamp: e.Timestamp,
+ }
+}
+
+func ToExecutionResponses(in []model.ProcessExecution) []ExecutionResponse {
+ out := make([]ExecutionResponse, 0, len(in))
+ for i := range in {
+ out = append(out, ToExecutionResponse(&in[i]))
+ }
+ return out
+}
diff --git a/api/process/dto/process.go b/api/process/dto/process.go
index 983b5af624..02afc35115 100644
--- a/api/process/dto/process.go
+++ b/api/process/dto/process.go
@@ -190,21 +190,23 @@ func (r *Request) Validate() []httpx.FieldError {
// Response is the read model for a process, with every section it carries
nested
// inside it.
type Response struct {
- ProcessID string `json:"processId"`
- UserID *string `json:"userId"`
- ProcessType *model.ProcessType `json:"processType"`
- LastStatusID *string `json:"lastStatusId"`
+ ProcessID string `json:"processId"`
+ UserID *string `json:"userId"`
+ ProcessType *model.ProcessType `json:"processType"`
+ LastStatusID *string `json:"lastStatusId"`
+ LastExecutionID *string `json:"lastExecutionId"`
BatchProcess *BatchProcessResponse `json:"batchProcess"`
}
func ToResponse(p *model.Process) Response {
return Response{
- ProcessID: p.ID,
- UserID: p.OwnerID,
- ProcessType: p.ProcessType,
- LastStatusID: p.LastStatusID,
- BatchProcess: ToBatchProcessResponse(p.BatchProcess),
+ ProcessID: p.ID,
+ UserID: p.OwnerID,
+ ProcessType: p.ProcessType,
+ LastStatusID: p.LastStatusID,
+ LastExecutionID: p.LastExecutionID,
+ BatchProcess: ToBatchProcessResponse(p.BatchProcess),
}
}
diff --git a/api/process/model/process.go b/api/process/model/process.go
index bedd1f9f2b..c896bffff5 100644
--- a/api/process/model/process.go
+++ b/api/process/model/process.go
@@ -102,6 +102,11 @@ type Process struct {
// the newest status row, maintained by ProcessStatus.AfterCreate.
LastStatusID *string
`gorm:"column:last_status_id;type:varchar(36);index"
json:"lastStatusId,omitempty"`
+ // The last execution recorded for this process, if any. Like
LastStatusID it
+ // carries no foreign key, for the same reason, and is maintained by
+ // ProcessExecution.AfterCreate.
+ LastExecutionID *string
`gorm:"column:last_execution_id;type:varchar(36);index"
json:"lastExecutionId,omitempty"`
+
// BatchProcess is present exactly when ProcessType is BATCH_JOB. It is
owned by
// the process, not shared with it: deleting the process deletes it too.
BatchProcess *BatchJobProcess
`gorm:"foreignKey:ProcessID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"
json:"batchProcess,omitempty"`
@@ -126,10 +131,10 @@ func (p *Process) BeforeCreate(*gorm.DB) error {
// BeforeDelete removes what the database will not.
//
-// The statuses have to go first: their own ProcessID foreign key is RESTRICT,
so the
-// server would refuse to delete a process any status still points at.
LastStatusID
-// needs no clearing — it holds no constraint — and the row carrying it is
about to be
-// deleted in this same transaction.
+// The statuses and executions have to go first: their own ProcessID foreign
keys are
+// RESTRICT, so the server would refuse to delete a process any of them still
points at.
+// LastStatusID and LastExecutionID need no clearing — they hold no constraint
— and the
+// row carrying them is about to be deleted in this same transaction.
//
// The batch process is deleted through GORM rather than left to its ON DELETE
CASCADE
// so that its own AfterDelete fires and takes the owned BatchJobConfig with
it. A
@@ -143,6 +148,9 @@ func (p *Process) BeforeDelete(tx *gorm.DB) error {
if err := tx.Where("process_id = ?",
p.ID).Delete(&ProcessStatus{}).Error; err != nil {
return err
}
+ if err := tx.Where("process_id = ?",
p.ID).Delete(&ProcessExecution{}).Error; err != nil {
+ return err
+ }
var batch []BatchJobProcess
if err := tx.Where("parent_process_id = ?", p.ID).Find(&batch).Error;
err != nil {
@@ -219,3 +227,46 @@ func (s *ProcessStatus) AfterCreate(tx *gorm.DB) error {
Where("process_id = ?", *s.ProcessID).
Update("last_status_id", s.ID).Error
}
+
+type ProcessExecutionType string
+
+const (
+ ProcessExecutionTypeBatchJobSubmission ProcessExecutionType =
"BATCH_JOB_SUBMISSION"
+ ProcessExecutionTypeJobMonitoring ProcessExecutionType =
"JOB_MONITORING"
+ ProcessExecutionTypeJobCompletion ProcessExecutionType =
"BATCH_JOB_COMPLETION"
+)
+
+// ProcessExecution records one workflow run started on behalf of a process —
the job
+// submission, monitoring or completion workflow — by the id the workflow
engine knows
+// it by.
+type ProcessExecution struct {
+ ID string
`gorm:"column:process_execution_id;primaryKey;type:varchar(36)"
json:"processExecutionId"`
+
+ ProcessID *string `gorm:"column:process_id;type:varchar(36);index"
json:"processId,omitempty"`
+ Process *Process
`gorm:"references:ID;constraint:OnDelete:RESTRICT,OnUpdate:CASCADE" json:"-"`
+ // Workflow id or monitoring task id
+ ExecutionID string
`gorm:"column:execution_id;type:varchar(36)" json:"executionId"`
+ ExecutionType *ProcessExecutionType
`gorm:"column:execution_type;type:varchar(255)" json:"executionType,omitempty"`
+
+ // The time the execution was recorded, in milliseconds since the epoch.
+ Timestamp *int64 `gorm:"column:timestamp" json:"timestamp,omitempty"`
+}
+
+// TableName returns the table backing ProcessExecution.
+func (ProcessExecution) TableName() string { return "process_executions" }
+
+func (p *ProcessExecution) BeforeCreate(*gorm.DB) error {
+ if p.ID == "" {
+ p.ID = uuid.NewString()
+ }
+ return nil
+}
+
+func (p *ProcessExecution) AfterCreate(tx *gorm.DB) error {
+ if p.ProcessID == nil || *p.ProcessID == "" {
+ return nil
+ }
+ return tx.Model(&Process{}).
+ Where("process_id = ?", *p.ProcessID).
+ Update("last_execution_id", p.ID).Error
+}
diff --git a/api/process/repository/execution.go
b/api/process/repository/execution.go
new file mode 100644
index 0000000000..217b668812
--- /dev/null
+++ b/api/process/repository/execution.go
@@ -0,0 +1,73 @@
+/**
+*
+* 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 repository
+
+import (
+ "context"
+
+ "gorm.io/gorm"
+
+ model "github.com/apache/airavata/api/process/model"
+)
+
+// ExecutionRepository reads and writes process executions.
+//
+// There is no Update: an execution records a workflow run that was started,
which is
+// never corrected in place.
+type ExecutionRepository struct{ db *gorm.DB }
+
+// NewExecutionRepository returns a repository backed by db.
+func NewExecutionRepository(db *gorm.DB) *ExecutionRepository {
+ return &ExecutionRepository{db: db}
+}
+
+// WithTx returns a repository bound to tx.
+func (r *ExecutionRepository) WithTx(tx *gorm.DB) *ExecutionRepository {
+ return &ExecutionRepository{db: tx}
+}
+
+// FindByProcessID returns every execution recorded for one process, oldest
first.
+func (r *ExecutionRepository) FindByProcessID(ctx context.Context, processID
string) ([]model.ProcessExecution, error) {
+ var out []model.ProcessExecution
+ err := r.db.WithContext(ctx).
+ Where("process_id = ?", processID).
+ Order("timestamp").
+ Find(&out).Error
+ return out, err
+}
+
+// FindByIDAndProcessID returns one execution scoped to its process, or
+// gorm.ErrRecordNotFound if the id does not belong to that process.
+func (r *ExecutionRepository) FindByIDAndProcessID(ctx context.Context, id,
processID string) (*model.ProcessExecution, error) {
+ var out model.ProcessExecution
+ err := r.db.WithContext(ctx).
+ First(&out, "process_execution_id = ? AND process_id = ?", id,
processID).Error
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
+
+// Create inserts an execution row. BeforeCreate assigns its id and AfterCreate
+// repoints the owning process's LastExecutionID at it.
+func (r *ExecutionRepository) Create(ctx context.Context, e
*model.ProcessExecution) error {
+ return r.db.WithContext(ctx).Create(e).Error
+}
diff --git a/api/process/service/execution.go b/api/process/service/execution.go
new file mode 100644
index 0000000000..e58d7e63e3
--- /dev/null
+++ b/api/process/service/execution.go
@@ -0,0 +1,135 @@
+/**
+*
+* 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"
+ "time"
+
+ "gorm.io/gorm"
+
+ "github.com/apache/airavata/internal/auth"
+ "github.com/apache/airavata/internal/httpx"
+ "github.com/apache/airavata/internal/ptr"
+
+ dto "github.com/apache/airavata/api/process/dto"
+ model "github.com/apache/airavata/api/process/model"
+ "github.com/apache/airavata/api/process/repository"
+)
+
+// ExecutionService records and reads the workflow executions started for a
process.
+//
+// There is no create endpoint, by design: an execution is recorded by the
code that
+// starts a workflow for the process, never accepted from a client request
body. Reads
+// are owner-scoped like TaskStatusService's, since an execution id is a
handle on the
+// workflow engine's own record of the run.
+type ExecutionService struct {
+ db *gorm.DB
+ executions *repository.ExecutionRepository
+ processes *repository.ProcessRepository
+}
+
+// NewExecutionService returns an execution service.
+func NewExecutionService(db *gorm.DB, executions
*repository.ExecutionRepository, processes *repository.ProcessRepository)
*ExecutionService {
+ return &ExecutionService{db: db, executions: executions, processes:
processes}
+}
+
+// Record appends a new execution for a process, in its own transaction.
+//
+// It does not check authorisation: recording an execution is an internal
operation
+// performed by trusted service code, never taken directly from a client
request.
+func (s *ExecutionService) Record(ctx context.Context, processID, executionID
string, executionType model.ProcessExecutionType) (*dto.ExecutionResponse,
error) {
+ var out dto.ExecutionResponse
+ err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
+ created, err := s.RecordTx(ctx, tx, processID, executionID,
executionType)
+ if err != nil {
+ return err
+ }
+ out = dto.ToExecutionResponse(created)
+ return nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
+
+// RecordTx appends a new execution inside an already-open transaction, so a
caller
+// that is already inside one of its own commits or rolls back the execution
together
+// with the rest of its work.
+func (s *ExecutionService) RecordTx(ctx context.Context, tx *gorm.DB,
processID, executionID string, executionType model.ProcessExecutionType)
(*model.ProcessExecution, error) {
+ if _, err := s.processes.WithTx(tx).FindByID(ctx, processID); err !=
nil {
+ return nil, notFoundAs(err, "Process not found: %s", processID)
+ }
+
+ created := &model.ProcessExecution{
+ ProcessID: &processID,
+ ExecutionID: executionID,
+ ExecutionType: &executionType,
+ Timestamp: ptr.To(time.Now().UnixMilli()),
+ }
+ if err := s.executions.WithTx(tx).Create(ctx, created); err != nil {
+ return nil, err
+ }
+ return created, nil
+}
+
+// ListForProcess returns every execution recorded for a process, oldest first.
+func (s *ExecutionService) ListForProcess(ctx context.Context, processID
string) ([]dto.ExecutionResponse, error) {
+ if err := s.requireProcess(ctx, processID); err != nil {
+ return nil, err
+ }
+ found, err := s.executions.FindByProcessID(ctx, processID)
+ if err != nil {
+ return nil, err
+ }
+ return dto.ToExecutionResponses(found), nil
+}
+
+// Get returns one execution, scoped to the process it must belong to.
+func (s *ExecutionService) Get(ctx context.Context, processID, executionID
string) (*dto.ExecutionResponse, error) {
+ if err := s.requireProcess(ctx, processID); err != nil {
+ return nil, err
+ }
+ found, err := s.executions.FindByIDAndProcessID(ctx, executionID,
processID)
+ if err != nil {
+ return nil, notFoundAs(err, "Execution not found: %s in process
%s", executionID, processID)
+ }
+ out := dto.ToExecutionResponse(found)
+ return &out, nil
+}
+
+// requireProcess checks the process exists and the caller may see its
executions: its
+// owner, or an admin.
+func (s *ExecutionService) 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
executions of your own processes")
+ }
+ return nil
+}
diff --git a/api/process/service/launch.go b/api/process/service/launch.go
index 32ee607a82..f2ed4bf40c 100644
--- a/api/process/service/launch.go
+++ b/api/process/service/launch.go
@@ -269,7 +269,14 @@ func (s *LaunchService) launchBatchProcess(ctx
context.Context, process *dto.Res
}
slog.Info("Created tasks for process. Now launching those",
"processId", process.ProcessID)
- s.executionEngine.LaunchBatchJobSubmission(ctx, process.ProcessID)
+ workflowId, err := s.executionEngine.LaunchBatchJobSubmission(ctx,
process.ProcessID)
+
+ if err != nil {
+ slog.Error("Failed to launch batch job submission",
"processId", process.ProcessID, "error", err)
+ return err
+ }
+
+ slog.Info("Launched batch job submission", "processId",
process.ProcessID, "workflowId", workflowId)
if _, err := s.statusService.Record(ctx, process.ProcessID,
procmodel.ProcessStatusTypeSubmitted, nil); err != nil {
return err
diff --git a/dashboard/src/lib/types.ts b/dashboard/src/lib/types.ts
index 2418e1d8d6..a5584ddb58 100644
--- a/dashboard/src/lib/types.ts
+++ b/dashboard/src/lib/types.ts
@@ -250,6 +250,7 @@ export interface Process {
userId: string | null;
processType: "BATCH_JOB" | "CLOUD_JOB" | null;
lastStatusId: string | null;
+ lastExecutionId: string | null;
batchProcess: BatchProcess | null;
}
diff --git a/internal/app/app.go b/internal/app/app.go
index 615cb8eedc..facd23fd7d 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -98,6 +98,7 @@ type Services struct {
Process *processsvc.ProcessService
ProcessStatus *processsvc.StatusService
TaskStatus *processsvc.TaskStatusService
+ Execution *processsvc.ExecutionService
DataStagingTask *processsvc.DataStagingTaskService
JobSubmissionTask *processsvc.JobSubmissionTaskService
JobMonitoringTask *processsvc.JobMonitoringTaskService
@@ -128,6 +129,7 @@ type Repositories struct {
Processes *processrepo.ProcessRepository
Statuses *processrepo.StatusRepository
TaskStatuses *processrepo.TaskStatusRepository
+ Executions *processrepo.ExecutionRepository
BatchJobStatuses *processrepo.BatchJobStatusRepository
DataStagingTasks *processrepo.DataStagingTaskRepository
JobSubmissionTasks *processrepo.JobSubmissionTaskRepository
@@ -154,6 +156,7 @@ func NewRepositories(db *gorm.DB) *Repositories {
Processes: processrepo.NewProcessRepository(db),
Statuses: processrepo.NewStatusRepository(db),
TaskStatuses:
processrepo.NewTaskStatusRepository(db),
+ Executions: processrepo.NewExecutionRepository(db),
BatchJobStatuses:
processrepo.NewBatchJobStatusRepository(db),
DataStagingTasks:
processrepo.NewDataStagingTaskRepository(db),
JobSubmissionTasks:
processrepo.NewJobSubmissionTaskRepository(db),
@@ -252,6 +255,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos
*Repositories, workflowBa
Process: processSvs,
ProcessStatus: statusSvc,
TaskStatus:
processsvc.NewTaskStatusService(repos.TaskStatuses, processes),
+ Execution: processsvc.NewExecutionService(db,
repos.Executions, processes),
DataStagingTask:
processsvc.NewDataStagingTaskService(db, stagingTasks, processes),
JobSubmissionTask:
processsvc.NewJobSubmissionTaskService(db, submissionTasks, processes),
JobMonitoringTask:
processsvc.NewJobMonitoringTaskService(db, monitoringTasks, processes),
diff --git a/internal/db/foreignkey_test.go b/internal/db/foreignkey_test.go
index 14d18e2f61..c4541f3aa9 100644
--- a/internal/db/foreignkey_test.go
+++ b/internal/db/foreignkey_test.go
@@ -71,6 +71,7 @@ func TestForeignKeyDirections(t *testing.T) {
{"batch_processes", "slurm_cluster_config_id",
"slurm_cluster_configs", "slurm_cluster_config_id"},
{"batch_processes", "batch_job_config_id", "batch_job_configs",
"batch_job_config_id"},
{"process_statuses", "process_id", "processes", "process_id"},
+ {"process_executions", "process_id", "processes", "process_id"},
{"process_template_input_mappings", "batch_process_id",
"batch_processes", "batch_process_id"},
{"process_template_input_mappings", "template_input_id",
"application_template_inputs", "input_id"},
{"process_template_output_mappings", "batch_process_id",
"batch_processes", "batch_process_id"},
@@ -81,7 +82,7 @@ func TestForeignKeyDirections(t *testing.T) {
{"job_submission_tasks", "process_id", "processes",
"process_id"},
{"job_monitoring_tasks", "process_id", "processes",
"process_id"},
{"interactive_command_tasks", "process_id", "processes",
"process_id"},
- // processes.last_status_id deliberately has none: a constraint
in that
+ // processes.last_status_id and last_execution_id deliberately
have none: a constraint in that
// direction would make the two tables mutually dependent,
which PostgreSQL
// cannot create. See Process.LastStatusID.
}
diff --git a/internal/db/migrate.go b/internal/db/migrate.go
index 9f478907e5..0912e8c731 100644
--- a/internal/db/migrate.go
+++ b/internal/db/migrate.go
@@ -102,6 +102,10 @@ func Entities() []any {
// The status history of those steps. It references the process
rather than a
// task, since a task id may name a row in any of the four
tables above.
&processmodel.TaskStatus{},
+
+ // The workflow runs started for a process. Like ProcessStatus
it is referenced
+ // back from Process, through LastExecutionID, which carries no
constraint.
+ &processmodel.ProcessExecution{},
}
}
diff --git a/internal/db/migrate_test.go b/internal/db/migrate_test.go
index 22521aa9bd..92069ce6fd 100644
--- a/internal/db/migrate_test.go
+++ b/internal/db/migrate_test.go
@@ -73,7 +73,7 @@ func TestAutoMigrateCreatesEveryTable(t *testing.T) {
"processes", "batch_processes", "batch_process_statuses",
"process_statuses",
"process_template_input_mappings",
"process_template_output_mappings",
"data_staging_tasks", "job_submission_tasks",
"job_monitoring_tasks",
- "interactive_command_tasks", "task_statuses",
+ "interactive_command_tasks", "task_statuses",
"process_executions",
}
for _, table := range want {
if !gdb.Migrator().HasTable(table) {
diff --git a/internal/db/migrations/0005_process_executions.sql
b/internal/db/migrations/0005_process_executions.sql
new file mode 100644
index 0000000000..97b97e638d
--- /dev/null
+++ b/internal/db/migrations/0005_process_executions.sql
@@ -0,0 +1,18 @@
+-- Record the workflow executions started for a process.
+--
+-- Each row names one workflow instance (execution_id, the id the workflow
engine knows
+-- it by) and which of the process's workflows it ran. The process reference is
+-- RESTRICT, like process_statuses: Process.BeforeDelete removes the
executions first.
+--
+-- processes.last_execution_id caches the newest execution the way
last_status_id caches
+-- the newest status, and for the same reason carries no foreign key: the two
tables
+-- would otherwise reference each other. It is maintained by
ProcessExecution.AfterCreate.
+-- The DDL is what AutoMigrate emits — see
TestBaselineMigrationMatchesAutoMigrate.
+
+ALTER TABLE "processes" ADD COLUMN "last_execution_id" varchar(36);
+
+CREATE INDEX IF NOT EXISTS "idx_processes_last_execution_id" ON "processes"
("last_execution_id");
+
+CREATE TABLE "process_executions" ("process_execution_id"
varchar(36),"process_id" varchar(36),"execution_id"
varchar(36),"execution_type" varchar(255),"timestamp" bigint,PRIMARY KEY
("process_execution_id"),CONSTRAINT "fk_process_executions_process" FOREIGN KEY
("process_id") REFERENCES "processes"("process_id") ON DELETE RESTRICT ON
UPDATE CASCADE);
+
+CREATE INDEX IF NOT EXISTS "idx_process_executions_process_id" ON
"process_executions" ("process_id");
diff --git a/internal/server/server.go b/internal/server/server.go
index b3e4a36f5a..6e993f36e9 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -73,6 +73,7 @@ func New(cfg config.Config, svcs *app.Services, introspector
auth.Introspector)
processctl.NewLaunchController(svcs.Launch).Register(mux)
processctl.NewStatusController(svcs.ProcessStatus).Register(mux)
processctl.NewTaskStatusController(svcs.TaskStatus).Register(mux)
+ processctl.NewExecutionController(svcs.Execution).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 d1c86c7448..e82028faf8 100644
--- a/internal/server/server_test.go
+++ b/internal/server/server_test.go
@@ -2598,3 +2598,78 @@ func TestTaskStatusesAreReadThroughTheirProcess(t
*testing.T) {
t.Errorf("POST task-statuses: status = %d, want 405", rec.Code)
}
}
+
+// Executions are recorded by the engine, read through the process they belong
to, and
+// owner-scoped like task statuses. Recording one repoints the process's
lastExecutionId.
+func TestExecutionsAreReadThroughTheirProcess(t *testing.T) {
+ h := newHarness(t)
+ processID := h.seedProcess("executions", tokenAlice)
+ other := h.seedProcess("other-executions", tokenAlice)
+
+ ctx := context.Background()
+ submission, err := h.svcs.Execution.Record(ctx, processID,
"workflow-1", "BATCH_JOB_SUBMISSION")
+ if err != nil {
+ t.Fatalf("record submission: %v", err)
+ }
+ completion, err := h.svcs.Execution.Record(ctx, processID,
"workflow-2", "BATCH_JOB_COMPLETION")
+ if err != nil {
+ t.Fatalf("record completion: %v", err)
+ }
+ if _, err := h.svcs.Execution.Record(ctx, "no-such-process",
"workflow-3", "BATCH_JOB_SUBMISSION"); err == nil {
+ t.Error("recording against an unknown process succeeded, want
an error")
+ }
+
+ all := h.list("/api/v1/processes/"+processID+"/executions", tokenAlice)
+ if len(all) != 2 || all[0]["executionId"] != "workflow-1" ||
all[1]["executionId"] != "workflow-2" {
+ t.Fatalf("executions = %v, want workflow-1 then workflow-2",
all)
+ }
+ if all[1]["executionType"] != "BATCH_JOB_COMPLETION" {
+ t.Errorf("execution = %v, want it to name its type", all[1])
+ }
+
+ proc := h.mustDo(http.MethodGet, "/api/v1/processes/"+processID,
tokenAlice, nil, http.StatusOK)
+ if proc["lastExecutionId"] != completion.ProcessExecutionID {
+ t.Errorf("lastExecutionId = %v, want %s",
proc["lastExecutionId"], completion.ProcessExecutionID)
+ }
+
+ one := h.mustDo(http.MethodGet,
"/api/v1/processes/"+processID+"/executions/"+submission.ProcessExecutionID,
tokenAlice, nil, http.StatusOK)
+ if one["executionId"] != "workflow-1" {
+ t.Errorf("execution = %v, want workflow-1", one)
+ }
+
+ // An execution id from one process reads nothing through another's
path.
+ if rec := h.do(http.MethodGet,
"/api/v1/processes/"+other+"/executions/"+submission.ProcessExecutionID,
tokenAlice, nil); rec.Code != http.StatusNotFound {
+ t.Errorf("cross-process execution: status = %d, want 404",
rec.Code)
+ }
+
+ for _, path := range []string{
+ "/api/v1/processes/" + processID + "/executions",
+ "/api/v1/processes/" + processID + "/executions/" +
submission.ProcessExecutionID,
+ } {
+ 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/executions", 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+"/executions", tokenAlice, map[string]any{});
rec.Code != http.StatusMethodNotAllowed {
+ t.Errorf("POST executions: status = %d, want 405", rec.Code)
+ }
+
+ // The executions' foreign key is RESTRICT, so deleting the process
relies on
+ // Process.BeforeDelete removing them first.
+ h.mustDo(http.MethodDelete, "/api/v1/processes/"+processID, tokenAdmin,
nil, http.StatusNoContent)
+ var left int64
+ if err := h.db.Table("process_executions").Where("process_id = ?",
processID).Count(&left).Error; err != nil {
+ t.Fatalf("count executions: %v", err)
+ }
+ if left != 0 {
+ t.Errorf("executions left after deleting their process = %d,
want 0", left)
+ }
+}