From 48eda99dd937d8b40cc18d60f1579b39f08b0db3 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 28 Jul 2016 12:13:35 -0700 Subject: [PATCH 1/2] Setting the queued count as zero if there is nothing to place --- scheduler/generic_sched.go | 5 ++++ scheduler/generic_sched_test.go | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index acafac9c5..61428a311 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -392,6 +392,11 @@ func (s *GenericScheduler) computeJobAllocs() error { // Nothing remaining to do if placement is not required if len(diff.place) == 0 { + if s.job != nil { + for _, tg := range s.job.TaskGroups { + s.queuedAllocs[tg.Name] = 0 + } + } return nil } diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index 691fb3cf7..585676dd0 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -1294,6 +1294,56 @@ func TestServiceSched_NodeDown(t *testing.T) { h.AssertEvalStatus(t, structs.EvalStatusComplete) } +func TestServiceSched_NodeUpdate(t *testing.T) { + h := NewHarness(t) + + // Register a node + node := mock.Node() + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) + + // Generate a fake job with allocations and an update policy. + job := mock.Job() + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) + + var allocs []*structs.Allocation + for i := 0; i < 10; i++ { + alloc := mock.Alloc() + alloc.Job = job + alloc.JobID = job.ID + alloc.NodeID = node.ID + alloc.Name = fmt.Sprintf("my-job.web[%d]", i) + allocs = append(allocs, alloc) + } + noErr(t, h.State.UpsertAllocs(h.NextIndex(), allocs)) + + // Mark some allocs as running + for i := 0; i < 4; i++ { + out, _ := h.State.AllocByID(allocs[i].ID) + out.ClientStatus = structs.AllocClientStatusRunning + noErr(t, h.State.UpdateAllocsFromClient(h.NextIndex(), []*structs.Allocation{out})) + } + + // Create a mock evaluation to deal with drain + eval := &structs.Evaluation{ + ID: structs.GenerateUUID(), + Priority: 50, + TriggeredBy: structs.EvalTriggerNodeUpdate, + JobID: job.ID, + NodeID: node.ID, + } + + // Process the evaluation + err := h.Process(NewServiceScheduler, eval) + if err != nil { + t.Fatalf("err: %v", err) + } + if h.Evals[0].QueuedAllocations["web"] != 0 { + t.Fatalf("bad queued allocations: %v", h.Evals[0].QueuedAllocations) + } + + h.AssertEvalStatus(t, structs.EvalStatusComplete) +} + func TestServiceSched_NodeDrain(t *testing.T) { h := NewHarness(t) From 2e84d246f9f88b7cc606d0fef59adc33891dea1b Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 28 Jul 2016 12:22:44 -0700 Subject: [PATCH 2/2] fixed a comment --- scheduler/generic_sched_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index 585676dd0..69e72e69d 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -1323,7 +1323,7 @@ func TestServiceSched_NodeUpdate(t *testing.T) { noErr(t, h.State.UpdateAllocsFromClient(h.NextIndex(), []*structs.Allocation{out})) } - // Create a mock evaluation to deal with drain + // Create a mock evaluation which won't trigger any new placements eval := &structs.Evaluation{ ID: structs.GenerateUUID(), Priority: 50,