scheduler: allow updating the base nodes

This commit is contained in:
Armon Dadgar
2015-09-07 11:30:13 -07:00
parent 831848bf5e
commit efdf717991
2 changed files with 29 additions and 2 deletions

View File

@@ -22,6 +22,9 @@ const (
// make placement decisions. Different schedulers may customize the
// stack they use to vary the way placements are made.
type Stack interface {
// SetNodes is used to set the base set of potential nodes
SetNodes([]*structs.Node)
// SetTaskGroup is used to set the job for selection
SetJob(job *structs.Job)
@@ -34,6 +37,7 @@ type Stack interface {
type GenericStack struct {
batch bool
ctx Context
source *StaticIterator
jobConstraint *ConstraintIterator
taskGroupDrivers *DriverIterator
taskGroupConstraint *ConstraintIterator
@@ -53,10 +57,10 @@ func NewGenericStack(batch bool, ctx Context, baseNodes []*structs.Node) *Generi
// Create the source iterator. We randomize the order we visit nodes
// to reduce collisions between schedulers and to do a basic load
// balancing across eligible nodes.
source := NewRandomIterator(ctx, baseNodes)
stack.source = NewRandomIterator(ctx, baseNodes)
// Attach the job constraints. The job is filled in later.
stack.jobConstraint = NewConstraintIterator(ctx, source, nil)
stack.jobConstraint = NewConstraintIterator(ctx, stack.source, nil)
// Filter on task group drivers first as they are faster
stack.taskGroupDrivers = NewDriverIterator(ctx, stack.jobConstraint, nil)
@@ -101,6 +105,14 @@ func NewGenericStack(batch bool, ctx Context, baseNodes []*structs.Node) *Generi
return stack
}
func (s *GenericStack) SetNodes(baseNodes []*structs.Node) {
// Shuffle base nodes
shuffleNodes(baseNodes)
// Update the set of base nodes
s.source.SetNodes(baseNodes)
}
func (s *GenericStack) SetJob(job *structs.Job) {
s.jobConstraint.SetConstraints(job.Constraints)
s.binPack.SetPriority(job.Priority)

View File

@@ -8,6 +8,21 @@ import (
"github.com/hashicorp/nomad/nomad/structs"
)
func TestServiceStack_SetNodes(t *testing.T) {
_, ctx := testContext(t)
stack := NewGenericStack(false, ctx, nil)
nodes := []*structs.Node{
mock.Node(),
}
stack.SetNodes(nodes)
out := collectFeasible(stack.source)
if !reflect.DeepEqual(out, nodes) {
t.Fatalf("bad: %#v", out)
}
}
func TestServiceStack_SetJob(t *testing.T) {
_, ctx := testContext(t)
stack := NewGenericStack(false, ctx, nil)