Skip to content

Commit

Permalink
check for spread changes when checking inplace update
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Nov 18, 2019
1 parent 1344651 commit 6d7d0bd
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 7 deletions.
42 changes: 35 additions & 7 deletions scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
return true
}

// Check Spreads
if spreadsUpdated(jobA, jobB, taskGroup) {
return true
}

// Check each task
for _, at := range a.Tasks {
bt := b.LookupTask(at.Name)
Expand Down Expand Up @@ -459,11 +464,11 @@ func affinitiesUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
tgA := jobA.LookupTaskGroup(taskGroup)
tgB := jobB.LookupTaskGroup(taskGroup)

// append job level affinities
// Append jobA job and task group level affinities
aAffinities = append(aAffinities, jobA.Affinities...)
aAffinities = append(aAffinities, tgA.Affinities...)

// append task group affinities
// Append jobB job and task group level affinities
bAffinities = append(bAffinities, jobB.Affinities...)
bAffinities = append(bAffinities, tgB.Affinities...)

Expand All @@ -472,11 +477,11 @@ func affinitiesUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
aAffinities = append(aAffinities, task.Affinities...)
}

// append task affinities
for _, task := range tgB.Tasks {
bAffinities = append(bAffinities, task.Affinities...)
}

// Check for equality
if len(aAffinities) != len(bAffinities) {
return true
}
Expand All @@ -491,31 +496,54 @@ func constraintsUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
tgA := jobA.LookupTaskGroup(taskGroup)
tgB := jobB.LookupTaskGroup(taskGroup)

// append job level constraints
// Append jobA job and task group level constraints
aConstraints = append(aConstraints, jobA.Constraints...)
aConstraints = append(aConstraints, tgA.Constraints...)

// append task group constraints
// Append jobB job and task group level constraints
bConstraints = append(bConstraints, jobB.Constraints...)
bConstraints = append(bConstraints, tgB.Constraints...)

// append task constraints
// Append task constraints
for _, task := range tgA.Tasks {
aConstraints = append(aConstraints, task.Constraints...)
}

// append task constraints
for _, task := range tgB.Tasks {
bConstraints = append(bConstraints, task.Constraints...)
}

// Check for equality
if len(aConstraints) != len(bConstraints) {
return true
}

return !reflect.DeepEqual(aConstraints, bConstraints)
}

func spreadsUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
var aSpreads []*structs.Spread
var bSpreads []*structs.Spread

tgA := jobA.LookupTaskGroup(taskGroup)
tgB := jobB.LookupTaskGroup(taskGroup)

// append jobA and task group level spreads
aSpreads = append(aSpreads, jobA.Spreads...)
aSpreads = append(aSpreads, tgA.Spreads...)

// append jobB and task group level spreads
bSpreads = append(bSpreads, jobB.Spreads...)
bSpreads = append(bSpreads, tgB.Spreads...)

// Check for equality
if len(aSpreads) != len(bSpreads) {
return true
}

return !reflect.DeepEqual(aSpreads, bSpreads)
}

// setStatus is used to update the status of the evaluation
func setStatus(logger log.Logger, planner Planner,
eval, nextEval, spawnedBlocked *structs.Evaluation,
Expand Down
65 changes: 65 additions & 0 deletions scheduler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,71 @@ func TestTaskUpdated_Constraint(t *testing.T) {
require.False(t, tasksUpdated(j5, j6, name))
}

func TestTaskUpdatedSpread(t *testing.T) {
j1 := mock.Job()
j2 := mock.Job()
name := j1.TaskGroups[0].Name

require.False(t, tasksUpdated(j1, j2, name))

// TaskGroup Spread
j2.TaskGroups[0].Spreads = []*structs.Spread{
{
Attribute: "node.datacenter",
Weight: 100,
SpreadTarget: []*structs.SpreadTarget{
{
Value: "r1",
Percent: 50,
},
{
Value: "r2",
Percent: 50,
},
},
},
}
require.True(t, tasksUpdated(j1, j2, name))

// check different level of same constraint
j5 := mock.Job()
j5.Spreads = []*structs.Spread{
{
Attribute: "node.datacenter",
Weight: 100,
SpreadTarget: []*structs.SpreadTarget{
{
Value: "r1",
Percent: 50,
},
{
Value: "r2",
Percent: 50,
},
},
},
}

j6 := mock.Job()
j6.TaskGroups[0].Spreads = []*structs.Spread{
{
Attribute: "node.datacenter",
Weight: 100,
SpreadTarget: []*structs.SpreadTarget{
{
Value: "r1",
Percent: 50,
},
{
Value: "r2",
Percent: 50,
},
},
},
}

require.False(t, tasksUpdated(j5, j6, name))
}
func TestTasksUpdated(t *testing.T) {
j1 := mock.Job()
j2 := mock.Job()
Expand Down

0 comments on commit 6d7d0bd

Please sign in to comment.