Skip to content
Open
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
6 changes: 3 additions & 3 deletions scheduler/generic_sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *GenericScheduler) Process(eval *structs.Evaluation) (err error) {
default:
desc := fmt.Sprintf("scheduler cannot handle '%s' evaluation reason",
eval.TriggeredBy)
return setStatus(s.logger, s.planner, s.eval, nil, s.blocked,
return setStatus(s.logger, s.planner, s.eval, s.blocked,
s.failedTGAllocs, s.planAnnotations, structs.EvalStatusFailed, desc, s.queuedAllocs,
s.deployment.GetID())
}
Expand All @@ -148,7 +148,7 @@ func (s *GenericScheduler) Process(eval *structs.Evaluation) (err error) {
if err := s.createBlockedEval(true); err != nil {
mErr.Errors = append(mErr.Errors, err)
}
if err := setStatus(s.logger, s.planner, s.eval, nil, s.blocked,
if err := setStatus(s.logger, s.planner, s.eval, s.blocked,
s.failedTGAllocs, s.planAnnotations, statusErr.EvalStatus, err.Error(),
s.queuedAllocs, s.deployment.GetID()); err != nil {
mErr.Errors = append(mErr.Errors, err)
Expand All @@ -170,7 +170,7 @@ func (s *GenericScheduler) Process(eval *structs.Evaluation) (err error) {
}

// Update the status to complete
return setStatus(s.logger, s.planner, s.eval, nil, s.blocked,
return setStatus(s.logger, s.planner, s.eval, s.blocked,
s.failedTGAllocs, s.planAnnotations, structs.EvalStatusComplete, "", s.queuedAllocs,
s.deployment.GetID())
}
Expand Down
6 changes: 3 additions & 3 deletions scheduler/scheduler_sysbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *SysBatchScheduler) Process(eval *structs.Evaluation) (err error) {
// Verify the evaluation trigger reason is understood
if !s.canHandle(eval.TriggeredBy) {
desc := fmt.Sprintf("scheduler cannot handle '%s' evaluation reason", eval.TriggeredBy)
return setStatus(s.logger, s.planner, s.eval, nil, nil,
return setStatus(s.logger, s.planner, s.eval, nil,
s.failedTGAllocs, s.planAnnotations, structs.EvalStatusFailed, desc,
s.queuedAllocs, "")
}
Expand All @@ -89,15 +89,15 @@ func (s *SysBatchScheduler) Process(eval *structs.Evaluation) (err error) {
progress := func() bool { return progressMade(s.planResult) }
if err := retryMax(limit, s.process, progress); err != nil {
if statusErr, ok := err.(*SetStatusError); ok {
return setStatus(s.logger, s.planner, s.eval, nil, nil,
return setStatus(s.logger, s.planner, s.eval, nil,
s.failedTGAllocs, s.planAnnotations, statusErr.EvalStatus, err.Error(),
s.queuedAllocs, "")
}
return err
}

// Update the status to complete
return setStatus(s.logger, s.planner, s.eval, nil, nil,
return setStatus(s.logger, s.planner, s.eval, nil,
s.failedTGAllocs, s.planAnnotations, structs.EvalStatusComplete, "",
s.queuedAllocs, "")
}
Expand Down
6 changes: 3 additions & 3 deletions scheduler/scheduler_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *SystemScheduler) Process(eval *structs.Evaluation) (err error) {
// Verify the evaluation trigger reason is understood
if !s.canHandle(eval.TriggeredBy) {
desc := fmt.Sprintf("scheduler cannot handle '%s' evaluation reason", eval.TriggeredBy)
return setStatus(s.logger, s.planner, s.eval, nil, nil,
return setStatus(s.logger, s.planner, s.eval, nil,
s.failedTGAllocs, s.planAnnotations, structs.EvalStatusFailed, desc,
s.queuedAllocs, s.deployment.GetID())
}
Expand All @@ -98,15 +98,15 @@ func (s *SystemScheduler) Process(eval *structs.Evaluation) (err error) {
progress := func() bool { return progressMade(s.planResult) }
if err := retryMax(limit, s.process, progress); err != nil {
if statusErr, ok := err.(*SetStatusError); ok {
return setStatus(s.logger, s.planner, s.eval, nil, nil,
return setStatus(s.logger, s.planner, s.eval, nil,
s.failedTGAllocs, s.planAnnotations, statusErr.EvalStatus, err.Error(),
s.queuedAllocs, s.deployment.GetID())
}
return err
}

// Update the status to complete
return setStatus(s.logger, s.planner, s.eval, nil, nil,
return setStatus(s.logger, s.planner, s.eval, nil,
s.failedTGAllocs, s.planAnnotations, structs.EvalStatusComplete, "",
s.queuedAllocs, s.deployment.GetID())
}
Expand Down
6 changes: 2 additions & 4 deletions scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func renderTemplatesUpdated(a, b *structs.RestartPolicy, msg string) comparison

// setStatus is used to update the status of the evaluation
func setStatus(logger log.Logger, planner sstructs.Planner,
eval, nextEval, spawnedBlocked *structs.Evaluation,
eval, spawnedBlocked *structs.Evaluation,
tgMetrics map[string]*structs.AllocMetric,
annotations *structs.PlanAnnotations,
status, desc string,
Expand All @@ -554,9 +554,7 @@ func setStatus(logger log.Logger, planner sstructs.Planner,
newEval.StatusDescription = desc
newEval.DeploymentID = deploymentID
newEval.FailedTGAllocs = tgMetrics
if nextEval != nil {
newEval.NextEval = nextEval.ID
}

if spawnedBlocked != nil {
newEval.BlockedEval = spawnedBlocked.ID
}
Expand Down
21 changes: 6 additions & 15 deletions scheduler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,26 +613,17 @@ func TestSetStatus(t *testing.T) {
eval := mock.Eval()
status := "a"
desc := "b"
must.NoError(t, setStatus(logger, h, eval, nil, nil, nil, nil, status, desc, nil, ""))
must.NoError(t, setStatus(logger, h, eval, nil, nil, nil, status, desc, nil, ""))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

newEval := h.Evals[0]
must.True(t, newEval.ID == eval.ID && newEval.Status == status && newEval.StatusDescription == desc,
must.Sprintf("setStatus() submited invalid eval: %v", newEval))

// Test next evals
h = tests.NewHarness(t)
next := mock.Eval()
must.NoError(t, setStatus(logger, h, eval, next, nil, nil, nil, status, desc, nil, ""))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

newEval = h.Evals[0]
must.Eq(t, next.ID, newEval.NextEval, must.Sprintf("setStatus() didn't set nextEval correctly: %v", newEval))

// Test blocked evals
h = tests.NewHarness(t)
blocked := mock.Eval()
must.NoError(t, setStatus(logger, h, eval, nil, blocked, nil, nil, status, desc, nil, ""))
must.NoError(t, setStatus(logger, h, eval, blocked, nil, nil, status, desc, nil, ""))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

newEval = h.Evals[0]
Expand All @@ -641,7 +632,7 @@ func TestSetStatus(t *testing.T) {
// Test metrics
h = tests.NewHarness(t)
metrics := map[string]*structs.AllocMetric{"foo": nil}
must.NoError(t, setStatus(logger, h, eval, nil, nil, metrics, nil, status, desc, nil, ""))
must.NoError(t, setStatus(logger, h, eval, nil, metrics, nil, status, desc, nil, ""))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

newEval = h.Evals[0]
Expand All @@ -652,7 +643,7 @@ func TestSetStatus(t *testing.T) {
h = tests.NewHarness(t)
queuedAllocs := map[string]int{"web": 1}

must.NoError(t, setStatus(logger, h, eval, nil, nil, metrics, nil, status, desc, queuedAllocs, ""))
must.NoError(t, setStatus(logger, h, eval, nil, metrics, nil, status, desc, queuedAllocs, ""))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

// Test annotations
Expand All @@ -662,15 +653,15 @@ func TestSetStatus(t *testing.T) {
PreemptedAllocs: []*structs.AllocListStub{{ID: uuid.Generate()}},
}

must.NoError(t, setStatus(logger, h, eval, nil, nil, metrics, annotations, status, desc, queuedAllocs, ""))
must.NoError(t, setStatus(logger, h, eval, nil, metrics, annotations, status, desc, queuedAllocs, ""))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

newEval = h.Evals[0]
must.Eq(t, annotations, newEval.PlanAnnotations, must.Sprintf("setStatus() didn't set plan annotations correctly: %v", newEval))

h = tests.NewHarness(t)
dID := uuid.Generate()
must.NoError(t, setStatus(logger, h, eval, nil, nil, metrics, nil, status, desc, queuedAllocs, dID))
must.NoError(t, setStatus(logger, h, eval, nil, metrics, nil, status, desc, queuedAllocs, dID))
must.Eq(t, 1, len(h.Evals), must.Sprintf("setStatus() didn't update plan: %v", h.Evals))

newEval = h.Evals[0]
Expand Down
Loading