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

refactor(ui): workflow v2 graph display matrix and gate #6914

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions engine/api/clean_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestDeleteDisabledWorkers(t *testing.T) {
Username: admin.Username,
ProjectKey: wr.ProjectKey,
JobID: sdk.RandomString(10),
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunJobStatusBuilding,
}
require.NoError(t, workflow_v2.InsertRunJob(context.TODO(), db, &wrj))

Expand All @@ -88,7 +88,7 @@ func TestDeleteDisabledWorkers(t *testing.T) {
Username: admin.Username,
ProjectKey: wr.ProjectKey,
JobID: sdk.RandomString(10),
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunJobStatusBuilding,
}
require.NoError(t, workflow_v2.InsertRunJob(context.TODO(), db, &wrj2))

Expand Down Expand Up @@ -137,7 +137,7 @@ func TestDisabledDeadWorkers(t *testing.T) {
RunNumber: 1,
Started: time.Now(),
LastModified: time.Now(),
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
UserID: admin.ID,
Username: admin.Username,
RunEvent: sdk.V2WorkflowRunEvent{},
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestDisabledDeadWorkers(t *testing.T) {
Username: admin.Username,
ProjectKey: wr.ProjectKey,
JobID: sdk.RandomString(10),
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunJobStatusBuilding,
}
require.NoError(t, workflow_v2.InsertRunJob(context.TODO(), db, &wrj))

Expand All @@ -186,7 +186,7 @@ func TestDisabledDeadWorkers(t *testing.T) {
Username: admin.Username,
ProjectKey: wr.ProjectKey,
JobID: sdk.RandomString(10),
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunJobStatusBuilding,
}
require.NoError(t, workflow_v2.InsertRunJob(context.TODO(), db, &wrj2))

Expand Down
2 changes: 1 addition & 1 deletion engine/api/event_v2/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func workflowNotifications(ctx context.Context, db *gorp.DbMap, store cache.Stor
}

title := fmt.Sprintf("%s-%s", event.ProjectKey, run.WorkflowName)
description := run.WorkflowName + ":" + run.Status
description := run.WorkflowName + ":" + string(run.Status)
if run.WorkflowData.Workflow.CommitStatus != nil {
if run.WorkflowData.Workflow.CommitStatus.Title != "" {
title = run.WorkflowData.Workflow.CommitStatus.Title
Expand Down
16 changes: 9 additions & 7 deletions engine/api/v2_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (api *API) postJobResultHandler() ([]service.RbacChecker, service.Handler)
return sdk.NewErrorFrom(sdk.ErrInvalidData, "unknown job %s on region %s", jobRun.ID, regionName)
}

if sdk.StatusIsTerminated(jobRun.Status) {
if jobRun.Status.IsTerminated() {
return sdk.NewErrorFrom(sdk.ErrWrongRequest, "job %s is already in a final state %s", jobRun.JobID, jobRun.Status)
}

Expand All @@ -188,7 +188,8 @@ func (api *API) postJobResultHandler() ([]service.RbacChecker, service.Handler)
}

jobRun.Status = result.Status
jobRun.Ended = time.Now()
now := time.Now()
jobRun.Ended = &now

tx, err := api.mustDB().Begin()
if err != nil {
Expand Down Expand Up @@ -382,7 +383,7 @@ func (api *API) deleteHatcheryReleaseJobRunHandler() ([]service.RbacChecker, ser
return sdk.NewErrorFrom(sdk.ErrInvalidData, "unknown job %s on region %s taken by hatchery %s", jobRun.ID, regionName, hatch.Name)
}

jobRun.Status = sdk.StatusWaiting
jobRun.Status = sdk.V2WorkflowRunJobStatusWaiting
jobRun.HatcheryName = ""

tx, err := api.mustDB().Begin()
Expand Down Expand Up @@ -460,7 +461,7 @@ func (api *API) postHatcheryTakeJobRunHandler() ([]service.RbacChecker, service.
if jobRun.Region != regionName {
return sdk.NewErrorFrom(sdk.ErrInvalidData, "unknown job %s on region %s", jobRun.ID, regionName)
}
if sdk.StatusIsTerminated(jobRun.Status) {
if jobRun.Status.IsTerminated() {
return sdk.NewErrorFrom(sdk.ErrWrongRequest, "job %s is already in a final state %s", jobRun.JobID, jobRun.Status)
}

Expand All @@ -469,7 +470,7 @@ func (api *API) postHatcheryTakeJobRunHandler() ([]service.RbacChecker, service.
trace.StringAttribute(telemetry.TagProjectKey, jobRun.ProjectKey),
trace.StringAttribute(telemetry.TagWorkflowRunNumber, strconv.FormatInt(jobRun.RunNumber, 10)))

if jobRun.Status != sdk.StatusWaiting {
if jobRun.Status != sdk.V2WorkflowRunJobStatusWaiting {
return sdk.WrapError(sdk.ErrNotFound, "job has already been taken by %s", jobRun.HatcheryName)
}

Expand All @@ -483,8 +484,9 @@ func (api *API) postHatcheryTakeJobRunHandler() ([]service.RbacChecker, service.
}

jobRun.HatcheryName = hatch.Name
jobRun.Status = sdk.StatusScheduling
jobRun.Scheduled = time.Now()
jobRun.Status = sdk.V2WorkflowRunJobStatusScheduling
now := time.Now()
jobRun.Scheduled = &now

tx, err := api.mustDB().Begin()
if err != nil {
Expand Down
34 changes: 17 additions & 17 deletions engine/api/v2_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestPostHatcheryTakeAndReleaseJobRunHandler(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand All @@ -49,7 +49,7 @@ func TestPostHatcheryTakeAndReleaseJobRunHandler(t *testing.T) {
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusWaiting,
Status: sdk.V2WorkflowRunJobStatusWaiting,
ModelType: "docker",
Region: "default",
WorkflowRunID: wr.ID,
Expand Down Expand Up @@ -97,7 +97,7 @@ hatcheries:
require.Equal(t, 200, w.Code)
var jobRunResponse sdk.V2WorkflowRunJob
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &jobRunResponse))
require.Equal(t, sdk.StatusScheduling, jobRunResponse.Status)
require.Equal(t, sdk.V2WorkflowRunJobStatusScheduling, jobRunResponse.Status)

// release

Expand All @@ -110,8 +110,8 @@ hatcheries:

jobRunDB, err := workflow_v2.LoadRunJobByRunIDAndID(ctx, db, wr.ID, jobRun.ID)
require.NoError(t, err)
require.Equal(t, jobRunDB.Status, sdk.StatusWaiting)
require.Equal(t, jobRunDB.HatcheryName, "")
require.Equal(t, sdk.V2WorkflowRunJobStatusWaiting, jobRunDB.Status)
require.Equal(t, "", jobRunDB.HatcheryName)
}

func TestPostJobResultHandler(t *testing.T) {
Expand All @@ -131,7 +131,7 @@ func TestPostJobResultHandler(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand Down Expand Up @@ -164,7 +164,7 @@ hatcheries:
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusScheduling,
Status: sdk.V2WorkflowRunJobStatusScheduling,
ModelType: "docker",
Region: "default",
WorkflowRunID: wr.ID,
Expand All @@ -182,7 +182,7 @@ hatcheries:

// Take Job
jobResult := sdk.V2WorkflowRunJobResult{
Status: sdk.StatusFail,
Status: sdk.V2WorkflowRunJobStatusFail,
Error: "unable to craft job",
}
vars := map[string]string{"runJobID": jobRun.ID, "regionName": "default"}
Expand All @@ -195,7 +195,7 @@ hatcheries:

jobRunDB, err := workflow_v2.LoadRunJobByRunIDAndID(ctx, db, wr.ID, jobRun.ID)
require.NoError(t, err)
require.Equal(t, sdk.StatusFail, jobRunDB.Status)
require.Equal(t, sdk.V2WorkflowRunJobStatusFail, jobRunDB.Status)
}

func TestGetJobsQueuedHandler(t *testing.T) {
Expand All @@ -213,7 +213,7 @@ func TestGetJobsQueuedHandler(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand All @@ -227,7 +227,7 @@ func TestGetJobsQueuedHandler(t *testing.T) {
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusWaiting,
Status: sdk.V2WorkflowRunJobStatusWaiting,
JobID: "job1",
ModelType: "docker",
Region: "default",
Expand All @@ -238,7 +238,7 @@ func TestGetJobsQueuedHandler(t *testing.T) {
jobRun2 := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusWaiting,
Status: sdk.V2WorkflowRunJobStatusWaiting,
JobID: "job2",
ModelType: "docker",
Region: "default2",
Expand All @@ -249,7 +249,7 @@ func TestGetJobsQueuedHandler(t *testing.T) {
jobRun3 := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusWaiting,
Status: sdk.V2WorkflowRunJobStatusWaiting,
JobID: "job3",
ModelType: "openstack",
Region: "default",
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestGetJobHandler(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand All @@ -334,7 +334,7 @@ func TestGetJobHandler(t *testing.T) {
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusWaiting,
Status: sdk.V2WorkflowRunJobStatusWaiting,
JobID: "job1",
ModelType: "docker",
Region: "default",
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestPostJobRunInfoHandler(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand All @@ -419,7 +419,7 @@ func TestPostJobRunInfoHandler(t *testing.T) {
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusWaiting,
Status: sdk.V2WorkflowRunJobStatusWaiting,
JobID: "job1",
ModelType: "docker",
Region: "default",
Expand Down
16 changes: 9 additions & 7 deletions engine/api/v2_queue_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (api *API) postV2WorkerTakeJobHandler() ([]service.RbacChecker, service.Han
return err
}

if jobRun.Status != sdk.StatusScheduling {
if jobRun.Status != sdk.V2WorkflowRunJobStatusScheduling {
return sdk.NewErrorFrom(sdk.ErrForbidden, "unable take the job %s, current status %s", jobRunID, jobRun.Status)
}

Expand Down Expand Up @@ -95,16 +95,18 @@ func (api *API) postV2WorkerTakeJobHandler() ([]service.RbacChecker, service.Han
return err
}

jobRun.Status = sdk.StatusBuilding
jobRun.Started = time.Now()
now := time.Now()

jobRun.Status = sdk.V2WorkflowRunJobStatusBuilding
jobRun.Started = &now
jobRun.WorkerName = wrkWithSecret.Name
if err := workflow_v2.UpdateJobRun(ctx, tx, jobRun); err != nil {
return err
}

info := sdk.V2WorkflowRunJobInfo{
Level: sdk.WorkflowRunInfoLevelInfo,
IssuedAt: time.Now(),
IssuedAt: now,
WorkflowRunJobID: jobRun.ID,
WorkflowRunID: jobRun.WorkflowRunID,
Message: fmt.Sprintf("Worker %q is starting for job %q", wk.Name, jobRun.JobID),
Expand Down Expand Up @@ -264,8 +266,8 @@ func computeRunJobContext(ctx context.Context, db gorpmapper.SqlExecutorWithTx,
Result: j.Result,
Outputs: contexts.Jobs[n].Outputs,
}
if j.Result == sdk.StatusFail && run.WorkflowData.Workflow.Jobs[n].ContinueOnError {
needContext.Result = sdk.StatusSuccess
if j.Result == sdk.V2WorkflowRunJobStatusFail && run.WorkflowData.Workflow.Jobs[n].ContinueOnError {
needContext.Result = sdk.V2WorkflowRunJobStatusSuccess
}
contexts.Needs[n] = needContext
}
Expand Down Expand Up @@ -452,7 +454,7 @@ func (api *API) postV2RegisterWorkerHandler() ([]service.RbacChecker, service.Ha
if err != nil {
return err
}
if runJob.Status != sdk.StatusScheduling || runJob.HatcheryName != hatch.Name || runJob.ID != jobRunID || runJob.Region != regionName {
if runJob.Status != sdk.V2WorkflowRunJobStatusScheduling || runJob.HatcheryName != hatch.Name || runJob.ID != jobRunID || runJob.Region != regionName {
return sdk.WrapError(sdk.ErrForbidden, "unable to take job %s, current status: %s, hatchery: %s, region: %s", runJob.ID, runJob.Status, runJob.HatcheryName, runJob.Region)
}

Expand Down
20 changes: 10 additions & 10 deletions engine/api/v2_queue_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestWorkerUnregistered(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand Down Expand Up @@ -97,7 +97,7 @@ hatcheries:
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusScheduling,
Status: sdk.V2WorkflowRunJobStatusScheduling,
ModelType: "docker",
Region: "default",
WorkflowRunID: wr.ID,
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestWorkerRefresh(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand Down Expand Up @@ -172,7 +172,7 @@ hatcheries:
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusScheduling,
Status: sdk.V2WorkflowRunJobStatusScheduling,
ModelType: "docker",
Region: "default",
WorkflowRunID: wr.ID,
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestWorkerTakeJobHandler(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand Down Expand Up @@ -266,7 +266,7 @@ hatcheries:
jobRunSuccess := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusSuccess,
Status: sdk.V2WorkflowRunJobStatusSuccess,
JobID: "myjob",
ModelType: "docker",
Region: "default",
Expand Down Expand Up @@ -298,7 +298,7 @@ hatcheries:
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusScheduling,
Status: sdk.V2WorkflowRunJobStatusScheduling,
ModelType: "docker",
Region: "default",
WorkflowRunID: wr.ID,
Expand All @@ -323,7 +323,7 @@ hatcheries:
var takeJob sdk.V2TakeJobResponse
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &takeJob))

require.Equal(t, sdk.StatusBuilding, takeJob.RunJob.Status)
require.Equal(t, sdk.V2WorkflowRunJobStatusBuilding, takeJob.RunJob.Status)
require.Equal(t, workerName, takeJob.RunJob.WorkerName)

wkDB, err := worker_v2.LoadByID(ctx, db, wkr.ID)
Expand Down Expand Up @@ -419,7 +419,7 @@ func TestWorkerRegister(t *testing.T) {

wkfName := sdk.RandomString(10)
wr := sdk.V2WorkflowRun{
Status: sdk.StatusBuilding,
Status: sdk.V2WorkflowRunStatusBuilding,
ProjectKey: proj.Key,
UserID: admin.ID,
WorkflowName: wkfName,
Expand Down Expand Up @@ -465,7 +465,7 @@ hatcheries:
jobRun := sdk.V2WorkflowRunJob{
ProjectKey: proj.Key,
UserID: admin.ID,
Status: sdk.StatusScheduling,
Status: sdk.V2WorkflowRunJobStatusScheduling,
ModelType: "docker",
Region: "default",
WorkflowRunID: wr.ID,
Expand Down
Loading