offer

package
v1.20.11 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package offer provides mesos offers resources pool implements.

struct Offer is responsible for the managements of mesos's offers, including add, use and delete.

Offer need interface SchedManager's function to manage offers, so we need struct SchedManager to new struct offer. Interface SchedManager have four functions, for details please look interface.go

para := &OfferPara{
	Sched: &SchedManager{},
}

offerPool := NewOfferPool(para)
//...
var mesosOffers []*mesos.Offer
//...

//add mesos's offers to offer pool
offerPool.AddOffers(mesosOffers)

//get the first offer
offer := offerPool.GetFirstOffer()
for{
	if offer == nil {
		break
	}

	// if offer is suitable, then use this offer
	ok := offerPool.UseOffer(offer)
	if ok {
		break
	}

	//else get the next offer, until you get the right one
	offer = offerPool.GetNextOffer(offer)
}
//...

Index

Constants

View Source
const (
	// lost mesos slave's grace period time
	DefaultLostSlaveGracePeriod = 180

	//mesos slave offer life period
	DefaultOfferLifePeriod = 240

	//decline offer grace period
	DefaultDeclineOfferGracePeriod = 5

	DeclineOfferChannelLength = 1024
	DefaultOfferEventLength   = 1024
	DefaultMiniResourceCpu    = 0.05
)

Variables

This section is empty.

Functions

func GetOfferAttribute

func GetOfferAttribute(offer *mesos.Offer, name string) (*mesos.Attribute, error)

func GetOfferIp

func GetOfferIp(offer *mesos.Offer) (string, bool)

Types

type Offer

type Offer struct {
	// offer id, int64
	Id int64

	//mesos slave offer
	Offer *mesos.Offer

	DeltaCPU  float64
	DeltaMem  float64
	DeltaDisk float64
	// contains filtered or unexported fields
}

type OfferPara

type OfferPara struct {
	// struct SchedManager
	Sched SchedManager

	//LostSlaveGracePeriod
	//if you don't specify, it will the const DefaultLostSlaveGracePeriod
	LostSlaveGracePeriod int

	//DefaultLostSlaveGracePeriod
	//if you don't specify, it will the const DefaultOfferLifePeriod
	OfferlifePeriod int

	//store
	Store store.Store
}

NewOfferPool's input parameter.

type OfferPool

type OfferPool interface {
	//get the first offer from the offer pool.
	//if the offer pool don't have offer,it return nil
	GetFirstOffer() *Offer

	//get the specified offer's next offer.
	//if the offer don't have next offer,it return nil
	GetNextOffer(*Offer) *Offer

	//get all valid offers at the moment
	GetAllOffers() []*Offer

	//scheduler can use the offer by function UseOffer.
	//offer pool don't manage the offer after scheduler use it.
	//at concurrency,it is possible that multiple threads will use the same offer.
	//so only return true, indicating use the offer successful.
	UseOffer(*Offer) bool

	//add mesos's offers in offer pool
	AddOffers([]*mesos.Offer) error

	//when mesos slave lost, the slave need grace period to recover after re-registration.
	//so sign the lost slave, it's offer is invalid for the moment
	AddLostSlave(string)

	//get offer pool's length
	GetOffersLength() int
}

OfferPool is mesos offer pool, it is responsible for the managements of the mesos's offers. OfferPool maintains an ordered list of offers, we can use it by the following functions.

func NewOfferPool

func NewOfferPool(para *OfferPara) OfferPool

new struct OfferPool

type SchedManager

type SchedManager interface {
	//GetHostAttributes is used to get variable mesos slave's attributes.
	//Examples for ip-resources, netflow.
	//If slave don't have variable attributes, it return nil
	GetHostAttributes(*typesplugin.HostPluginParameter) (map[string]*typesplugin.HostAttributes, error)

	//FetchAgentSetting is used to get user custom mesos slave's attributes.
	//input is slave's ip
	FetchAgentSetting(string) (*commtype.BcsClusterAgentSetting, error)

	//FetchAgentSchedInfo is used to get agent DeltaCPU, DeltaDisk, DeltaMem
	//input is slave's hostname
	FetchAgentSchedInfo(string) (*types.AgentSchedInfo, error)

	//Get mesos cluster id
	GetClusterId() string

	//decline mesos slave's offer, mesos will resubmit this offer after a few
	//seconds.
	//input is mesos offer's id
	DeclineResource(*string) (*http.Response, error)

	//fetch taskgroup
	FetchTaskGroup(taskGroupID string) (*types.TaskGroup, error)

	//update mesos agents
	UpdateMesosAgents()
}

A SchedManager is a struct Scheduler, it is responsible for interacting with struct Offer.

Jump to

Keyboard shortcuts

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