scheduler: Adding State to Context

This commit is contained in:
Armon Dadgar
2015-08-13 11:33:58 -07:00
parent a4bf95e282
commit 3e8117e91c
5 changed files with 39 additions and 7 deletions

View File

@@ -2,14 +2,25 @@ package scheduler
// Context is used to track contextual information used for placement
type Context interface {
// State is used to inspect the current global state
State() State
}
// EvalContext is a Context used during an Evaluation
type EvalContext struct {
state State
}
// NewEvalContext constructs a new EvalContext
func NewEvalContext() *EvalContext {
func NewEvalContext(s State) *EvalContext {
ctx := &EvalContext{}
return ctx
}
func (e *EvalContext) State() State {
return e.state
}
func (e *EvalContext) SetState(s State) {
e.state = s
}

18
scheduler/context_test.go Normal file
View File

@@ -0,0 +1,18 @@
package scheduler
import (
"os"
"testing"
"github.com/hashicorp/nomad/nomad/state"
)
func testContext(t *testing.T) (*state.StateStore, *EvalContext) {
state, err := state.NewStateStore(os.Stderr)
if err != nil {
t.Fatalf("err: %v", err)
}
ctx := NewEvalContext(state)
return state, ctx
}

View File

@@ -9,7 +9,7 @@ import (
)
func TestRandomIterator(t *testing.T) {
ctx := NewEvalContext()
_, ctx := testContext(t)
var nodes []*structs.Node
for i := 0; i < 10; i++ {
nodes = append(nodes, mock.Node())
@@ -37,7 +37,7 @@ func TestRandomIterator(t *testing.T) {
}
func TestDriverIterator(t *testing.T) {
ctx := NewEvalContext()
_, ctx := testContext(t)
nodes := []*structs.Node{
mock.Node(),
mock.Node(),
@@ -72,7 +72,7 @@ func TestDriverIterator(t *testing.T) {
}
func TestConstraintIterator(t *testing.T) {
ctx := NewEvalContext()
_, ctx := testContext(t)
nodes := []*structs.Node{
mock.Node(),
mock.Node(),

View File

@@ -8,7 +8,7 @@ import (
)
func TestFeasibleRankIterator(t *testing.T) {
ctx := NewEvalContext()
_, ctx := testContext(t)
var nodes []*structs.Node
for i := 0; i < 10; i++ {
nodes = append(nodes, mock.Node())
@@ -31,6 +31,9 @@ func TestFeasibleRankIterator(t *testing.T) {
}
}
func TestBinPackIterator(t *testing.T) {
}
func TestScoreFit(t *testing.T) {
node := mock.Node()
node.Resources = &structs.Resources{

View File

@@ -7,7 +7,7 @@ import (
)
func TestLimitIterator(t *testing.T) {
ctx := NewEvalContext()
_, ctx := testContext(t)
nodes := []*RankedNode{
&RankedNode{
Node: mock.Node(),
@@ -44,7 +44,7 @@ func TestLimitIterator(t *testing.T) {
}
func TestMaxScoreIterator(t *testing.T) {
ctx := NewEvalContext()
_, ctx := testContext(t)
nodes := []*RankedNode{
&RankedNode{
Node: mock.Node(),