hostsummary

package
v0.0.0-...-ac6a2c4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateResource

func CreateResource(cpu, mem float64) (r scalar.Resources)

func GeneratePodSpecWithRes

func GeneratePodSpecWithRes(
	numPods int,
	cpu, mem float64,
) map[string]*pbpod.PodSpec

func GeneratePodToResMap

func GeneratePodToResMap(
	numPods int,
	cpu, mem float64,
) map[string]scalar.Resources

GeneratePodToResMap generates a map of podIDs to resources where each pod gets the specified `cpu` and `mem`

Types

type FakeHostSummary

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

func GenerateFakeHostSummaries

func GenerateFakeHostSummaries(numHosts int) []*FakeHostSummary

GenerateFakeHostSummaries returns a list of FakeHostSummary.

func NewFakeHostSummary

func NewFakeHostSummary(
	hostname string, version string, capacity scalar.Resources) *FakeHostSummary

NewFakeHostSummary is used for testing. It offers methods for easier manipulation of internal attribute.

func (FakeHostSummary) CasStatus

func (a FakeHostSummary) CasStatus(old, new HostStatus) error

CasStatus sets the status to new value if current value is old, otherwise returns error.

func (FakeHostSummary) CompleteLaunchPod

func (a FakeHostSummary) CompleteLaunchPod(pod *models.LaunchablePod)

func (FakeHostSummary) CompleteLease

func (a FakeHostSummary) CompleteLease(
	leaseID string,
	podToSpecMap map[string]*pbpod.PodSpec,
) error

CompleteLease verifies that the leaseID on this host is still valid. It checks that current baseHostSummary is in Placing status, updates pods to the host summary, recalculates allocated resources and set the host status to Ready.

func (FakeHostSummary) DeleteExpiredHolds

func (a FakeHostSummary) DeleteExpiredHolds(
	deadline time.Time) (bool, models.HostResources, []*peloton.PodID)

DeleteExpiredHolds deletes expired held pods in a hostSummary, returns whether the hostSummary is free of helds, available resource, and the pods held expired.

func (FakeHostSummary) GetAllocated

func (a FakeHostSummary) GetAllocated() models.HostResources

GetAllocated returns the allocation of the host.

func (FakeHostSummary) GetAvailable

func (a FakeHostSummary) GetAvailable() models.HostResources

GetAvailable returns the available resources of the host.

func (FakeHostSummary) GetCapacity

func (a FakeHostSummary) GetCapacity() models.HostResources

GetCapacity returns the capacity of the host.

func (FakeHostSummary) GetHeldPods

func (a FakeHostSummary) GetHeldPods() []*peloton.PodID

GetHeldPods returns a list of held PodIDs.

func (FakeHostSummary) GetHostLease

func (a FakeHostSummary) GetHostLease() *hostmgr.HostLease

GetHostLease creates and returns a host lease.

func (FakeHostSummary) GetHostStatus

func (a FakeHostSummary) GetHostStatus() HostStatus

GetHostStatus returns the HostStatus of the host.

func (FakeHostSummary) GetHostname

func (a FakeHostSummary) GetHostname() string

GetHostname returns the hostname of the host.

func (*FakeHostSummary) GetPodInfo

func (f *FakeHostSummary) GetPodInfo(
	podID *peloton.PodID,
) (pbpod.PodState, *pbpod.PodSpec, bool)

func (FakeHostSummary) GetVersion

func (a FakeHostSummary) GetVersion() string

GetVersion returns the version of the host.

func (FakeHostSummary) HandlePodEvent

func (a FakeHostSummary) HandlePodEvent(event *p2kscalar.PodEvent)

HandlePodEvent update host to pod map in baseHostSummary, corresponding subclasses could overwrite the method, but need to call the superclass method manually

func (FakeHostSummary) HoldForPod

func (a FakeHostSummary) HoldForPod(id *peloton.PodID) error

HoldForPod adds pod to heldPodIDs map when host is not reserved. It is noop if pod already exists in the map.

func (FakeHostSummary) RecoverPodInfo

func (a FakeHostSummary) RecoverPodInfo(
	id *peloton.PodID,
	state pbpod.PodState,
	spec *pbpod.PodSpec)

RecoverPodInfo updates pods info on the host, it is used only when hostsummary needs to recover the info upon restart

func (FakeHostSummary) ReleaseHoldForPod

func (a FakeHostSummary) ReleaseHoldForPod(id *peloton.PodID)

ReleaseHoldForPod removes the pod from heldPodIDs map. It should be called when: 1. pod is upgraded in place. 2. hold for this pod expires.

func (*FakeHostSummary) SetAllocated

func (f *FakeHostSummary) SetAllocated(allocated scalar.Resources)

func (FakeHostSummary) SetAvailable

func (a FakeHostSummary) SetAvailable(r models.HostResources)

SetAvailable sets the available resources of the host.

func (FakeHostSummary) SetCapacity

func (a FakeHostSummary) SetCapacity(r models.HostResources)

SetCapacity sets the capacity of the host.

func (FakeHostSummary) SetVersion

func (a FakeHostSummary) SetVersion(v string)

SetVersion sets the version of the host.

func (FakeHostSummary) TerminateLease

func (a FakeHostSummary) TerminateLease(leaseID string) error

TerminateLease is called when terminating the lease on a host. This will be called when host in PLACING state is not used, and placement engine decides to terminate its lease and set the host back to Ready.

func (FakeHostSummary) TryMatch

func (a FakeHostSummary) TryMatch(
	filter *hostmgr.HostFilter,
) Match

TryMatch atomically tries to match the current host with given HostFilter, and lock the host if it does. If current baseHostSummary is matched, this host will be marked as `PLACING`, after which it cannot be used by another placement engine until released. If current host is not matched by given HostFilter, the host status will remain unchanged.

type HostStatus

type HostStatus int

HostStatus represents status (Ready/Placing/Reserved/Held) of the host in host cache

const (
	// ReadyHost represents a host ready to be used.
	ReadyHost HostStatus = iota + 1

	// PlacingHost represents a host being used by placement engine.
	PlacingHost

	// ReservedHost represents a host that is reserved for tasks.
	ReservedHost
)

type HostSummary

type HostSummary interface {
	// TryMatch atomically tries to match the current host with given
	// HostFilter, and lock the host if it does.
	TryMatch(filter *hostmgr.HostFilter) Match

	// CompleteLease verifies that the leaseID on this host is still valid.
	CompleteLease(leaseID string, podToSpecMap map[string]*pbpod.PodSpec) error

	// CasStatus sets the status to new value if current value is old, otherwise
	// returns error.
	CasStatus(old, new HostStatus) error

	// GetCapacity returns the capacity of the host.
	GetCapacity() models.HostResources

	// GetAllocated returns the allocation of the host.
	GetAllocated() models.HostResources

	// GetAvailable returns the available resources of the host.
	GetAvailable() models.HostResources

	// SetCapacity sets the capacity of the host.
	SetCapacity(r models.HostResources)

	// SetAvailable sets the available resource of the host.
	SetAvailable(r models.HostResources)

	// GetVersion returns the version of the host.
	GetVersion() string

	// SetVersion sets the version of the host.
	SetVersion(v string)

	// GetHostname returns the hostname of the host.
	GetHostname() string

	// GetHostStatus returns the HostStatus of the host.
	GetHostStatus() HostStatus

	// GetHostLease creates and returns a host lease.
	GetHostLease() *hostmgr.HostLease

	// TerminateLease is called when terminating the lease on a host.
	TerminateLease(leaseID string) error

	// HandlePodEvent is called when a pod event occurs for a pod
	// that affects this host.
	HandlePodEvent(event *p2kscalar.PodEvent)

	// HoldForPod holds the host for the pod specified.
	// If an error is returned, hostsummary would guarantee that
	// the host is not held for the task.
	HoldForPod(id *peloton.PodID) error

	// ReleaseHoldForPod release the hold of host for the pod specified.
	ReleaseHoldForPod(id *peloton.PodID)

	// GetHeldPods returns a slice of pods that puts the host in held.
	GetHeldPods() []*peloton.PodID

	// DeleteExpiredHolds deletes expired held pods in a hostSummary, returns
	// whether the hostSummary is free of helds,
	// available resource,
	// and the pods held expired.
	DeleteExpiredHolds(now time.Time) (bool, models.HostResources, []*peloton.PodID)

	// CompleteLaunchPod is called when a pod is successfully launched,
	// for example to remove the ports from the available port ranges.
	CompleteLaunchPod(pod *models.LaunchablePod)

	// RecoverPodInfo updates pods info on the host, it is used only
	// when hostsummary needs to recover the info upon restart
	RecoverPodInfo(id *peloton.PodID, state pbpod.PodState, spec *pbpod.PodSpec)
}

func NewKubeletHostSummary

func NewKubeletHostSummary(
	hostname string,
	capacity models.HostResources,
	version string,
) HostSummary

NewKubeletHostSummary returns a zero initialized HostSummary object.

func NewMesosHostSummary

func NewMesosHostSummary(hostname string) HostSummary

type Match

type Match struct {
	// The result of the match
	Result hostmgr.HostFilterResult
	// host name of the matched host
	HostName string
}

Match represents the result of a match

type Matcher

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

Matcher keeps track of matched hosts for given constraints. This struct is not thread-safe.

func NewMatcher

func NewMatcher(hostFilter *hostmgr.HostFilter) *Matcher

NewMatcher returns a new instance of Matcher.

func (*Matcher) GetFilterCounts

func (m *Matcher) GetFilterCounts() map[string]uint32

func (*Matcher) GetHostNames

func (m *Matcher) GetHostNames() []string

GetHostNames returns list of host names that match the filter.

func (*Matcher) HostLimitReached

func (m *Matcher) HostLimitReached() bool

HostLimitReached returns true when the matcher has matched hosts equal to the max hosts specified in the filter

func (*Matcher) TryMatch

func (m *Matcher) TryMatch(
	hostname string,
	s HostSummary)

TryMatch tries to match ready host with particular constraint. If properly matched, the host name will be kept in Matcher.

Jump to

Keyboard shortcuts

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