scheduler

package
v0.3.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2016 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinSchedulers = map[string]Factory{
	"service": NewServiceScheduler,
	"batch":   NewBatchScheduler,
	"system":  NewSystemScheduler,
}

BuiltinSchedulers contains the built in registered schedulers which are available

Functions

This section is empty.

Types

type BinPackIterator

type BinPackIterator struct {
	// contains filtered or unexported fields
}

BinPackIterator is a RankIterator that scores potential options based on a bin-packing algorithm.

func NewBinPackIterator

func NewBinPackIterator(ctx Context, source RankIterator, evict bool, priority int) *BinPackIterator

NewBinPackIterator returns a BinPackIterator which tries to fit tasks potentially evicting other tasks based on a given priority.

func (*BinPackIterator) Next

func (iter *BinPackIterator) Next() *RankedNode

func (*BinPackIterator) Reset

func (iter *BinPackIterator) Reset()

func (*BinPackIterator) SetPriority

func (iter *BinPackIterator) SetPriority(p int)

func (*BinPackIterator) SetTasks

func (iter *BinPackIterator) SetTasks(tasks []*structs.Task)

type ComputedClassFeasibility added in v0.3.0

type ComputedClassFeasibility byte
const (
	// EvalComputedClassUnknown is the initial state until the eligibility has
	// been explicitely marked to eligible/ineligible or escaped.
	EvalComputedClassUnknown ComputedClassFeasibility = iota

	// EvalComputedClassIneligible is used to mark the computed class as
	// ineligible for the evaluation.
	EvalComputedClassIneligible

	// EvalComputedClassIneligible is used to mark the computed class as
	// eligible for the evaluation.
	EvalComputedClassEligible

	// EvalComputedClassEscaped signals that computed class can not determine
	// eligibility because a constraint exists that is not captured by computed
	// node classes.
	EvalComputedClassEscaped
)

type ConstraintChecker added in v0.3.0

type ConstraintChecker struct {
	// contains filtered or unexported fields
}

ConstraintChecker is a FeasibilityChecker which returns nodes that match a given set of constraints. This is used to filter on job, task group, and task constraints.

func NewConstraintChecker added in v0.3.0

func NewConstraintChecker(ctx Context, constraints []*structs.Constraint) *ConstraintChecker

NewConstraintChecker creates a ConstraintChecker for a set of constraints

func (*ConstraintChecker) Feasible added in v0.3.0

func (c *ConstraintChecker) Feasible(option *structs.Node) bool

func (*ConstraintChecker) SetConstraints added in v0.3.0

func (c *ConstraintChecker) SetConstraints(constraints []*structs.Constraint)

type Context

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()

	// ProposedAllocs returns the proposed allocations for a node
	// which is the existing allocations, removing evictions, and
	// adding any planned placements.
	ProposedAllocs(nodeID string) ([]*structs.Allocation, error)

	// RegexpCache is a cache of regular expressions
	RegexpCache() map[string]*regexp.Regexp

	// ConstraintCache is a cache of version constraints
	ConstraintCache() map[string]version.Constraints

	// Eligibility returns a tracker for node eligibility in the context of the
	// eval.
	Eligibility() *EvalEligibility
}

Context is used to track contextual information used for placement

type DriverChecker added in v0.3.0

type DriverChecker struct {
	// contains filtered or unexported fields
}

DriverChecker is a FeasibilityChecker which returns whether a node has the drivers necessary to scheduler a task group.

func NewDriverChecker added in v0.3.0

func NewDriverChecker(ctx Context, drivers map[string]struct{}) *DriverChecker

NewDriverChecker creates a DriverChecker from a set of drivers

func (*DriverChecker) Feasible added in v0.3.0

func (c *DriverChecker) Feasible(option *structs.Node) bool

func (*DriverChecker) SetDrivers added in v0.3.0

func (c *DriverChecker) SetDrivers(d map[string]struct{})

type EvalCache added in v0.2.0

type EvalCache struct {
	// contains filtered or unexported fields
}

EvalCache is used to cache certain things during an evaluation

func (*EvalCache) ConstraintCache added in v0.2.0

func (e *EvalCache) ConstraintCache() map[string]version.Constraints

func (*EvalCache) RegexpCache added in v0.2.0

func (e *EvalCache) RegexpCache() map[string]*regexp.Regexp

type EvalContext

type EvalContext struct {
	EvalCache
	// contains filtered or unexported fields
}

EvalContext is a Context used during an Evaluation

func NewEvalContext

func NewEvalContext(s State, p *structs.Plan, log *log.Logger) *EvalContext

NewEvalContext constructs a new EvalContext

func (*EvalContext) Eligibility added in v0.3.0

func (e *EvalContext) Eligibility() *EvalEligibility

func (*EvalContext) Logger

func (e *EvalContext) Logger() *log.Logger

func (*EvalContext) Metrics

func (e *EvalContext) Metrics() *structs.AllocMetric

func (*EvalContext) Plan

func (e *EvalContext) Plan() *structs.Plan

func (*EvalContext) ProposedAllocs

func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, error)

func (*EvalContext) Reset

func (e *EvalContext) Reset()

func (*EvalContext) SetState

func (e *EvalContext) SetState(s State)

func (*EvalContext) State

func (e *EvalContext) State() State

type EvalEligibility added in v0.3.0

type EvalEligibility struct {
	// contains filtered or unexported fields
}

EvalEligibility tracks eligibility of nodes by computed node class over the course of an evaluation.

func NewEvalEligibility added in v0.3.0

func NewEvalEligibility() *EvalEligibility

NewEvalEligibility returns an eligibility tracker for the context of an evaluation.

func (*EvalEligibility) GetClasses added in v0.3.0

func (e *EvalEligibility) GetClasses() map[string]bool

GetClasses returns the tracked classes to their eligibility, across the job and task groups.

func (*EvalEligibility) HasEscaped added in v0.3.0

func (e *EvalEligibility) HasEscaped() bool

HasEscaped returns whether any of the constraints in the passed job have escaped computed node classes.

func (*EvalEligibility) JobStatus added in v0.3.0

func (e *EvalEligibility) JobStatus(class string) ComputedClassFeasibility

JobStatus returns the eligibility status of the job.

func (*EvalEligibility) SetJob added in v0.3.0

func (e *EvalEligibility) SetJob(job *structs.Job)

SetJob takes the job being evaluated and calculates the escaped constraints at the job and task group level.

func (*EvalEligibility) SetJobEligibility added in v0.3.0

func (e *EvalEligibility) SetJobEligibility(eligible bool, class string)

SetJobEligibility sets the eligibility status of the job for the computed node class.

func (*EvalEligibility) SetTaskGroupEligibility added in v0.3.0

func (e *EvalEligibility) SetTaskGroupEligibility(eligible bool, tg, class string)

SetTaskGroupEligibility sets the eligibility status of the task group for the computed node class.

func (*EvalEligibility) TaskGroupStatus added in v0.3.0

func (e *EvalEligibility) TaskGroupStatus(tg, class string) ComputedClassFeasibility

TaskGroupStatus returns the eligibility status of the task group.

type Factory

type Factory func(*log.Logger, State, Planner) Scheduler

Factory is used to instantiate a new Scheduler

type FeasibilityChecker added in v0.3.0

type FeasibilityChecker interface {
	Feasible(*structs.Node) bool
}

FeasibilityChecker is used to check if a single node meets feasibility constraints.

type FeasibilityWrapper added in v0.3.0

type FeasibilityWrapper struct {
	// contains filtered or unexported fields
}

FeasibilityWrapper is a FeasibleIterator which wraps both job and task group FeasibilityCheckers in which feasibility checking can be skipped if the computed node class has previously been marked as eligible or ineligible.

func NewFeasibilityWrapper added in v0.3.0

func NewFeasibilityWrapper(ctx Context, source FeasibleIterator,
	jobCheckers, tgCheckers []FeasibilityChecker) *FeasibilityWrapper

NewFeasibilityWrapper returns a FeasibleIterator based on the passed source and FeasibilityCheckers.

func (*FeasibilityWrapper) Next added in v0.3.0

func (w *FeasibilityWrapper) Next() *structs.Node

Next returns an eligible node, only running the FeasibilityCheckers as needed based on the sources computed node class.

func (*FeasibilityWrapper) Reset added in v0.3.0

func (w *FeasibilityWrapper) Reset()

func (*FeasibilityWrapper) SetTaskGroup added in v0.3.0

func (w *FeasibilityWrapper) SetTaskGroup(tg string)

type FeasibleIterator

type FeasibleIterator interface {
	// Next yields a feasible node or nil if exhausted
	Next() *structs.Node

	// Reset is invoked when an allocation has been placed
	// to reset any stale state.
	Reset()
}

FeasibleIterator is used to iteratively yield nodes that match feasibility constraints. The iterators may manage some state for performance optimizations.

type FeasibleRankIterator

type FeasibleRankIterator struct {
	// contains filtered or unexported fields
}

FeasibleRankIterator is used to consume from a FeasibleIterator and return an unranked node with base ranking.

func NewFeasibleRankIterator

func NewFeasibleRankIterator(ctx Context, source FeasibleIterator) *FeasibleRankIterator

NewFeasibleRankIterator is used to return a new FeasibleRankIterator from a FeasibleIterator source.

func (*FeasibleRankIterator) Next

func (iter *FeasibleRankIterator) Next() *RankedNode

func (*FeasibleRankIterator) Reset

func (iter *FeasibleRankIterator) Reset()

type GenericScheduler

type GenericScheduler struct {
	// contains filtered or unexported fields
}

GenericScheduler is used for 'service' and 'batch' type jobs. This scheduler is designed for long-lived services, and as such spends more time attemping to make a high quality placement. This is the primary scheduler for most workloads. It also supports a 'batch' mode to optimize for fast decision making at the cost of quality.

func (*GenericScheduler) Process

func (s *GenericScheduler) Process(eval *structs.Evaluation) error

Process is used to handle a single evaluation

type GenericStack

type GenericStack struct {
	// contains filtered or unexported fields
}

GenericStack is the Stack used for the Generic scheduler. It is designed to make better placement decisions at the cost of performance.

func NewGenericStack

func NewGenericStack(batch bool, ctx Context) *GenericStack

NewGenericStack constructs a stack used for selecting service placements

func (*GenericStack) Select

func (*GenericStack) SetJob

func (s *GenericStack) SetJob(job *structs.Job)

func (*GenericStack) SetNodes

func (s *GenericStack) SetNodes(baseNodes []*structs.Node)

type JobAntiAffinityIterator

type JobAntiAffinityIterator struct {
	// contains filtered or unexported fields
}

JobAntiAffinityIterator is used to apply an anti-affinity to allocating along side other allocations from this job. This is used to help distribute load across the cluster.

func NewJobAntiAffinityIterator

func NewJobAntiAffinityIterator(ctx Context, source RankIterator, penalty float64, jobID string) *JobAntiAffinityIterator

NewJobAntiAffinityIterator is used to create a JobAntiAffinityIterator that applies the given penalty for co-placement with allocs from this job.

func (*JobAntiAffinityIterator) Next

func (iter *JobAntiAffinityIterator) Next() *RankedNode

func (*JobAntiAffinityIterator) Reset

func (iter *JobAntiAffinityIterator) Reset()

func (*JobAntiAffinityIterator) SetJob

func (iter *JobAntiAffinityIterator) SetJob(jobID string)

type LimitIterator

type LimitIterator struct {
	// contains filtered or unexported fields
}

LimitIterator is a RankIterator used to limit the number of options that are returned before we artifically end the stream.

func NewLimitIterator

func NewLimitIterator(ctx Context, source RankIterator, limit int) *LimitIterator

NewLimitIterator is returns a LimitIterator with a fixed limit of returned options

func (*LimitIterator) Next

func (iter *LimitIterator) Next() *RankedNode

func (*LimitIterator) Reset

func (iter *LimitIterator) Reset()

func (*LimitIterator) SetLimit

func (iter *LimitIterator) SetLimit(limit int)

type MaxScoreIterator

type MaxScoreIterator struct {
	// contains filtered or unexported fields
}

MaxScoreIterator is a RankIterator used to return only a single result of the item with the highest score. This iterator will consume all of the possible inputs and only returns the highest ranking result.

func NewMaxScoreIterator

func NewMaxScoreIterator(ctx Context, source RankIterator) *MaxScoreIterator

MaxScoreIterator returns a MaxScoreIterator over the given source

func (*MaxScoreIterator) Next

func (iter *MaxScoreIterator) Next() *RankedNode

func (*MaxScoreIterator) Reset

func (iter *MaxScoreIterator) Reset()

type Planner

type Planner interface {
	// SubmitPlan is used to submit a plan for consideration.
	// This will return a PlanResult or an error. It is possible
	// that this will result in a state refresh as well.
	SubmitPlan(*structs.Plan) (*structs.PlanResult, State, error)

	// UpdateEval is used to update an evaluation. This should update
	// a copy of the input evaluation since that should be immutable.
	UpdateEval(*structs.Evaluation) error

	// CreateEval is used to create an evaluation. This should set the
	// PreviousEval to that of the current evaluation.
	CreateEval(*structs.Evaluation) error
}

Planner interface is used to submit a task allocation plan.

type ProposedAllocConstraintIterator added in v0.2.0

type ProposedAllocConstraintIterator struct {
	// contains filtered or unexported fields
}

ProposedAllocConstraintIterator is a FeasibleIterator which returns nodes that match constraints that are not static such as Node attributes but are effected by proposed alloc placements. Examples are distinct_hosts and tenancy constraints. This is used to filter on job and task group constraints.

func NewProposedAllocConstraintIterator added in v0.2.0

func NewProposedAllocConstraintIterator(ctx Context, source FeasibleIterator) *ProposedAllocConstraintIterator

NewProposedAllocConstraintIterator creates a ProposedAllocConstraintIterator from a source.

func (*ProposedAllocConstraintIterator) Next added in v0.2.0

func (*ProposedAllocConstraintIterator) Reset added in v0.2.0

func (iter *ProposedAllocConstraintIterator) Reset()

func (*ProposedAllocConstraintIterator) SetJob added in v0.2.0

func (iter *ProposedAllocConstraintIterator) SetJob(job *structs.Job)

func (*ProposedAllocConstraintIterator) SetTaskGroup added in v0.2.0

func (iter *ProposedAllocConstraintIterator) SetTaskGroup(tg *structs.TaskGroup)

type RankIterator

type RankIterator interface {
	// Next yields a ranked option or nil if exhausted
	Next() *RankedNode

	// Reset is invoked when an allocation has been placed
	// to reset any stale state.
	Reset()
}

RankFeasibleIterator is used to iteratively yield nodes along with ranking metadata. The iterators may manage some state for performance optimizations.

type RankedNode

type RankedNode struct {
	Node          *structs.Node
	Score         float64
	TaskResources map[string]*structs.Resources

	// Allocs is used to cache the proposed allocations on the
	// node. This can be shared between iterators that require it.
	Proposed []*structs.Allocation
}

Rank is used to provide a score and various ranking metadata along with a node when iterating. This state can be modified as various rank methods are applied.

func (*RankedNode) GoString

func (r *RankedNode) GoString() string

func (*RankedNode) ProposedAllocs

func (r *RankedNode) ProposedAllocs(ctx Context) ([]*structs.Allocation, error)

func (*RankedNode) SetTaskResources

func (r *RankedNode) SetTaskResources(task *structs.Task,
	resource *structs.Resources)

type Scheduler

type Scheduler interface {
	// Process is used to handle a new evaluation. The scheduler is free to
	// apply any logic necessary to make the task placements. The state and
	// planner will be provided prior to any invocations of process.
	Process(*structs.Evaluation) error
}

Scheduler is the top level instance for a scheduler. A scheduler is meant to only encapsulate business logic, pushing the various plumbing into Nomad itself. They are invoked to process a single evaluation at a time. The evaluation may result in task allocations which are computed optimistically, as there are many concurrent evaluations being processed. The task allocations are submitted as a plan, and the current leader will coordinate the commmits to prevent oversubscription or improper allocations based on stale state.

func NewBatchScheduler

func NewBatchScheduler(logger *log.Logger, state State, planner Planner) Scheduler

NewBatchScheduler is a factory function to instantiate a new batch scheduler

func NewScheduler

func NewScheduler(name string, logger *log.Logger, state State, planner Planner) (Scheduler, error)

NewScheduler is used to instantiate and return a new scheduler given the scheduler name, initial state, and planner.

func NewServiceScheduler

func NewServiceScheduler(logger *log.Logger, state State, planner Planner) Scheduler

NewServiceScheduler is a factory function to instantiate a new service scheduler

func NewSystemScheduler added in v0.2.0

func NewSystemScheduler(logger *log.Logger, state State, planner Planner) Scheduler

NewSystemScheduler is a factory function to instantiate a new system scheduler.

type SetStatusError

type SetStatusError struct {
	Err        error
	EvalStatus string
}

SetStatusError is used to set the status of the evaluation to the given error

func (*SetStatusError) Error

func (s *SetStatusError) Error() string

type Stack

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)

	// Select is used to select a node for the task group
	Select(tg *structs.TaskGroup) (*RankedNode, *structs.Resources)
}

Stack is a chained collection of iterators. The stack is used to make placement decisions. Different schedulers may customize the stack they use to vary the way placements are made.

type State

type State interface {
	// Nodes returns an iterator over all the nodes.
	// The type of each result is *structs.Node
	Nodes() (memdb.ResultIterator, error)

	// AllocsByJob returns the allocations by JobID
	AllocsByJob(jobID string) ([]*structs.Allocation, error)

	// AllocsByNode returns all the allocations by node
	AllocsByNode(node string) ([]*structs.Allocation, error)

	// AllocsByNodeTerminal returns all the allocations by node filtering by terminal status
	AllocsByNodeTerminal(node string, terminal bool) ([]*structs.Allocation, error)

	// GetNodeByID is used to lookup a node by ID
	NodeByID(nodeID string) (*structs.Node, error)

	// GetJobByID is used to lookup a job by ID
	JobByID(id string) (*structs.Job, error)
}

State is an immutable view of the global state. This allows schedulers to make intelligent decisions based on allocations of other schedulers and to enforce complex constraints that require more information than is available to a local state scheduler.

type StaticIterator

type StaticIterator struct {
	// contains filtered or unexported fields
}

StaticIterator is a FeasibleIterator which returns nodes in a static order. This is used at the base of the iterator chain only for testing due to deterministic behavior.

func NewRandomIterator

func NewRandomIterator(ctx Context, nodes []*structs.Node) *StaticIterator

NewRandomIterator constructs a static iterator from a list of nodes after applying the Fisher-Yates algorithm for a random shuffle. This is applied in-place

func NewStaticIterator

func NewStaticIterator(ctx Context, nodes []*structs.Node) *StaticIterator

NewStaticIterator constructs a random iterator from a list of nodes

func (*StaticIterator) Next

func (iter *StaticIterator) Next() *structs.Node

func (*StaticIterator) Reset

func (iter *StaticIterator) Reset()

func (*StaticIterator) SetNodes

func (iter *StaticIterator) SetNodes(nodes []*structs.Node)

type StaticRankIterator

type StaticRankIterator struct {
	// contains filtered or unexported fields
}

StaticRankIterator is a RankIterator that returns a static set of results. This is largely only useful for testing.

func NewStaticRankIterator

func NewStaticRankIterator(ctx Context, nodes []*RankedNode) *StaticRankIterator

NewStaticRankIterator returns a new static rank iterator over the given nodes

func (*StaticRankIterator) Next

func (iter *StaticRankIterator) Next() *RankedNode

func (*StaticRankIterator) Reset

func (iter *StaticRankIterator) Reset()

type SystemScheduler added in v0.2.0

type SystemScheduler struct {
	// contains filtered or unexported fields
}

SystemScheduler is used for 'system' jobs. This scheduler is designed for services that should be run on every client.

func (*SystemScheduler) Process added in v0.2.0

func (s *SystemScheduler) Process(eval *structs.Evaluation) error

Process is used to handle a single evaluation.

type SystemStack added in v0.2.0

type SystemStack struct {
	// contains filtered or unexported fields
}

SystemStack is the Stack used for the System scheduler. It is designed to attempt to make placements on all nodes.

func NewSystemStack added in v0.2.0

func NewSystemStack(ctx Context) *SystemStack

NewSystemStack constructs a stack used for selecting service placements

func (*SystemStack) Select added in v0.2.0

func (*SystemStack) SetJob added in v0.2.0

func (s *SystemStack) SetJob(job *structs.Job)

func (*SystemStack) SetNodes added in v0.2.0

func (s *SystemStack) SetNodes(baseNodes []*structs.Node)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL