nomad: use OutstandingReset in Eval endpoints and Plan apply

This commit is contained in:
Armon Dadgar 2015-10-23 10:22:44 -07:00
parent b9bb7bdaaa
commit c6502fac83
2 changed files with 8 additions and 23 deletions

View File

@ -134,12 +134,8 @@ func (e *Eval) Update(args *structs.EvalUpdateRequest,
eval := args.Evals[0]
// Verify the evaluation is outstanding, and that the tokens match.
token, ok := e.srv.evalBroker.Outstanding(eval.ID)
if !ok {
return fmt.Errorf("evaluation is not outstanding")
}
if args.EvalToken != token {
return fmt.Errorf("evaluation token does not match")
if err := e.srv.evalBroker.OutstandingReset(eval.ID, args.EvalToken); err != nil {
return err
}
// Update via Raft
@ -168,12 +164,8 @@ func (e *Eval) Create(args *structs.EvalUpdateRequest,
eval := args.Evals[0]
// Verify the parent evaluation is outstanding, and that the tokens match.
token, ok := e.srv.evalBroker.Outstanding(eval.PreviousEval)
if !ok {
return fmt.Errorf("previous evaluation is not outstanding")
}
if args.EvalToken != token {
return fmt.Errorf("previous evaluation token does not match")
if err := e.srv.evalBroker.OutstandingReset(eval.PreviousEval, args.EvalToken); err != nil {
return err
}
// Look for the eval

View File

@ -50,17 +50,10 @@ func (s *Server) planApply() {
}
// Verify the evaluation is outstanding, and that the tokens match.
token, ok := s.evalBroker.Outstanding(pending.plan.EvalID)
if !ok {
s.logger.Printf("[ERR] nomad: plan received for non-outstanding evaluation %s",
pending.plan.EvalID)
pending.respond(nil, fmt.Errorf("evaluation is not outstanding"))
continue
}
if pending.plan.EvalToken != token {
s.logger.Printf("[ERR] nomad: plan received for evaluation %s with wrong token",
pending.plan.EvalID)
pending.respond(nil, fmt.Errorf("evaluation token does not match"))
if err := s.evalBroker.OutstandingReset(pending.plan.EvalID, pending.plan.EvalToken); err != nil {
s.logger.Printf("[ERR] nomad: plan rejected for evaluation %s: %v",
pending.plan.EvalID, err)
pending.respond(nil, err)
continue
}