core

package
v0.0.0-...-6410feb Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	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 = 1
)

Variables

View Source
var (
	EmptyCapacities          = make(map[string]Counter)
	EmptySelectPriorityValue = SSelectPriorityValue(0)
)
View Source
var ErrInstanceGroupNotFound = errors.Error("InstanceGroupNotFound")

Functions

func GetCapacities

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

func ReservedSub

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

Types

type AllocatedResource

type AllocatedResource struct {
	Disks []*schedapi.CandidateDiskV2 `json:"disks"`
	Nets  []*schedapi.CandidateNet    `json:"nets"`
}

func NewAllocatedResource

func NewAllocatedResource() *AllocatedResource

type CandidatePropertyGetter

type CandidatePropertyGetter interface {
	Id() string
	Name() string
	Zone() *computemodels.SZone
	Host() *computemodels.SHost
	Cloudprovider() *computemodels.SCloudprovider
	IsPublic() bool
	DomainId() string
	PublicScope() string
	SharedDomains() []string
	Region() *computemodels.SCloudregion
	HostType() string
	Sku(string) *sku.ServerSku
	Storages() []*api.CandidateStorage
	Networks() []*api.CandidateNetwork
	OvnCapable() bool
	Status() string
	HostStatus() string
	Enabled() bool
	IsEmpty() bool
	ResourceType() string
	NetInterfaces() map[string][]computemodels.SNetInterface
	ProjectGuests() map[string]int64
	CreatingGuestCount() int

	CPUArch() string
	IsArmHost() bool
	RunningCPUCount() int64
	TotalCPUCount(useRsvd bool) int64
	FreeCPUCount(useRsvd bool) int64

	RunningMemorySize() int64
	TotalMemorySize(useRsvd bool) int64
	FreeMemorySize(useRsvd bool) int64
	GetFreeCpuNuma() []*schedapi.SFreeNumaCpuMem
	NumaAllocateEnabled() bool

	StorageInfo() []*baremetal.BaremetalStorage
	GetFreeStorageSizeOfType(storageType string, mediumType string, useRsvd bool, reqMaxSize int64) (int64, int64, error)

	GetFreePort(netId string) int

	InstanceGroups() map[string]*api.CandidateGroup
	GetFreeGroupCount(groupId string) (int, error)

	GetAllClassMetadata() (map[string]string, error)

	GetIpmiInfo() types.SIPMIInfo

	GetNics() []*types.SNic

	GetQuotaKeys(s *api.SchedInfo) computemodels.SComputeResourceKeys

	GetPendingUsage() *schedmodels.SPendingUsage

	// isloatedDevices
	UnusedIsolatedDevices() []*IsolatedDeviceDesc
	UnusedIsolatedDevicesByType(devType string) []*IsolatedDeviceDesc
	UnusedIsolatedDevicesByVendorModel(vendorModel string) []*IsolatedDeviceDesc
	UnusedIsolatedDevicesByModel(model string) []*IsolatedDeviceDesc
	UnusedIsolatedDevicesByModelAndWire(model, wire string) []*IsolatedDeviceDesc
	UnusedIsolatedDevicesByDevicePath(devPath string) []*IsolatedDeviceDesc
	GetIsolatedDevice(devID string) *IsolatedDeviceDesc
	UnusedGpuDevices() []*IsolatedDeviceDesc
	GetIsolatedDevices() []*IsolatedDeviceDesc

	db.IResource
}

type Candidater

type Candidater interface {
	Getter() CandidatePropertyGetter
	// IndexKey return candidate cache item's ident, usually host ID
	IndexKey() string
	Type() int

	GetSchedDesc() *jsonutils.JSONDict
	GetGuestCount() int64
	GetResourceType() string
	AllocCpuNumaPin(vcpuCount, memSizeKB int) []schedapi.SCpuNumaPin
	AllocCpuNumaPinWithNodeCount(vcpuCount, memSizeKB, nodeCount int) []schedapi.SCpuNumaPin
}

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(context.Context, *Unit, []Candidater) (bool, error)
	Execute(context.Context, *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(ctx context.Context, unit *Unit, candidates []Candidater, helper IResultHelper) (*ScheduleResult, error)

type HostPriority

type HostPriority struct {
	// Name of the host
	Host string
	// Score associated with the host
	Score Score
	// 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 IResultHelper

type IResultHelper interface {
	ResultHelp(result *SchedResultItemList, schedInfo *api.SchedInfo) *ScheduleResult
}

type IsolatedDeviceDesc

type IsolatedDeviceDesc struct {
	ID             string
	GuestID        string
	HostID         string
	DevType        string
	Model          string
	Addr           string
	VendorDeviceID string
	WireId         string
	DevicePath     string
}

func (*IsolatedDeviceDesc) GetVendorModel

func (i *IsolatedDeviceDesc) GetVendorModel() *VendorModel

func (*IsolatedDeviceDesc) VendorID

func (i *IsolatedDeviceDesc) VendorID() string

type Kind

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

type LogMessage

type LogMessage struct {
	Type string
	Info string
}

type LogMessages

type LogMessages []*LogMessage

func (LogMessages) String

func (ms LogMessages) String() string

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 PredicateFailureError

type PredicateFailureError interface {
	GetReason() string
}

type PredicateFailureReason

type PredicateFailureReason interface {
	PredicateFailureError
	GetType() 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)

	// Score intervals
	ScoreIntervals() score.Intervals
}

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 SResultHelperFunc

type SResultHelperFunc func(result *SchedResultItemList, schedInfo *api.SchedInfo) *ScheduleResult

ResultHelperFunc type is an adapter to allwo the use of ordinary functions as a ResultHelper. If f is a function with the appropriate signature, ResultHelperFunc(f) is a ResultHelper that calls f.

func (SResultHelperFunc) ResultHelp

func (r SResultHelperFunc) ResultHelp(result *SchedResultItemList, schedInfo *api.SchedInfo) *ScheduleResult

type SSelectPriority

type SSelectPriority map[string]SSelectPriorityValue

func NewSSelctPriority

func NewSSelctPriority() SSelectPriority

func (SSelectPriority) Value

func (s SSelectPriority) Value() (val SSelectPriorityValue)

type SSelectPriorityUpdater

type SSelectPriorityUpdater func(u *Unit, origin SSelectPriorityValue, hostID string) SSelectPriorityValue

SSelectPriorityUpdater will call to update the specified host after each round of selection

type SSelectPriorityValue

type SSelectPriorityValue int

func (SSelectPriorityValue) IsEmpty

func (s SSelectPriorityValue) IsEmpty() bool

func (SSelectPriorityValue) Less

func (SSelectPriorityValue) Sub

func (SSelectPriorityValue) SubOne

type SchedContextDataItem

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

type SchedLog

type SchedLog struct {
	Candidate string
	Action    string
	Messages  LogMessages
	IsFailed  bool
}

func NewSchedLog

func NewSchedLog(candidate, action string, messages LogMessages, isFailed bool) SchedLog

func (*SchedLog) String

func (log *SchedLog) String() string

type SchedLogList

type SchedLogList []SchedLog

func (SchedLogList) Get

func (logList SchedLogList) Get(index string) *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) Appends

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

func (*SchedLogManager) FailedLogs

func (m *SchedLogManager) FailedLogs() SchedLogList

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    Score                  `json:"score"`

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

	Candidater Candidater `json:"-"`

	*AllocatedResource

	SchedData *api.SchedInfo
}

func (*SchedResultItem) ToCandidateResource

func (item *SchedResultItem) ToCandidateResource(storageUsed *StorageUsed) *schedapi.CandidateResource

type SchedResultItemList

type SchedResultItemList struct {
	Unit *Unit
	Data SchedResultItems
}

func (SchedResultItemList) String

func (its SchedResultItemList) String() string

type SchedResultItems

type SchedResultItems []*SchedResultItem

func (SchedResultItems) Len

func (its SchedResultItems) Len() int

func (SchedResultItems) Less

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

func (SchedResultItems) Swap

func (its SchedResultItems) Swap(i, j int)

type ScheduleResult

type ScheduleResult struct {
	// Result is sync schedule result
	Result *schedapi.ScheduleOutput
	// ForecastResult is forecast schedule result
	ForecastResult *api.SchedForecastResult
	// TestResult is test schedule result
	TestResult interface{}
}

func ResultHelp

func ResultHelp(result *SchedResultItemList, schedInfo *api.SchedInfo) *ScheduleResult

func ResultHelpForForcast

func ResultHelpForForcast(result *SchedResultItemList, _ *api.SchedInfo) *ScheduleResult

func ResultHelpForTest

func ResultHelpForTest(result *SchedResultItemList, schedInfo *api.SchedInfo) *ScheduleResult

type Scheduler

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

type Score

type Score struct {
	*score.ScoreBucket
}

type ScoreValue

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

type SelectPlugin

type SelectPlugin interface {
	Name() string
	OnPriorityEnd(*Unit, Candidater)
	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) GetCount

func (s SelectedCandidate) GetCount() uint64

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 StorageUsed

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

func NewStorageUsed

func NewStorageUsed() *StorageUsed

func (*StorageUsed) Add

func (s *StorageUsed) Add(storageId string, used int64)

func (*StorageUsed) Get

func (s *StorageUsed) Get(storageId string) int64

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

	AllocatedResources map[string]*AllocatedResource

	SelectPriorityMap        map[string]SSelectPriority
	SelectPriorityUpdaterMap map[string]SSelectPriorityUpdater
	SelectPriorityLock       sync.Mutex
	// 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) GetAllocatedResource

func (u *Unit) GetAllocatedResource(candidateId string) *AllocatedResource

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

func (u *Unit) GetHypervisor() string

func (*Unit) GetHypervisorDriver

func (u *Unit) GetHypervisorDriver() models.IGuestDriver

func (*Unit) GetMaxSelectPriority

func (u *Unit) GetMaxSelectPriority() (max SSelectPriorityValue)

func (*Unit) GetScore

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

func (*Unit) GetScoreDetails

func (u *Unit) GetScoreDetails(id string) string

func (*Unit) GetSelectPriority

func (u *Unit) GetSelectPriority(id string) SSelectPriorityValue

func (*Unit) Info

func (u *Unit) Info() string

func (*Unit) RegisterSelectPriorityUpdater

func (u *Unit) RegisterSelectPriorityUpdater(name string, f SSelectPriorityUpdater)

func (*Unit) SchedData

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

func (*Unit) SessionID

func (u *Unit) SessionID() string

func (*Unit) SetAvoidScore

func (u *Unit) SetAvoidScore(id string, val score.SScore)

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

func (u *Unit) SetPreferScore(id string, val score.SScore)

func (*Unit) SetScore

func (u *Unit) SetScore(id string, val score.SScore)

func (*Unit) SetSelectPriorityWithLock

func (u *Unit) SetSelectPriorityWithLock(id string, name string, spv SSelectPriorityValue)

func (*Unit) UpdateSelectPriority

func (u *Unit) UpdateSelectPriority()

type VendorModel

type VendorModel struct {
	Vendor string
	Model  string
}

func NewVendorModelByStr

func NewVendorModelByStr(desc string) *VendorModel

func (*VendorModel) IsMatch

func (vm *VendorModel) IsMatch(target *VendorModel) bool

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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