Back to godoc.org

Package offerpool

v0.0.0 (a69e935)
Latest Go to latest
Published: Oct 1, 2019 | License: Apache-2.0 | Module: github.com/uber/peloton

Index

Package Files

type Matcher

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

Matcher keeps track of matched host offers for given constraints.

func NewMatcher

func NewMatcher(
	hostFilter *hostsvc.HostFilter,
	evaluator constraints.Evaluator,
	hostPoolManager manager.HostPoolManager,
) *Matcher

NewMatcher returns a new instance of Matcher.

func (*Matcher) HasEnoughHosts

func (m *Matcher) HasEnoughHosts() bool

HasEnoughHosts returns whether this instance has matched enough hosts based on input HostLimit.

type Metrics

type Metrics struct {
	// Revocable/Non-Revocable Resources in Ready/Placing status
	Ready            scalar.GaugeMaps
	ReadyRevocable   scalar.GaugeMaps
	Placing          scalar.GaugeMaps
	PlacingRevocable scalar.GaugeMaps

	// metrics for number of hosts on each status.
	ReadyHosts               tally.Gauge
	PlacingHosts             tally.Gauge
	AvailableHosts           tally.Gauge
	ReturnUnusedHosts        tally.Counter
	ResetExpiredPlacingHosts tally.Counter
	ResetExpiredHeldHosts    tally.Counter

	// metrics for offers
	UnavailableOffers tally.Counter
	AcceptableOffers  tally.Counter
	ExpiredOffers     tally.Counter
	RescindEvents     tally.Counter
	Decline           tally.Counter
	DeclineFail       tally.Counter
}

Metrics tracks various metrics at offer pool level.

func NewMetrics

func NewMetrics(scope tally.Scope) *Metrics

NewMetrics returns a new Metrics struct, with all metrics initialized and rooted at the given tally.Scope

type Pool

type Pool interface {
	// Add offers to the pool. Filters out non-viable offers (offers with
	// non-nil Unavailability) and returns slice of acceptable offers.
	AddOffers(context.Context, []*mesos.Offer) []*mesos.Offer

	// Rescind a offer from the pool, on Mesos Master --offer-timeout
	// Returns whether the offer is found in the pool.
	RescindOffer(*mesos.OfferID) bool

	// UpdateTasksOnHost updates the task to host map for host summary.
	UpdateTasksOnHost(taskID string, taskState task.TaskState, taskInfo *task.TaskInfo)

	// RemoveExpiredOffers, prunes offers from the pool, when offer-hold-time
	// is expired.
	RemoveExpiredOffers() (map[string]*TimedOffer, int)

	// Clear all offers in the pool
	Clear()

	// Decline offers, sends Mesos Master decline call and removes from offer
	// pool.
	DeclineOffers(ctx context.Context, offerIds []*mesos.OfferID) error

	// ClaimForPlace obtains offers from pool conforming to given HostFilter
	// for placement purposes.
	// First return value is returned offers, grouped by hostname as key,
	// Second return value is a map from hostsvc.HostFilterResult to count.
	ClaimForPlace(
		ctx context.Context,
		constraint *hostsvc.HostFilter) (
		map[string]*summary.Offer,
		map[string]uint32, error)

	// ClaimForLaunch finds offers previously for placement on given host.
	// The difference from ClaimForPlace is that offers claimed from this
	// function are considered used and sent back to Mesos master in a Launch
	// operation, while result in `ClaimForPlace` are still considered part
	// of peloton apps.
	// An optional list of task ids is provided if the host is held for
	// the tasks
	ClaimForLaunch(
		hostname string,
		hostOfferID string,
		launchableTasks []*hostsvc.LaunchableTask,
		taskIDs ...*peloton.TaskID) (map[string]*mesos.Offer, error)

	// ReturnUnusedOffers returns previously placed offers on hostname back
	// to current offer pool so they can be used by future launch actions.
	ReturnUnusedOffers(hostname string) error

	// ResetExpiredPlacingHostSummaries resets the status of each hostSummary of the
	// offerPool from PlacingOffer to ReadyOffer if the PlacingOffer status has
	// expired and returns the hostnames which got reset
	ResetExpiredPlacingHostSummaries(now time.Time) []string

	// ResetExpiredHeldHostSummaries resets the status of each hostSummary of the
	// offerPool from HeldHost to ReadyHost if the HeldHost status has
	// expired and returns the hostnames which got reset
	ResetExpiredHeldHostSummaries(now time.Time) []string

	// GetAllOffers returns hostOffers : map[hostname] -> map(offerid -> offers
	// & #offers for reserved, unreserved or all offer type.
	GetAllOffers() (map[string]map[string]*mesos.Offer, int)

	// RefreshGaugeMaps refreshes ready/placing metrics from all hosts.
	RefreshGaugeMaps()

	// GetHostSummary returns the host summary object for the given host name
	GetHostSummary(hostName string) (summary.HostSummary, error)

	// GetBinPackingRanker returns the associated ranker with the offer pool
	GetBinPackingRanker() binpacking.Ranker

	// GetHostOfferIndex returns the host to host summary mapping
	// it makes the copy and returns the new map
	GetHostOfferIndex() map[string]summary.HostSummary

	// GetHostSummaries returns a map of hostname to host summary object
	GetHostSummaries(hostnames []string) (map[string]summary.HostSummary, error)

	// GetHostHeldForTask returns the host that is held for the task
	GetHostHeldForTask(taskID *peloton.TaskID) string

	// HoldForTasks holds the host for the tasks specified
	HoldForTasks(hostname string, taskIDs []*peloton.TaskID) error

	// ReleaseHoldForTasks release the hold of host for the tasks specified
	ReleaseHoldForTasks(hostname string, taskIDs []*peloton.TaskID) error

	// SetHostPoolManager set host pool manager in the offer pool.
	SetHostPoolManager(manager manager.HostPoolManager)
}

Pool caches a set of offers received from Mesos master. It is currently only instantiated at the leader of Peloton masters.

func NewOfferPool

func NewOfferPool(
	offerHoldTime time.Duration,
	schedulerClient mpb.SchedulerClient,
	metrics *Metrics,
	frameworkInfoProvider hostmgr_mesos.FrameworkInfoProvider,
	scarceResourceTypes []string,
	slackResourceTypes []string,
	binPackingRanker binpacking.Ranker,
	hostPlacingOfferStatusTimeout time.Duration,
	processor watchevent.WatchProcessor,
	hostPoolManager manager.HostPoolManager) Pool

NewOfferPool creates a offerPool object and registers the corresponding YARPC procedures.

type Refresher

type Refresher interface {
	Refresh(_ *atomic.Bool)
}

Refresher is the interface to refresh bin packed host list

func NewRefresher

func NewRefresher(
	pool Pool) Refresher

NewRefresher initializes the refresher for an OfferPool

type TimedOffer

type TimedOffer struct {
	Hostname   string
	Expiration time.Time
}

TimedOffer contains hostname and possible expiration time of an offer.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier