provision

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 35 Imported by: 3

Documentation

Overview

Package provision exposes the Engine type. Engine is a fully configurable type that can be used to implement custom provisioning of workloads

Index

Constants

View Source
const (
	// StateError constant
	StateError = ResultState(workloads.ResultStateError)
	// StateOk constant
	StateOk = ResultState(workloads.ResultStateOK)
	//StateDeleted constant
	StateDeleted = ResultState(workloads.ResultStateDeleted)
)

Variables

View Source
var (
	ResourceUnitsCRU = ResourceUnits("CRU")
	ResourceUnitsMRU = ResourceUnits("MRU")
	ResourceUnitsHRU = ResourceUnits("HRU")
	ResourceUnitsSRU = ResourceUnits("SRU")
)

ResourcesUnits are the units used to compute how much capacity is reserved on the system

View Source
var (
	// ErrPollEOS can be returned by a reservation poll to
	// notify the caller that it has reached end of stream
	// and next calls will not return any more data.
	ErrPollEOS = fmt.Errorf("end of stream")
)

Functions

func FilesystemName added in v0.4.9

func FilesystemName(r Reservation) string

FilesystemName return a string to be used as filesystem name from a reservation object

func NetworkID added in v0.4.0

func NetworkID(userID, name string) pkg.NetID

NetworkID construct a network ID based on a userID and network name

func Verify

func Verify(r *Reservation) error

Verify verifies the signature of the reservation

func WorkloadIDFromFilesystem added in v0.4.9

func WorkloadIDFromFilesystem(fs pkg.Filesystem) (int64, error)

WorkloadIDFromFilesystem parse a filesystem object and return the reservation ID that created it

Types

type DecomissionerFunc

type DecomissionerFunc func(ctx context.Context, reservation *Reservation) error

DecomissionerFunc is the function called by the Engine to decomission a workload

type Engine

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

Engine is the core of this package The engine is responsible to manage provision and decomission of workloads on the system

func New

func New(opts EngineOps) (*Engine, error)

New creates a new engine. Once started, the engine will continue processing all reservations from the reservation source and try to apply them. the default implementation is a single threaded worker. so it process one reservation at a time. On error, the engine will log the error. and continue to next reservation.

func (*Engine) Counters

func (e *Engine) Counters(ctx context.Context) <-chan pkg.ProvisionCounters

Counters is a zbus stream that sends statistics from the engine

func (*Engine) DecommissionCached added in v0.4.9

func (e *Engine) DecommissionCached(id string, reason string) error

DecommissionCached is used by other module to ask provisiond that a certain reservation is dead beyond repair and owner must be informed the decommission method will take care to update the reservation instance and also decommission the reservation normally

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

Run starts reader reservation from the Source and handle them

type EngineOps

type EngineOps struct {
	// NodeID is the identity of the system running the engine
	NodeID string
	// Source is responsible to retrieve reservation for a remote source
	Source ReservationSource
	// Feedback is used to send provision result to the source
	// after the reservation is provisionned
	Feedback Feedbacker
	// Cache is a used to keep track of which reservation are provisionned on the system
	// and know when they expired so they can be decommissioned
	Cache ReservationCache
	// Provisioners is a function map so the engine knows how to provision the different
	// workloads supported by the system running the engine
	Provisioners map[ReservationType]ProvisionerFunc
	// Decomissioners contains the opposite function from Provisioners
	// they are used to decomission workloads from the system
	Decomissioners map[ReservationType]DecomissionerFunc
	// Signer is used to authenticate the result send to the source
	Signer Signer
	// Statser is responsible to keep track of how much workloads and resource units
	// are reserved on the system running the engine
	// After each provision/decomission the engine sends statistics update to the staster
	Statser Statser
	// ZbusCl is a client to Zbus
	ZbusCl zbus.Client

	// Janitor is used to clean up some of the resources that might be lingering on the node
	// if not set, no cleaning up will be done
	Janitor *Janitor
}

EngineOps are the configuration of the engine

type Feedbacker

type Feedbacker interface {
	Feedback(nodeID string, r *Result) error
	Deleted(nodeID, id string) error
	UpdateStats(nodeID string, w directory.WorkloadAmount, u directory.ResourceAmount) error
}

Feedbacker defines the method that needs to be implemented to send the provision result to BCDB

type Janitor added in v0.4.9

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

Janitor structure

func NewJanitor added in v0.4.9

func NewJanitor(zbus zbus.Client, getter ReservationGetter) *Janitor

NewJanitor creates a new Janitor instance

func (*Janitor) CleanupResources added in v0.4.9

func (j *Janitor) CleanupResources(ctx context.Context) error

CleanupResources cleans up unused resources

type ProvisionerFunc

type ProvisionerFunc func(ctx context.Context, reservation *Reservation) (interface{}, error)

ProvisionerFunc is the function called by the Engine to provision a workload

type Reservation

type Reservation struct {
	// ID of the reservation
	ID string `json:"id"`
	// NodeID of the node where to deploy this reservation
	NodeID string `json:"node_id"`
	// Identification of the user requesting the reservation
	User string `json:"user_id"`
	// Type of the reservation (container, zdb, vm, etc...)
	Type ReservationType `json:"type"`
	// Data is the reservation type arguments.
	Data json.RawMessage `json:"data,omitempty"`
	// Date of creation
	Created time.Time `json:"created"`
	// Duration of the reservation
	Duration time.Duration `json:"duration"`
	// Signature is the signature to the reservation
	// it contains all the field of this struct except the signature itself and the Result field
	Signature []byte `json:"signature,omitempty"`

	// This flag is set to true when a reservation needs to be deleted
	// before its expiration time
	ToDelete bool `json:"to_delete"`

	// Tag object is mainly used for debugging.
	Tag Tag `json:"-"`

	// Reference is a pointer to an existing reservation
	// this is used to allow a new type of workload to point to an existing one
	// so the provision engine know both are linked
	Reference string `json:"reference"`

	Result Result `json:"result"`

	Version int `json:"version"`
}

Reservation struct

func (*Reservation) Expired

func (r *Reservation) Expired() bool

Expired returns a boolean depending if the reservation has expire or not at the time of the function call

func (*Reservation) Sign

func (r *Reservation) Sign(privateKey ed25519.PrivateKey) error

Sign creates a signature from all the field of the reservation object and fill the Signature field

func (*Reservation) SplitID

func (r *Reservation) SplitID() (reservation uint64, workload uint64, err error)

SplitID gets the reservation part and the workload part from a full reservation ID

type ReservationCache

type ReservationCache interface {
	Add(r *Reservation) error
	Get(id string) (*Reservation, error)
	Remove(id string) error
	Exists(id string) (bool, error)
	NetworkExists(id string) (bool, error)
	Sync(Statser) error
}

ReservationCache define the interface to store some reservations

type ReservationConverterFunc

type ReservationConverterFunc func(w workloads.Workloader) (*Reservation, error)

ReservationConverterFunc is used to convert from the explorer workloads type into the internal Reservation type

type ReservationExpirer

type ReservationExpirer interface {
	// GetExpired returns all id the the reservations that are expired
	// at the time of the function call
	GetExpired() ([]*Reservation, error)
}

ReservationExpirer define the interface to implement to get all the reservation that have expired

type ReservationGetter added in v0.4.9

type ReservationGetter interface {
	Get(gwid string) (*Reservation, error)
}

ReservationGetter interface. Some reservation sources can implement the getter interface

type ReservationJob added in v0.4.9

type ReservationJob struct {
	Reservation
	// contains filtered or unexported fields
}

ReservationJob wraps a reservation type and has a boolean to indicate it is the last reservation

type ReservationPoller

type ReservationPoller interface {
	ReservationGetter
	// Poll ask the store to send us reservation for a specific node ID
	// from is the used as a filter to which reservation to use as
	// reservation.ID >= from. So a client to the Poll method should make
	// sure to call it with the last (MAX) reservation ID he receieved.
	Poll(nodeID pkg.Identifier, from uint64) (reservations []*Reservation, lastID uint64, err error)
}

ReservationPoller define the interface to implement to poll the Explorer for new reservation

type ReservationSource

type ReservationSource interface {
	Reservations(ctx context.Context) <-chan *ReservationJob
}

ReservationSource interface. The source defines how the node will get reservation requests then reservations are applied to the node to deploy a resource of the given Reservation.Type

func CombinedSource

func CombinedSource(sources ...ReservationSource) ReservationSource

CombinedSource merge different ReservationSources into one ReservationSource

func NewDecommissionSource

func NewDecommissionSource(store ReservationExpirer) ReservationSource

NewDecommissionSource creates a ReservationSource that sends reservation that have expired into it's output channel

func PollSource

func PollSource(store ReservationPoller, nodeID pkg.Identifier) ReservationSource

PollSource does a long poll on address to get new and to be deleted reservations. the server should only return unique reservations stall the connection as long as possible if no new reservations are available.

type ReservationType

type ReservationType string

ReservationType type

type ResourceUnits

type ResourceUnits string

ResourceUnits type

type Result

type Result struct {
	Type ReservationType `json:"type"`
	//Reservation ID
	ID string `json:"id"`
	// Time when the result is sent
	Created time.Time `json:"created"`
	// State of the deployment (ok,error)
	State ResultState `json:"state"`
	// if State is "error", then this field contains the error
	// otherwise it's nil
	Error string `json:"message"`
	// Data is the information generated by the provisioning of the workload
	// its type depend on the reservation type
	Data json.RawMessage `json:"data_json"`
	// Signature is the signature to the result
	// is generated by signing the bytes returned from call to Result.Bytes()
	// and hex
	Signature string `json:"signature"`
}

Result is the struct filled by the node after a reservation object has been processed

func (*Result) Bytes

func (r *Result) Bytes() ([]byte, error)

Bytes returns a slice of bytes container all the information used to sign the Result object

func (*Result) IsNil added in v0.4.0

func (r *Result) IsNil() bool

IsNil checks if Result is the zero values

type ResultConverterFunc

type ResultConverterFunc func(result Result) (*workloads.Result, error)

ResultConverterFunc is used to convert internal Result type to the explorer workload result

type ResultState

type ResultState workloads.ResultStateEnum

ResultState type

func (ResultState) String

func (s ResultState) String() string

type Signer

type Signer interface {
	Sign(b []byte) ([]byte, error)
}

Signer interface is used to sign reservation result before sending them to the explorer

type Statser

type Statser interface {
	Increment(r *Reservation) error
	Decrement(r *Reservation) error
	CurrentUnits() directory.ResourceAmount
	CurrentWorkloads() directory.WorkloadAmount
	CheckMemoryRequirements(r *Reservation, totalMemAvailable uint64) error
}

Statser is used by the provision Engine to keep track of how much resource unit and number of primitives is provisionned

type Tag

type Tag map[string]string

Tag is custom tag to mark certain reservations

func AppendTag

func AppendTag(t, n Tag) Tag

AppendTag appends tags

func (Tag) String

func (t Tag) String() string

Directories

Path Synopsis
Package common hold logic that is used by both the provision and primitive package it purpose is mainly to avoid circular dependencies
Package common hold logic that is used by both the provision and primitive package it purpose is mainly to avoid circular dependencies

Jump to

Keyboard shortcuts

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