scheduler: share context and stack

This commit is contained in:
Armon Dadgar
2015-09-07 11:34:59 -07:00
parent efdf717991
commit b54eeec47d

View File

@@ -48,8 +48,10 @@ type GenericScheduler struct {
planner Planner
batch bool
eval *structs.Evaluation
plan *structs.Plan
eval *structs.Evaluation
plan *structs.Plan
ctx *EvalContext
stack *GenericStack
}
// NewServiceScheduler is a factory function to instantiate a new service scheduler
@@ -127,6 +129,12 @@ func (s *GenericScheduler) process() (bool, error) {
// Create a plan
s.plan = s.eval.MakePlan(job)
// Create an evaluation context
s.ctx = NewEvalContext(s.state, s.plan, s.logger)
// Construct the placement stack
s.stack = NewGenericStack(s.batch, s.ctx, nil)
// Compute the target job allocations
if err := s.computeJobAllocs(job); err != nil {
s.logger.Printf("[ERR] sched: %#v: %v", s.eval, err)
@@ -228,8 +236,8 @@ func (s *GenericScheduler) computePlacements(job *structs.Job, place []allocTupl
return err
}
// Construct the placement stack
stack := NewGenericStack(s.batch, ctx, nodes)
// Update the set of placement ndoes
s.stack.SetNodes(nodes)
// Track the failed task groups so that we can coalesce
// the failures together to avoid creating many failed allocs.
@@ -243,7 +251,7 @@ func (s *GenericScheduler) computePlacements(job *structs.Job, place []allocTupl
}
// Attempt to match the task group
option, size := stack.Select(missing.TaskGroup)
option, size := s.stack.Select(missing.TaskGroup)
// Handle a placement failure
var nodeID, status, desc, clientStatus string
@@ -267,7 +275,7 @@ func (s *GenericScheduler) computePlacements(job *structs.Job, place []allocTupl
Job: job,
TaskGroup: missing.TaskGroup.Name,
Resources: size,
Metrics: ctx.Metrics(),
Metrics: s.ctx.Metrics(),
DesiredStatus: status,
DesiredDescription: desc,
ClientStatus: clientStatus,