From 92bddbc3a52444f9e1dfa25872242c3b4511afb6 Mon Sep 17 00:00:00 2001 From: Alex Dadgar <alex.dadgar@gmail.com> Date: Tue, 24 May 2016 18:12:59 -0700 Subject: [PATCH] rename SpawnedBlockedEval and simplify map safety check --- api/evaluations.go | 34 ++++++++++++++++----------------- command/monitor.go | 6 +++--- nomad/structs/structs.go | 8 ++++---- scheduler/generic_sched.go | 10 ++++------ scheduler/generic_sched_test.go | 6 +++--- scheduler/system_sched.go | 2 +- scheduler/util.go | 2 +- scheduler/util_test.go | 4 ++-- 8 files changed, 35 insertions(+), 37 deletions(-) diff --git a/api/evaluations.go b/api/evaluations.go index a10c3cba57..37774d321c 100644 --- a/api/evaluations.go +++ b/api/evaluations.go @@ -54,23 +54,23 @@ func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*Allocation // Evaluation is used to serialize an evaluation. type Evaluation struct { - ID string - Priority int - Type string - TriggeredBy string - JobID string - JobModifyIndex uint64 - NodeID string - NodeModifyIndex uint64 - Status string - StatusDescription string - Wait time.Duration - NextEval string - PreviousEval string - SpawnedBlockedEval string - FailedTGAllocs map[string]*AllocationMetric - CreateIndex uint64 - ModifyIndex uint64 + ID string + Priority int + Type string + TriggeredBy string + JobID string + JobModifyIndex uint64 + NodeID string + NodeModifyIndex uint64 + Status string + StatusDescription string + Wait time.Duration + NextEval string + PreviousEval string + BlockedEval string + FailedTGAllocs map[string]*AllocationMetric + CreateIndex uint64 + ModifyIndex uint64 } // EvalIndexSort is a wrapper to sort evaluations by CreateIndex. diff --git a/command/monitor.go b/command/monitor.go index f5417f26a8..5cfe6810f3 100644 --- a/command/monitor.go +++ b/command/monitor.go @@ -307,9 +307,9 @@ func (m *monitor) monitor(evalID string, allowPrefix bool) int { dumpAllocMetrics(m.ui, metrics, false) } - if eval.SpawnedBlockedEval != "" { - m.ui.Output(fmt.Sprintf("Spawned follow up blocked evaluation %q to place remainder", - limit(eval.SpawnedBlockedEval, m.length))) + if eval.BlockedEval != "" { + m.ui.Output(fmt.Sprintf("Evaluation %q waiting for additional capacity to place remainder", + limit(eval.BlockedEval, m.length))) } } default: diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 577893850b..4a70e96bb8 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2617,10 +2617,10 @@ type Evaluation struct { // This is used to support rolling upgrades, where we need a chain of evaluations. PreviousEval string - // SpawnedBlockedEval is the evaluation ID for a created blocked eval. A + // BlockedEval is the evaluation ID for a created blocked eval. A // blocked eval will be created if all allocations could not be placed due // to constraints or lacking resources. - SpawnedBlockedEval string + BlockedEval string // FailedTGAllocs are task groups which have allocations that could not be // made, but the metrics are persisted so that the user can use the feedback @@ -2744,10 +2744,10 @@ func (e *Evaluation) NextRollingEval(wait time.Duration) *Evaluation { } } -// BlockedEval creates a blocked evaluation to followup this eval to place any +// CreateBlockedEval creates a blocked evaluation to followup this eval to place any // failed allocations. It takes the classes marked explicitly eligible or // ineligible and whether the job has escaped computed node classes. -func (e *Evaluation) BlockedEval(classEligibility map[string]bool, escaped bool) *Evaluation { +func (e *Evaluation) CreateBlockedEval(classEligibility map[string]bool, escaped bool) *Evaluation { return &Evaluation{ ID: GenerateUUID(), Priority: e.Priority, diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index 2595fbac7c..056c90d4ed 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -140,7 +140,7 @@ func (s *GenericScheduler) createBlockedEval() error { classEligibility = e.GetClasses() } - s.blocked = s.eval.BlockedEval(classEligibility, escaped) + s.blocked = s.eval.CreateBlockedEval(classEligibility, escaped) return s.planner.CreateEval(s.blocked) } @@ -370,11 +370,9 @@ func (s *GenericScheduler) computePlacements(place []allocTuple) error { for _, missing := range place { // Check if this task group has already failed - if s.eval.FailedTGAllocs != nil { - if metric, ok := s.eval.FailedTGAllocs[missing.TaskGroup.Name]; ok { - metric.CoalescedFailures += 1 - continue - } + if metric, ok := s.eval.FailedTGAllocs[missing.TaskGroup.Name]; ok { + metric.CoalescedFailures += 1 + continue } // Attempt to match the task group diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index 879da2a837..ff6b983018 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -51,7 +51,7 @@ func TestServiceSched_JobRegister(t *testing.T) { // Ensure the eval has no spawned blocked eval if len(h.Evals) != 1 { t.Fatalf("bad: %#v", h.Evals) - if h.Evals[0].SpawnedBlockedEval != "" { + if h.Evals[0].BlockedEval != "" { t.Fatalf("bad: %#v", h.Evals[0]) } } @@ -248,7 +248,7 @@ func TestServiceSched_JobRegister_AllocFail(t *testing.T) { outEval := h.Evals[0] // Ensure the eval has its spawned blocked eval - if outEval.SpawnedBlockedEval != h.CreateEvals[0].ID { + if outEval.BlockedEval != h.CreateEvals[0].ID { t.Fatalf("bad: %#v", outEval) } @@ -432,7 +432,7 @@ func TestServiceSched_JobRegister_FeasibleAndInfeasibleTG(t *testing.T) { outEval := h.Evals[0] // Ensure the eval has its spawned blocked eval - if outEval.SpawnedBlockedEval != h.CreateEvals[0].ID { + if outEval.BlockedEval != h.CreateEvals[0].ID { t.Fatalf("bad: %#v", outEval) } diff --git a/scheduler/system_sched.go b/scheduler/system_sched.go index e0bef083ad..9f64e95be2 100644 --- a/scheduler/system_sched.go +++ b/scheduler/system_sched.go @@ -237,7 +237,7 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error { // Attempt to match the task group option, _ := s.stack.Select(missing.TaskGroup) - if option == nil && s.eval.FailedTGAllocs != nil { + if option == nil { // Check if this task group has already failed if metric, ok := s.eval.FailedTGAllocs[missing.TaskGroup.Name]; ok { metric.CoalescedFailures += 1 diff --git a/scheduler/util.go b/scheduler/util.go index 89ad49dc92..9961649c54 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -365,7 +365,7 @@ func setStatus(logger *log.Logger, planner Planner, eval, nextEval, spawnedBlock newEval.NextEval = nextEval.ID } if spawnedBlocked != nil { - newEval.SpawnedBlockedEval = spawnedBlocked.ID + newEval.BlockedEval = spawnedBlocked.ID } return planner.UpdateEval(newEval) } diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 73fc29f8f7..e9957a5012 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -526,8 +526,8 @@ func TestSetStatus(t *testing.T) { } newEval = h.Evals[0] - if newEval.SpawnedBlockedEval != blocked.ID { - t.Fatalf("setStatus() didn't set SpawnedBlockedEval correctly: %v", newEval) + if newEval.BlockedEval != blocked.ID { + t.Fatalf("setStatus() didn't set BlockedEval correctly: %v", newEval) } } -- GitLab