core

package
v2.3.20181123+incompat... Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmptyScore    int   = 0x7FFFFFFFFFFFFFFF
	BaseScore     int   = 10000
	EmptyCapacity int64 = -1
	MaxCapacity   int64 = 0x7FFFFFFFFFFFFFFF
)
View Source
const (
	NoResourceAvailableMsg = "No resource are avaliable that match all of the following predicates:"
)
View Source
const (
	PriorityStep int = 100
)

Variables

View Source
var (
	EmptyScores     = make(map[string]int)
	EmptyCapacities = make(map[string]Counter)
)

Functions

func GetCapacities

func GetCapacities(u *Unit, id string) (res map[string]int64)

func GetScore

func GetScore(u *Unit, id string, details bool) string

func ReservedSub

func ReservedSub(key string, value value_t, reserved value_t) value_t

func XGetCalculator

func XGetCalculator(c Candidater, key string, kind Kind) value_t

Types

type Candidater

type Candidater interface {
	// IndexKey return candidate cache item's ident, usually host ID
	IndexKey() string
	// Get return candidate cache item's value by key
	Get(key string) interface{}
	// XGet return candidate cache item's value by key and kind
	XGet(key string, kind Kind) interface{}
	Type() int

	GetAggregates() []*models.Aggregate
	GetHostAggregates() []*models.Aggregate

	GetSchedDesc() *jsonutils.JSONDict
}

Candidater replace host Candidate resource info

type Capacity

type Capacity struct {
	Values   map[string]Counter
	MinValue int64
}

type Counter

type Counter interface {
	GetCount() int64
}

type CounterManager

type CounterManager struct {
	Counters map[string]Counter
	// contains filtered or unexported fields
}

func NewCounterManager

func NewCounterManager() *CounterManager

func (*CounterManager) Get

func (m *CounterManager) Get(key string) Counter

func (*CounterManager) GetOrCreate

func (m *CounterManager) GetOrCreate(key string, creator func() Counter) Counter

type Counters

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

func NewCounters

func NewCounters() *Counters

func (*Counters) Add

func (c *Counters) Add(cnt Counter)

func (*Counters) GetCount

func (c *Counters) GetCount() int64

type DefaultResAlgorithm

type DefaultResAlgorithm struct{}

func (*DefaultResAlgorithm) Sub

func (al *DefaultResAlgorithm) Sub(sum value_t, reserved value_t) value_t

func (*DefaultResAlgorithm) Sum

func (al *DefaultResAlgorithm) Sum(values []value_t) value_t

type FailedCandidate

type FailedCandidate struct {
	Stage     string
	Candidate Candidater
	Reasons   []PredicateFailureReason
}

type FailedCandidates

type FailedCandidates struct {
	Candidates []FailedCandidate
}

type FailedPredicateMap

type FailedPredicateMap map[string][]PredicateFailureReason

type FitError

type FitError struct {
	Unit               *Unit
	FailedCandidateMap map[string]*FailedCandidates
}

func (*FitError) Error

func (fe *FitError) Error() string

Error returns detailed information of why the guest failed to fit on each host

type FitPredicate

type FitPredicate interface {
	// Get filter's name
	Name() string
	Clone() FitPredicate
	PreExecute(*Unit, []Candidater) (bool, error)
	Execute(*Unit, Candidater) (bool, []PredicateFailureReason, error)
}

type GenericScheduler

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

func NewGenericScheduler

func NewGenericScheduler(s Scheduler) (*GenericScheduler, error)

func (*GenericScheduler) Schedule

func (g *GenericScheduler) Schedule(unit *Unit, candidates []Candidater) ([]*SchedResultItem, error)

type HostPriority

type HostPriority struct {
	// Name of the host
	Host string
	// Score associated with the host
	Score int
	// Resource wraps Candidate host info
	Candidate Candidater
}

HostPriority represents the priority of scheduling to particular host, higher priority is better.

func EqualPriority

func EqualPriority(_ *Unit, candidate Candidater) (HostPriority, error)

EqualPriority is a prioritizer function that gives an equal weight of one to all candidates

type HostPriorityList

type HostPriorityList []HostPriority

func PrioritizeCandidates

func PrioritizeCandidates(
	unit *Unit,
	candidates []Candidater,
	priorities []PriorityConfig,
) (HostPriorityList, error)

PrioritizeCandidates by running the individual priority functions in parallel. Each priority function is expected to set a score of 0-10 0 is the lowest priority score (least preffered node) and 10 is the highest / Each priority function can also have its own weight The resource scores returned by priority function are multiplied by the weights to get weighted scores All scores are finally combined (added) to get the total weighted scores of all resources

func (HostPriorityList) Len

func (h HostPriorityList) Len() int

func (HostPriorityList) Less

func (h HostPriorityList) Less(i, j int) bool

func (HostPriorityList) Swap

func (h HostPriorityList) Swap(i, j int)

type Kind

type Kind int
const (
	KindFree Kind = iota
	KindRaw
	KindReserved
)

type MinCounters

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

func NewMinCounters

func NewMinCounters() *MinCounters

func (*MinCounters) Add

func (c *MinCounters) Add(counter Counter)

func (*MinCounters) GetCount

func (c *MinCounters) GetCount() int64

type MultiCounter

type MultiCounter interface {
	Counter
	Add(counter Counter)
}

type NoResourceError

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

func (*NoResourceError) Error

func (e *NoResourceError) Error() string

type NormalCounter

type NormalCounter struct {
	Value int64
}

func NewNormalCounter

func NewNormalCounter(value int64) *NormalCounter

func (*NormalCounter) GetCount

func (c *NormalCounter) GetCount() int64

type PredicateFailureReason

type PredicateFailureReason interface {
	GetReason() string
}

type Priority

type Priority interface {
	Name() string
	Clone() Priority
	Map(*Unit, Candidater) (HostPriority, error)
	Reduce(*Unit, []Candidater, HostPriorityList) error
	PreExecute(*Unit, []Candidater) (bool, []PredicateFailureReason, error)
}

type PriorityConfig

type PriorityConfig struct {
	Name   string
	Pre    PriorityPreFunction
	Map    PriorityMapFunction
	Reduce PriorityReduceFunction
	Weight int
}

type PriorityMapFunction

type PriorityMapFunction func(*Unit, Candidater) (HostPriority, error)

PriorityMapFunction is a function that computes per-resource results for a given resource.

type PriorityPreFunction

type PriorityPreFunction func(*Unit, []Candidater) (bool, []PredicateFailureReason, error)

type PriorityReduceFunction

type PriorityReduceFunction func(*Unit, []Candidater, HostPriorityList) error

PriorityReduceFunction is a function that aggregated per-resource results and computes final scores for all hosts.

type ResourceAlgorithm

type ResourceAlgorithm interface {
	Sum(values []value_t) value_t
	Sub(sum value_t, reserved value_t) value_t
}

func GetResourceAlgorithm

func GetResourceAlgorithm(res_name string) ResourceAlgorithm

type SchedContextDataItem

type SchedContextDataItem struct {
	Networks *sync.Map
	Data     map[string]interface{}
}

type SchedLog

type SchedLog struct {
	Candidate string
	Action    string
	Message   string
}

func NewSchedLog

func NewSchedLog(candidate, action, message string) SchedLog

func (*SchedLog) String

func (log *SchedLog) String() string

type SchedLogList

type SchedLogList []SchedLog

func (SchedLogList) Len

func (logList SchedLogList) Len() int

func (SchedLogList) Less

func (logList SchedLogList) Less(i, j int) bool

func (SchedLogList) Swap

func (logList SchedLogList) Swap(i, j int)

type SchedLogManager

type SchedLogManager struct {
	Logs SchedLogList
	// contains filtered or unexported fields
}

func NewSchedLogManager

func NewSchedLogManager() *SchedLogManager

func (*SchedLogManager) Append

func (m *SchedLogManager) Append(candidate, action, message string)

func (*SchedLogManager) Appends

func (m *SchedLogManager) Appends(logs []SchedLog)

func (*SchedLogManager) Read

func (m *SchedLogManager) Read() []string

type SchedResultItem

type SchedResultItem struct {
	ID       string                 `json:"id"`
	Name     string                 `json:"name"`
	Count    int64                  `json:"count"`
	Data     map[string]interface{} `json:"data"`
	Capacity int64                  `json:"capacity"`
	Score    int                    `json:"score"`

	CapacityDetails map[string]int64 `json:"capacity_details"`
	ScoreDetails    map[string]int   `json:"score_details"`
}

type SchedResultItemList

type SchedResultItemList struct {
	Unit *Unit
	Data []*SchedResultItem
}

func (SchedResultItemList) Len

func (its SchedResultItemList) Len() int

func (SchedResultItemList) Less

func (its SchedResultItemList) Less(i, j int) bool

type Scheduler

type Scheduler interface {
	BeforePredicate() error
	Predicates() (map[string]FitPredicate, error)
	PriorityConfigs() ([]PriorityConfig, error)

	// mark already selected candidates dirty that
	// can't be use again until cleanup them
	DirtySelectedCandidates([]*SelectedCandidate)
}

type Score

type Score struct {
	Values map[string]int
	Sum    int
}

type SelectPlugin

type SelectPlugin interface {
	OnSelect(*Unit, Candidater) bool
	OnSelectEnd(u *Unit, c Candidater, count int64)
}

type SelectedCandidate

type SelectedCandidate struct {
	Count     int64
	Candidate Candidater
}

func SelectHosts

func SelectHosts(unit *Unit, priorityList HostPriorityList) ([]*SelectedCandidate, error)

SelectHosts takes a prioritized list of candidates and then picks a group of hosts

func (SelectedCandidate) Index

func (s SelectedCandidate) Index() (string, error)

type SharedResourceManager

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

func NewSharedResourceManager

func NewSharedResourceManager() *SharedResourceManager

func (*SharedResourceManager) Add

func (m *SharedResourceManager) Add(resourceKey string, capacity Counter)

type Unit

type Unit struct {
	SchedInfo             *api.SchedInfo
	CapacityMap           map[string]*Capacity
	ScoreMap              map[string]Score
	DataMap               map[string]*SchedContextDataItem
	SharedResourceManager *SharedResourceManager
	CounterManager        *CounterManager

	FailedCandidateMap map[string]*FailedCandidates

	SchedulerManager interface{}

	LogManager *SchedLogManager
	// contains filtered or unexported fields
}

Unit wraps sched input info and other log and record manager

func NewScheduleUnit

func NewScheduleUnit(info *api.SchedInfo, schedManager interface{}) *Unit

func (*Unit) AllSelectPlugins

func (u *Unit) AllSelectPlugins() []SelectPlugin

func (*Unit) AppendFailedCandidates

func (u *Unit) AppendFailedCandidates(fcs []FailedCandidate)

func (*Unit) AppendSelectPlugin

func (u *Unit) AppendSelectPlugin(p SelectPlugin)

func (*Unit) GetCapacities

func (u *Unit) GetCapacities(id string) map[string]Counter

func (*Unit) GetCapacity

func (u *Unit) GetCapacity(id string) int64

func (*Unit) GetCapacityOfName

func (u *Unit) GetCapacityOfName(id string, name string) int64

func (*Unit) GetFiltedData

func (u *Unit) GetFiltedData(id string, count int64) map[string]interface{}

func (*Unit) GetScore

func (u *Unit) GetScore(id string) int

func (*Unit) GetScores

func (u *Unit) GetScores(id string) map[string]int

func (*Unit) IncreaseScore

func (u *Unit) IncreaseScore(id string, name string, increase int) error

func (*Unit) Info

func (u *Unit) Info() string

func (*Unit) IsPublicCloudProvider

func (u *Unit) IsPublicCloudProvider() bool

func (*Unit) SchedData

func (u *Unit) SchedData() *api.SchedData

func (*Unit) SessionID

func (u *Unit) SessionID() string

func (*Unit) SetCapacity

func (u *Unit) SetCapacity(id string, name string, capacity Counter) error

func (*Unit) SetFiltedData

func (u *Unit) SetFiltedData(id string, name string, data interface{}) error

func (*Unit) SetScore

func (u *Unit) SetScore(id, name string, score int) error

func (*Unit) SkipDirtyMarkHost

func (u *Unit) SkipDirtyMarkHost() bool

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap

func (w *WaitGroupWrapper) Wrap(cb func())

Jump to

Keyboard shortcuts

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