mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 02:45:42 +03:00
scheduler: Adding State to Context
This commit is contained in:
@@ -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
18
scheduler/context_test.go
Normal 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
|
||||
}
|
||||
@@ -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(),
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user