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
- Variables
- func NetworkID(userID, name string) pkg.NetID
- func Verify(r *Reservation) error
- type DecomissionerFunc
- type Engine
- type EngineOps
- type Feedbacker
- type ProvisionerFunc
- type Reservation
- type ReservationCache
- type ReservationConverterFunc
- type ReservationExpirer
- type ReservationPoller
- type ReservationSource
- type ReservationType
- type ResourceUnits
- type Result
- type ResultConverterFunc
- type ResultState
- type Signer
- type Statser
- type Tag
Constants ¶
const ( // StateError constant StateError = ResultState(workloads.ResultStateError) // StateOk constant StateOk = ResultState(workloads.ResultStateOK) //StateDeleted constant StateDeleted = ResultState(workloads.ResultStateDeleted) )
Variables ¶
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
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 ¶
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 ¶
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.
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 }
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 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"` }
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
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 ReservationPoller ¶
type ReservationPoller interface { // 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 *Reservation
}
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 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
type ResultConverterFunc ¶
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 ¶
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 }
Statser is used by the provision Engine to keep track of how much resource unit and number of primitives is provisionned