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 GetSubstrate(ctx context.Context) substrate.Manager
- func GetWorkload(ctx context.Context, name gridtypes.Name) (gridtypes.WorkloadWithID, error)
- func NewUnchangedError(cause error) error
- type DeployFunction
- type DescriptionField
- type Engine
- type EngineOption
- type ErrUnchanged
- type Field
- type Janitor
- type MetadataField
- type NativeEngine
- func (e *NativeEngine) Admins() Twins
- func (e *NativeEngine) DecommissionCached(id string, reason string) error
- func (e *NativeEngine) Deprovision(ctx context.Context, twin uint32, id uint64, reason string) error
- func (e *NativeEngine) Provision(ctx context.Context, deployment gridtypes.Deployment) 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 Provisioner
- type RemoveFunction
- type ResourceUnits
- type SignatureRequirementField
- type Storage
- type Twins
- 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("workload 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 ¶ added in v0.5.5
GetContract of deployment. panics if engine has no substrate set.
func GetDeployment ¶ added in v0.5.5
func GetDeployment(ctx context.Context) (gridtypes.Deployment, error)
GetDeployment gets a copy of the current deployment with latest state
func GetDeploymentID ¶ added in v0.5.5
GetDeploymentID gets twin and deployment ID for current deployment
func GetSubstrate ¶ added in v0.5.5
GetSubstrate if engine has substrate set, panics otherwise
func GetWorkload ¶ added in v0.5.5
GetWorkload get the last state of the workload for the current deployment
func NewUnchangedError ¶ added in v0.5.5
NewUnchangedError return an instance of ErrUnchanged
Types ¶
type DeployFunction ¶ added in v0.5.5
type DeployFunction func(ctx context.Context, wl *gridtypes.WorkloadWithID) (interface{}, error)
DeployFunction simple provision function interface
type DescriptionField ¶ added in v0.5.5
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 Update(ctx context.Context, update gridtypes.Deployment) error Storage() Storage Twins() Twins Admins() Twins }
Engine is engine interface
type EngineOption ¶ added in v0.5.5
type EngineOption interface {
// contains filtered or unexported methods
}
EngineOption interface
func WithAdmins ¶ added in v0.5.5
func WithAdmins(g Twins) EngineOption
WithAdmins sets the admins key getter on the engine
func WithRerunAll ¶ added in v0.5.5
func WithRerunAll(t bool) EngineOption
WithRerunAll if set forces the engine to re-run all reservations on engine start.
func WithStartupOrder ¶ added in v0.5.5
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 WithSubstrate ¶ added in v0.5.5
func WithSubstrate(node uint32, sub substrate.Manager) EngineOption
WithSubstrate sets the substrate client. 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 WithTwins ¶ added in v0.5.5
func WithTwins(g Twins) EngineOption
WithTwins sets the user key getter on the engine
type ErrUnchanged ¶ added in v0.5.5
type ErrUnchanged struct {
// contains filtered or unexported fields
}
ErrUnchanged can be returned by the Provisioner.Update it means that the update has failed but the workload is intact
func (ErrUnchanged) Error ¶ added in v0.5.5
func (e ErrUnchanged) Error() string
func (ErrUnchanged) Unwrap ¶ added in v0.5.5
func (e ErrUnchanged) Unwrap() error
type MetadataField ¶ added in v0.5.5
type MetadataField struct {
Metadata string
}
type NativeEngine ¶ added in v0.5.5
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) Admins ¶ added in v0.5.5
func (e *NativeEngine) Admins() Twins
Admins returns admins db
func (*NativeEngine) DecommissionCached ¶ added in v0.5.5
func (e *NativeEngine) DecommissionCached(id string, reason string) error
DecommissionCached implements the zbus interface
func (*NativeEngine) Deprovision ¶ added in v0.5.5
func (e *NativeEngine) Deprovision(ctx context.Context, twin uint32, id uint64, reason string) error
Deprovision workload
func (*NativeEngine) Provision ¶ added in v0.5.5
func (e *NativeEngine) Provision(ctx context.Context, deployment gridtypes.Deployment) error
Provision workload
func (*NativeEngine) Run ¶ added in v0.5.5
func (e *NativeEngine) Run(root context.Context) error
Run starts reader reservation from the Source and handle them
func (*NativeEngine) Storage ¶ added in v0.5.5
func (e *NativeEngine) Storage() Storage
Storage returns
func (*NativeEngine) Twins ¶ added in v0.5.5
func (e *NativeEngine) Twins() Twins
Twins returns twins db
func (*NativeEngine) Update ¶ added in v0.5.5
func (e *NativeEngine) Update(ctx context.Context, update gridtypes.Deployment) error
Update workloads
type Provisioner ¶ added in v0.5.5
type Provisioner interface { Provision(ctx context.Context, wl *gridtypes.WorkloadWithID) (gridtypes.Result, error) Decommission(ctx context.Context, wl *gridtypes.WorkloadWithID) error Update(ctx context.Context, wl *gridtypes.WorkloadWithID) (gridtypes.Result, error) 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 ¶ added in v0.5.5
func NewMapProvisioner(p map[gridtypes.WorkloadType]DeployFunction, d map[gridtypes.WorkloadType]RemoveFunction, u map[gridtypes.WorkloadType]DeployFunction) Provisioner
NewMapProvisioner returns a new instance of a map provisioner
type RemoveFunction ¶ added in v0.5.5
type RemoveFunction func(ctx context.Context, wl *gridtypes.WorkloadWithID) error
RemoveFunction simple decommission function
type SignatureRequirementField ¶ added in v0.5.5
type SignatureRequirementField struct {
SignatureRequirement gridtypes.SignatureRequirement
}
type Storage ¶ added in v0.5.5
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) }
Storage interface
type Twins ¶ added in v0.5.5
Twins is used to get twin public key
func NewSubstrateAdmins ¶ added in v0.5.5
NewSubstrateAdmins creates a substrate twins db that implements the provision.Users interface. but it also make sure the user is an admin
func NewSubstrateTwins ¶ added in v0.5.5
NewSubstrateTwins creates a substrate users db that implements the provision.Users interface.
type VersionField ¶ added in v0.5.5
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 |