Skip to content

Commit

Permalink
nomad: use OutstandingReset in Eval endpoints and Plan apply
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Oct 23, 2015
1 parent a050185 commit 2beae1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
16 changes: 4 additions & 12 deletions nomad/eval_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions nomad/plan_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 2beae1a

Please sign in to comment.