From a9d410dbee221c3590996c3b19a1b83680808686 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 24 Feb 2016 14:50:59 -0800 Subject: [PATCH] Store the job on allocations that are from stopped jobs --- nomad/structs/structs.go | 10 +++++++++- scheduler/generic_sched_test.go | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index bdb47b16c..1aa47ea3a 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2421,7 +2421,15 @@ type Plan struct { func (p *Plan) AppendUpdate(alloc *Allocation, status, desc string) { newAlloc := new(Allocation) *newAlloc = *alloc - newAlloc.Job = nil // Normalize the job + + // If the job is not set in the plan we are deregistering a job so we + // extract the job from the allocation. + if p.Job == nil && newAlloc.Job != nil { + p.Job = newAlloc.Job + } + + // Normalize the job + newAlloc.Job = nil newAlloc.DesiredStatus = status newAlloc.DesiredDescription = desc node := alloc.NodeID diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index 839112965..390b55182 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -634,6 +634,13 @@ func TestServiceSched_JobDeregister(t *testing.T) { out, err := h.State.AllocsByJob(job.ID) noErr(t, err) + // Ensure that the job field on the allocation is still populated + for _, alloc := range out { + if alloc.Job == nil { + t.Fatalf("bad: %#v", alloc) + } + } + // Ensure no remaining allocations out = structs.FilterTerminalAllocs(out) if len(out) != 0 {