Documentation ¶
Index ¶
- Variables
- type BinPackIterator
- type ConstraintIterator
- type Context
- type DriverIterator
- type EvalCache
- type EvalContext
- func (e *EvalContext) Logger() *log.Logger
- func (e *EvalContext) Metrics() *structs.AllocMetric
- func (e *EvalContext) Plan() *structs.Plan
- func (e *EvalContext) ProposedAllocs(nodeID string) ([]*structs.Allocation, error)
- func (e *EvalContext) Reset()
- func (e *EvalContext) SetState(s State)
- func (e *EvalContext) State() State
- type Factory
- type FeasibleIterator
- type FeasibleRankIterator
- type GenericScheduler
- type GenericStack
- type JobAntiAffinityIterator
- type LimitIterator
- type MaxScoreIterator
- type Planner
- type ProposedAllocConstraintIterator
- type RankIterator
- type RankedNode
- type Scheduler
- func NewBatchScheduler(logger *log.Logger, state State, planner Planner) Scheduler
- func NewScheduler(name string, logger *log.Logger, state State, planner Planner) (Scheduler, error)
- func NewServiceScheduler(logger *log.Logger, state State, planner Planner) Scheduler
- func NewSystemScheduler(logger *log.Logger, state State, planner Planner) Scheduler
- type SetStatusError
- type Stack
- type State
- type StaticIterator
- type StaticRankIterator
- type SystemScheduler
- type SystemStack
Constants ¶
This section is empty.
Variables ¶
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 ConstraintIterator ¶
type ConstraintIterator struct {
// contains filtered or unexported fields
}
ConstraintIterator is a FeasibleIterator which returns nodes that match a given set of constraints. This is used to filter on job, task group, and task constraints.
func NewConstraintIterator ¶
func NewConstraintIterator(ctx Context, source FeasibleIterator, constraints []*structs.Constraint) *ConstraintIterator
NewConstraintIterator creates a ConstraintIterator from a source and set of constraints
func (*ConstraintIterator) Next ¶
func (iter *ConstraintIterator) Next() *structs.Node
func (*ConstraintIterator) Reset ¶
func (iter *ConstraintIterator) Reset()
func (*ConstraintIterator) SetConstraints ¶
func (iter *ConstraintIterator) SetConstraints(c []*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 }
Context is used to track contextual information used for placement
type DriverIterator ¶
type DriverIterator struct {
// contains filtered or unexported fields
}
DriverIterator is a FeasibleIterator which returns nodes that have the drivers necessary to scheduler a task group.
func NewDriverIterator ¶
func NewDriverIterator(ctx Context, source FeasibleIterator, drivers map[string]struct{}) *DriverIterator
NewDriverIterator creates a DriverIterator from a source and set of drivers
func (*DriverIterator) Next ¶
func (iter *DriverIterator) Next() *structs.Node
func (*DriverIterator) Reset ¶
func (iter *DriverIterator) Reset()
func (*DriverIterator) SetDrivers ¶
func (iter *DriverIterator) 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
type EvalContext ¶
type EvalContext struct { EvalCache // contains filtered or unexported fields }
EvalContext is a Context used during an Evaluation
func NewEvalContext ¶
NewEvalContext constructs a new EvalContext
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 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 (s *GenericStack) Select(tg *structs.TaskGroup) (*RankedNode, *structs.Resources)
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 (iter *ProposedAllocConstraintIterator) Next() *structs.Node
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 ¶
NewBatchScheduler is a factory function to instantiate a new batch scheduler
func NewScheduler ¶
NewScheduler is used to instantiate and return a new scheduler given the scheduler name, initial state, and planner.
func NewServiceScheduler ¶
NewServiceScheduler is a factory function to instantiate a new service scheduler
type SetStatusError ¶
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) // 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 (s *SystemStack) Select(tg *structs.TaskGroup) (*RankedNode, *structs.Resources)
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)