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 ¶
- Variables
- func GetContract(ctx context.Context) substrate.NodeContract
- func GetDeployment(ctx context.Context) (gridtypes.Deployment, error)
- func GetDeploymentID(ctx context.Context) (twin uint32, deployment uint64)
- func GetWorkload(ctx context.Context, name gridtypes.Name) (gridtypes.WorkloadWithID, error)
- func IsRentedNode(ctx context.Context) bool
- type Callback
- type DescriptionField
- type Engine
- type EngineOption
- func WithAPIGateway(node uint32, substrateGateway *stubs.SubstrateGatewayStub) EngineOption
- func WithAdmins(g Twins) EngineOption
- func WithCallback(cb Callback) EngineOption
- func WithRerunAll(t bool) EngineOption
- func WithStartupOrder(t ...gridtypes.WorkloadType) EngineOption
- func WithTwins(g Twins) EngineOption
- type Exclude
- type Field
- type Initializer
- type Janitor
- type Manager
- type MetadataField
- type NativeEngine
- func (e *NativeEngine) Admins() Twins
- func (n *NativeEngine) Changes(twin uint32, contractID uint64) ([]gridtypes.Workload, error)
- func (n *NativeEngine) CreateOrUpdate(twin uint32, deployment gridtypes.Deployment, update bool) error
- func (e *NativeEngine) DecommissionCached(id string, reason string) error
- func (e *NativeEngine) Deprovision(ctx context.Context, twin uint32, id uint64, reason string) error
- func (n *NativeEngine) Get(twin uint32, contractID uint64) (gridtypes.Deployment, error)
- func (e *NativeEngine) GetWorkloadStatus(id string) (gridtypes.ResultState, bool, error)
- func (n *NativeEngine) List(twin uint32) ([]gridtypes.Deployment, error)
- func (n *NativeEngine) ListPrivateIPs(twin uint32, network gridtypes.Name) ([]string, error)
- func (n *NativeEngine) ListPublicIPs() ([]string, error)
- func (e *NativeEngine) Pause(ctx context.Context, twin uint32, id uint64) error
- func (e *NativeEngine) Provision(ctx context.Context, deployment gridtypes.Deployment) error
- func (e *NativeEngine) Resume(ctx context.Context, twin uint32, id uint64) error
- func (e *NativeEngine) Run(root context.Context) error
- func (e *NativeEngine) Storage() Storage
- func (e *NativeEngine) Twins() Twins
- func (e *NativeEngine) Update(ctx context.Context, update gridtypes.Deployment) error
- type Pauser
- type Provisioner
- type ResourceUnits
- type Response
- type SignatureRequirementField
- type Storage
- type StorageCapacity
- type Twins
- type Updater
- type VersionField
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDeploymentExists returned if object exist ErrDeploymentExists = fmt.Errorf("exists") // ErrWorkloadExists returned if object exist ErrWorkloadExists = fmt.Errorf("exists") // ErrDeploymentConflict returned if deployment cannot be stored because // it conflicts with another deployment ErrDeploymentConflict = fmt.Errorf("conflict") //ErrDeploymentNotExists returned if object not exists ErrDeploymentNotExists = fmt.Errorf("deployment does not exist") // ErrWorkloadNotExist returned by storage if workload does not exist ErrWorkloadNotExist = fmt.Errorf("workload does not exist") // ErrNoActionNeeded can be returned by any provision method to indicate that // no action has been taken in case a workload is already deployed and the // engine then can skip updating the result of the workload. // When returned, the data returned by the provision is ignored ErrNoActionNeeded = fmt.Errorf("no action needed") // ErrDeploymentUpgradeValidationError error, is returned if the deployment // failed to compute upgrade steps ErrDeploymentUpgradeValidationError = fmt.Errorf("upgrade validation error") // ErrInvalidVersion invalid version error ErrInvalidVersion = fmt.Errorf("invalid version") )
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
Functions ¶
func GetContract ¶
func GetContract(ctx context.Context) substrate.NodeContract
GetContract of deployment. panics if engine has no substrate set.
func GetDeployment ¶
func GetDeployment(ctx context.Context) (gridtypes.Deployment, error)
GetDeployment gets a copy of the current deployment with latest state
func GetDeploymentID ¶
GetDeploymentID gets twin and deployment ID for current deployment
func GetWorkload ¶
GetWorkload get the last state of the workload for the current deployment
func IsRentedNode ¶
IsRentedNode returns true if current node is rented
Types ¶
type DescriptionField ¶
type DescriptionField struct {
Description string
}
type Engine ¶
type Engine interface { // Provision pushes a workload to engine queue. on success // means that workload has been committed to storage (accepts) // and will be processes later Provision(ctx context.Context, wl gridtypes.Deployment) error Deprovision(ctx context.Context, twin uint32, id uint64, reason string) error Pause(ctx context.Context, twin uint32, id uint64) error Resume(ctx context.Context, twin uint32, id uint64) error Update(ctx context.Context, update gridtypes.Deployment) error Storage() Storage Twins() Twins Admins() Twins }
Engine is engine interface
type EngineOption ¶
type EngineOption interface {
// contains filtered or unexported methods
}
EngineOption interface
func WithAPIGateway ¶
func WithAPIGateway(node uint32, substrateGateway *stubs.SubstrateGatewayStub) EngineOption
WithAPIGateway sets the API Gateway. If set it will be used by the engine to fetch (and validate) the deployment contract then contract with be available on the deployment context
func WithAdmins ¶
func WithAdmins(g Twins) EngineOption
WithAdmins sets the admins key getter on the engine
func WithCallback ¶
func WithCallback(cb Callback) EngineOption
WithCallback sets a callback that is called when a deployment is being Created, Updated, Or Deleted The handler then can use the id to get current "state" of the deployment from storage and take proper action. A callback must not block otherwise the engine operation will get blocked
func WithRerunAll ¶
func WithRerunAll(t bool) EngineOption
WithRerunAll if set forces the engine to re-run all reservations on engine start.
func WithStartupOrder ¶
func WithStartupOrder(t ...gridtypes.WorkloadType) EngineOption
WithStartupOrder forces a specific startup order of types any type that is not listed in this list, will get started in an nondeterministic order
func WithTwins ¶
func WithTwins(g Twins) EngineOption
WithTwins sets the user key getter on the engine
type Exclude ¶
type Exclude = func(dl *gridtypes.Deployment, wl *gridtypes.Workload) bool
Used with Storage interface to compute capacity, exclude any deployment and or workload that returns true from the capacity calculation.
type Initializer ¶
Initializer interface define an extra Initialize method which is run on the provisioner before the provision engine is started.
type Manager ¶
type Manager interface { Provision(ctx context.Context, wl *gridtypes.WorkloadWithID) (interface{}, error) Deprovision(ctx context.Context, wl *gridtypes.WorkloadWithID) error }
Manager defines basic type manager functionality. This interface declares the provision and the deprovision method which is required by any Type manager.
type MetadataField ¶
type MetadataField struct {
Metadata string
}
type NativeEngine ¶
type NativeEngine struct {
// contains filtered or unexported fields
}
NativeEngine is the core of this package The engine is responsible to manage provision and decomission of workloads on the system
func New ¶
func New(storage Storage, provisioner Provisioner, root string, opts ...EngineOption) (*NativeEngine, 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 (*NativeEngine) CreateOrUpdate ¶
func (n *NativeEngine) CreateOrUpdate(twin uint32, deployment gridtypes.Deployment, update bool) error
func (*NativeEngine) DecommissionCached ¶
func (e *NativeEngine) DecommissionCached(id string, reason string) error
DecommissionCached implements the zbus interface
func (*NativeEngine) Deprovision ¶
func (e *NativeEngine) Deprovision(ctx context.Context, twin uint32, id uint64, reason string) error
Deprovision workload
func (*NativeEngine) Get ¶
func (n *NativeEngine) Get(twin uint32, contractID uint64) (gridtypes.Deployment, error)
func (*NativeEngine) GetWorkloadStatus ¶
func (e *NativeEngine) GetWorkloadStatus(id string) (gridtypes.ResultState, bool, error)
GetWorkloadStatus get workload status, returns status, exists, error
func (*NativeEngine) List ¶
func (n *NativeEngine) List(twin uint32) ([]gridtypes.Deployment, error)
func (*NativeEngine) ListPrivateIPs ¶
func (*NativeEngine) ListPublicIPs ¶
func (n *NativeEngine) ListPublicIPs() ([]string, error)
func (*NativeEngine) Provision ¶
func (e *NativeEngine) Provision(ctx context.Context, deployment gridtypes.Deployment) error
Provision workload
func (*NativeEngine) Run ¶
func (e *NativeEngine) Run(root context.Context) error
Run starts reader reservation from the Source and handle them
func (*NativeEngine) Update ¶
func (e *NativeEngine) Update(ctx context.Context, update gridtypes.Deployment) error
Update workloads
type Pauser ¶
type Pauser interface { Pause(ctx context.Context, wl *gridtypes.WorkloadWithID) error Resume(ctx context.Context, wl *gridtypes.WorkloadWithID) error }
Pauser defines optional Pause, Resume method for type managers. Types are allowed to implement pause, resume to put the workload in paused state where it's not usable by the user but at the same time not completely deleted.
type Provisioner ¶
type Provisioner interface { // Initialize is called before the provision engine is started Initialize(ctx context.Context) error // Provision a workload Provision(ctx context.Context, wl *gridtypes.WorkloadWithID) (gridtypes.Result, error) // Deprovision a workload Deprovision(ctx context.Context, wl *gridtypes.WorkloadWithID) error // Pause a workload Pause(ctx context.Context, wl *gridtypes.WorkloadWithID) (gridtypes.Result, error) // Resume a workload Resume(ctx context.Context, wl *gridtypes.WorkloadWithID) (gridtypes.Result, error) // Update a workload Update(ctx context.Context, wl *gridtypes.WorkloadWithID) (gridtypes.Result, error) // CanUpdate checks if this workload can be updated on the fly CanUpdate(ctx context.Context, typ gridtypes.WorkloadType) bool }
Provisioner interface. the errors returned by this interface are associated with provisioner errors, not workloads errors. The difference is, a failure to recognize the workload type for example, is a provisioner error. A workload error is when the workload fails to deploy and this is returned as Error state in the Result object (but nil error) Methods can return special error type ErrDidNotChange which instructs the engine that the workload provision was not carried on because it's already deployed, basically a no action needed indicator. In that case, the engine can ignore the returned result
func NewMapProvisioner ¶
func NewMapProvisioner(managers map[gridtypes.WorkloadType]Manager) Provisioner
NewMapProvisioner returns a new instance of a map provisioner
type Response ¶
type Response interface { error // contains filtered or unexported methods }
func Ok ¶
func Ok() Response
Ok response. you normally don't need to return this from Manager methods. instead returning `nil` error is preferred.
type SignatureRequirementField ¶
type SignatureRequirementField struct {
SignatureRequirement gridtypes.SignatureRequirement
}
type Storage ¶
type Storage interface { // Create a new deployment in storage, it sets the initial transactions // for all workloads to "init" and the correct creation time. Create(deployment gridtypes.Deployment) error // Update updates a deployment fields Update(twin uint32, deployment uint64, fields ...Field) error // Delete deletes a deployment from storage. Delete(twin uint32, deployment uint64) error // Get gets the current state of a deployment from storage Get(twin uint32, deployment uint64) (gridtypes.Deployment, error) // Error sets global deployment error Error(twin uint32, deployment uint64, err error) error // Add workload to deployment, if no active deployment exists with same name Add(twin uint32, deployment uint64, workload gridtypes.Workload) error // Remove a workload from deployment. Remove(twin uint32, deployment uint64, name gridtypes.Name) error // Transaction append a transaction to deployment transactions logs Transaction(twin uint32, deployment uint64, workload gridtypes.Workload) error // Changes return all the historic transactions of a deployment Changes(twin uint32, deployment uint64) (changes []gridtypes.Workload, err error) // Current gets last state of a workload by name Current(twin uint32, deployment uint64, name gridtypes.Name) (gridtypes.Workload, error) // Twins list twins in storage Twins() ([]uint32, error) // ByTwin return list of deployments for a twin ByTwin(twin uint32) ([]uint64, error) // return total capacity and active deployments Capacity(exclude ...Exclude) (StorageCapacity, error) }
Storage interface
type StorageCapacity ¶
type StorageCapacity struct { // Cap is total reserved capacity as per all active workloads Cap gridtypes.Capacity // Deployments is a list with all deployments that are active Deployments []gridtypes.Deployment // Workloads the total number of all workloads Workloads int // LastDeploymentTimestamp last deployment timestamp LastDeploymentTimestamp gridtypes.Timestamp }
type Twins ¶
Twins is used to get twin public key
func NewSubstrateAdmins ¶
func NewSubstrateAdmins(substrateGateway *stubs.SubstrateGatewayStub, farmID uint32) (Twins, error)
NewSubstrateAdmins creates a substrate twins db that implements the provision.Users interface. but it also make sure the user is an admin
func NewSubstrateTwins ¶
func NewSubstrateTwins(substrateGateway *stubs.SubstrateGatewayStub) (Twins, error)
NewSubstrateTwins creates a substrate users db that implements the provision.Users interface.
type Updater ¶
type Updater interface {
Update(ctx context.Context, wl *gridtypes.WorkloadWithID) (interface{}, error)
}
Updater defines the optional Update method for a type manager. Types are allowed to implement update to change their settings on the fly
type VersionField ¶
type VersionField struct {
Version uint32
}
Source Files
¶
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 |