placement

package
v0.0.0-...-c0686e8 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Less

func Less(tuple1, tuple2 []float64) bool

Less returns true iff tuple1 is strictly less than tuple2, i.e. tuple1 < tuple2 when comparing the entries lexicographically

Types

type Assignment

type Assignment struct {
	// Entity to be placed.
	Entity *Entity

	// AssignedGroup the Group that the Entity got assigned to.
	AssignedGroup *Group

	// Failed is true if the assignment failed.
	Failed bool

	// Transcript holds the placement transcript of the placement of the entity.
	Transcript *Transcript
}

Assignment represents a placement of an entity in a given group or the failure to be able to place the entity in a group that satisfies all requirements of the entity.

func NewAssignment

func NewAssignment(entity *Entity) *Assignment

NewAssignment creates a new empty assignment for the entity.

type Entities

type Entities map[string]*Entity

Entities represents a set of entities.

func (Entities) Add

func (entities Entities) Add(entity *Entity)

Add will add the entity to the set.

func (Entities) Remove

func (entities Entities) Remove(entity *Entity)

Remove will remove the entity from the set.

type Entity

type Entity struct {
	Name        string
	Reservation Reserved
	Requirement Requirement
	Ordering    Ordering
	Relations   *labels.Bag
	Metrics     *metrics.Set
}

Entity represents an task, process or some entity that should run on a group.

func NewEntity

func NewEntity(name string) *Entity

NewEntity will create a new entity with the given name and creation time.

type Group

type Group struct {
	Name      string
	Labels    *labels.Bag
	Metrics   *metrics.Set
	Relations *labels.Bag
	Entities  Entities
}

Group represents a host or other physical entity which can contain entities.

func NewGroup

func NewGroup(name string) *Group

NewGroup will create a new group with the given name.

func (*Group) Update

func (group *Group) Update()

Update will update the relations and metrics of the group from those of its entities.

type Ordering

type Ordering interface {
	// Tuple returns a tuple of floats created from the group, scope groups and the entity.
	Tuple(group *Group, scopeSet *ScopeSet, entity *Entity) []float64
}

Ordering returns a tuple of floats given a group relative to an entity and a scope of groups.

func NameOrdering

func NameOrdering() Ordering

NameOrdering returns a new ordering by the group name.

type RelocationRank

type RelocationRank struct {
	// Entity to be relocated.
	Entity *Entity

	// CurrentGroup the group where the entity is currently placed.
	CurrentGroup *Group

	// Rank is a lower bound on the number of groups different from the current group which are better than the current
	// group.
	Rank int

	// Transcript holds the relocation transcript of the relocation rank of the entity.
	Transcript *Transcript
}

RelocationRank contains a rank (number) that represents how many other groups, different than the currently assigned, that are better to place this entity on.

func NewRelocationRank

func NewRelocationRank(entity *Entity, current *Group) *RelocationRank

NewRelocationRank creates a new relocation rank for the entity.

type Requirement

type Requirement interface {
	// Passed returns true iff group passes the requirement in relation to the given scope.
	Passed(group *Group, scopeSet *ScopeSet, entity *Entity, transcript *Transcript) bool

	// The requirement should be transcript-able, so we can get metrics about how many groups pass and fail the
	// requirement.
	Transcriptable
}

Requirement tells if a given group passes the requirements for a given entity in relation to the given scope.

func FailedRequirement

func FailedRequirement() Requirement

FailedRequirement returns a requirement that never passes.

type Reservation

type Reservation struct {
	Entity *Entity
	Group  *Group
}

Reservation stores the reservation of an entity on a group

type Reserved

type Reserved struct {
	IsReserved bool
	Creation   time.Time
}

Reserved stores if an entity is reserved or not and the time when it was reserved.

type ScopeSet

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

ScopeSet contains a set of pre-computed label or relation bags for a given group and scope. The methods label scope and relation scope will return the labels or relations in the scope if they are pre-computed, else they will be computed and stored for the next call.

func NewScopeSet

func NewScopeSet(scopeGroups []*Group) *ScopeSet

NewScopeSet creates a new scope set for use in computations that need the label or relation scope of a group.

func (*ScopeSet) CompleteScope

func (set *ScopeSet) CompleteScope() map[string]*Group

CompleteScope returns the union of all groups that have ever been in scope for any call to LabelScope or RelationScope. Notice that the result will change depending on which calls are made to LabelScope and RelationScope.

func (*ScopeSet) Copy

func (set *ScopeSet) Copy() *ScopeSet

Copy makes a shallow copy of the scope set where the label bags are the same as in the original.

func (*ScopeSet) LabelScope

func (set *ScopeSet) LabelScope(group *Group, scope *labels.Label) *labels.Bag

LabelScope finds all labels in scope of the given group and caches them for the next call.

func (*ScopeSet) RelationScope

func (set *ScopeSet) RelationScope(group *Group, scope *labels.Label) *labels.Bag

RelationScope finds all relations in scope of the given group and caches them for the next call.

func (*ScopeSet) ScopeGroups

func (set *ScopeSet) ScopeGroups() []*Group

ScopeGroups returns the set of groups, given to a scope set when it is created, which are used as the basis for all scope calculations.

type Transcript

type Transcript struct {
	Requirement  string
	GroupsPassed int
	GroupsFailed int
	Subscripts   map[Transcriptable]*Transcript
}

Transcript represents a transcript of which requirements passed and failed when evaluating groups for an entity.

func NewTranscript

func NewTranscript(name string) *Transcript

NewTranscript creates a new transcript with a description.

func (*Transcript) Add

func (transcript *Transcript) Add(other *Transcript)

Add will add the other transcript into this transcript by merging them.

func (*Transcript) Copy

func (transcript *Transcript) Copy() *Transcript

Copy creates a deep copy of the transcript and all sub-transcripts, but with a shallow copy of all the transcriptables.

func (*Transcript) IncFailed

func (transcript *Transcript) IncFailed()

IncFailed will increment the number of groups that failed the requirements.

func (*Transcript) IncPassed

func (transcript *Transcript) IncPassed()

IncPassed will increment the number of groups that passed the requirements.

func (*Transcript) String

func (transcript *Transcript) String() string

String will create a human readable representation of the transcript.

func (*Transcript) Subscript

func (transcript *Transcript) Subscript(transcriptable Transcriptable) *Transcript

Subscript will create a sub transcript with the given description if one does not exist.

type Transcriptable

type Transcriptable interface {
	// String will return a human readable string representation of the transcript-able.
	String() string

	// Composite will return true iff the transcript-able is composed of other transcript-ables and a type name describing
	// the type of transcript-able.
	Composite() (composite bool, typeName string)
}

Transcriptable represents something we can create a transcript for, it is usually a requirement which can be composed of sub-requirements, hence we want a human readable name in the string-method and to know whatever it is composite in the composite-method and the type of composition.

func EmptyTranscript

func EmptyTranscript() Transcriptable

EmptyTranscript returns an empty transcript.

Jump to

Keyboard shortcuts

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