Skip to content

Commit

Permalink
Fix not enqueuing eval
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar authored and preetapan committed May 7, 2018
1 parent f952300 commit 01fcba1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
4 changes: 3 additions & 1 deletion nomad/drainer_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func allocPromoter(errCh chan<- error, ctx context.Context,

// For each alloc that doesn't have its deployment status set, set it
var updates []*structs.Allocation
now := time.Now()
for _, alloc := range allocs {
if alloc.Job.Type != structs.JobTypeService {
continue
Expand All @@ -48,7 +49,8 @@ func allocPromoter(errCh chan<- error, ctx context.Context,
}
newAlloc := alloc.Copy()
newAlloc.DeploymentStatus = &structs.AllocDeploymentStatus{
Healthy: helper.BoolToPtr(true),
Healthy: helper.BoolToPtr(true),
Timestamp: now,
}
updates = append(updates, newAlloc)
logger.Printf("Marked deployment health for alloc %q", alloc.ID)
Expand Down
54 changes: 31 additions & 23 deletions nomad/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,19 +582,34 @@ func (n *nomadFSM) upsertEvals(index uint64, evals []*structs.Evaluation) error
return err
}

n.handleUpsertedEvals(evals)
return nil
}

// handleUpsertingEval is a helper for taking action after upserting
// evaluations.
func (n *nomadFSM) handleUpsertedEvals(evals []*structs.Evaluation) {
for _, eval := range evals {
if eval.ShouldEnqueue() {
n.evalBroker.Enqueue(eval)
} else if eval.ShouldBlock() {
n.blockedEvals.Block(eval)
} else if eval.Status == structs.EvalStatusComplete &&
len(eval.FailedTGAllocs) == 0 {
// If we have a successful evaluation for a node, untrack any
// blocked evaluation
n.blockedEvals.Untrack(eval.JobID)
}
n.handleUpsertedEval(eval)
}
}

// handleUpsertingEval is a helper for taking action after upserting an eval.
func (n *nomadFSM) handleUpsertedEval(eval *structs.Evaluation) {
if eval == nil {
return
}

if eval.ShouldEnqueue() {
n.evalBroker.Enqueue(eval)
} else if eval.ShouldBlock() {
n.blockedEvals.Block(eval)
} else if eval.Status == structs.EvalStatusComplete &&
len(eval.FailedTGAllocs) == 0 {
// If we have a successful evaluation for a node, untrack any
// blocked evaluation
n.blockedEvals.Untrack(eval.JobID)
}
return nil
}

func (n *nomadFSM) applyDeleteEval(buf []byte, index uint64) interface{} {
Expand Down Expand Up @@ -730,6 +745,8 @@ func (n *nomadFSM) applyAllocUpdateDesiredTransition(buf []byte, index uint64) i
n.logger.Printf("[ERR] nomad.fsm: UpdateAllocsDesiredTransitions failed: %v", err)
return err
}

n.handleUpsertedEvals(req.Evals)
return nil
}

Expand Down Expand Up @@ -821,10 +838,7 @@ func (n *nomadFSM) applyDeploymentStatusUpdate(buf []byte, index uint64) interfa
return err
}

if req.Eval != nil && req.Eval.ShouldEnqueue() {
n.evalBroker.Enqueue(req.Eval)
}

n.handleUpsertedEval(req.Eval)
return nil
}

Expand All @@ -841,10 +855,7 @@ func (n *nomadFSM) applyDeploymentPromotion(buf []byte, index uint64) interface{
return err
}

if req.Eval != nil && req.Eval.ShouldEnqueue() {
n.evalBroker.Enqueue(req.Eval)
}

n.handleUpsertedEval(req.Eval)
return nil
}

Expand All @@ -862,10 +873,7 @@ func (n *nomadFSM) applyDeploymentAllocHealth(buf []byte, index uint64) interfac
return err
}

if req.Eval != nil && req.Eval.ShouldEnqueue() {
n.evalBroker.Enqueue(req.Eval)
}

n.handleUpsertedEval(req.Eval)
return nil
}

Expand Down

0 comments on commit 01fcba1

Please sign in to comment.