Files
nomad/scheduler/context.go
2015-08-13 18:34:04 -07:00

69 lines
1.3 KiB
Go

package scheduler
import (
"log"
"github.com/hashicorp/nomad/nomad/structs"
)
// Context is used to track contextual information used for placement
type Context interface {
// State is used to inspect the current global state
State() State
// Plan returns the current plan
Plan() *structs.Plan
// Logger provides a way to log
Logger() *log.Logger
// Metrics returns the current metrics
Metrics() *structs.AllocMetric
// Reset is invoked after making a placement
Reset()
}
// EvalContext is a Context used during an Evaluation
type EvalContext struct {
state State
plan *structs.Plan
logger *log.Logger
metrics *structs.AllocMetric
}
// NewEvalContext constructs a new EvalContext
func NewEvalContext(s State, p *structs.Plan, log *log.Logger) *EvalContext {
ctx := &EvalContext{
state: s,
plan: p,
logger: log,
metrics: new(structs.AllocMetric),
}
return ctx
}
func (e *EvalContext) State() State {
return e.state
}
func (e *EvalContext) Plan() *structs.Plan {
return e.plan
}
func (e *EvalContext) Logger() *log.Logger {
return e.logger
}
func (e *EvalContext) Metrics() *structs.AllocMetric {
return e.metrics
}
func (e *EvalContext) SetState(s State) {
e.state = s
}
func (e *EvalContext) Reset() {
e.metrics = new(structs.AllocMetric)
}