Documentation ¶
Index ¶
- Constants
- Variables
- func ActionID(taskID, componentSlug string, idx int) string
- type ActionStateMachine
- func (a *ActionStateMachine) ActionID() string
- func (a *ActionStateMachine) AddStateTransitionDocumentation(stateDocumentation []sw.StateDoc, ...)
- func (a *ActionStateMachine) ConditionalFault(task *model.Task, transitionType sw.TransitionType) error
- func (a *ActionStateMachine) DescribeAsJSON() ([]byte, error)
- func (a *ActionStateMachine) Run(ctx context.Context, action *model.Action, tctx *HandlerContext) error
- func (a *ActionStateMachine) SetTransitionOrder(transitions []sw.TransitionType)
- func (a *ActionStateMachine) TransitionOrder() []sw.TransitionType
- func (a *ActionStateMachine) TransitionsCompleted() []sw.TransitionType
- type ActionStateMachines
- type ErrAction
- type HandlerContext
- type MockTaskHandler
- func (h *MockTaskHandler) ConditionalFault(_ *HandlerContext, _ *model.Task, _ sw.TransitionType) error
- func (h *MockTaskHandler) Init(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) Plan(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) PublishStatus(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) Query(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) Run(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) TaskFailed(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) TaskSuccessful(_ sw.StateSwitch, _ sw.TransitionArgs) error
- func (h *MockTaskHandler) ValidatePlan(_ sw.StateSwitch, _ sw.TransitionArgs) (bool, error)
- type Publisher
Constants ¶
const ( // state for successful actions StateActionSuccessful sw.State = sw.State(model.StateSucceeded) // state for failed actions StateActionFailed sw.State = sw.State(model.StateFailed) )
Variables ¶
var ( // ErrActionTransition is returned when an action transition fails. ErrActionTransition = errors.New("error in action transition") // ErrActionTypeAssertion is returned when an action handler receives an unexpected type. ErrActionTypeAssertion = errors.New("error asserting the Action type") )
var ( ErrInvalidtaskHandlerContext = errors.New("expected a HandlerContext{} type") ErrInvalidTransitionHandler = errors.New("expected a valid transitionHandler{} type") )
Functions ¶
Types ¶
type ActionStateMachine ¶
type ActionStateMachine struct {
// contains filtered or unexported fields
}
ActionStateMachine is an object holding the action statemachine. action statemachines are sub-statemachines of a Task statemachine.
A Action statemachine corresponds to a task action which is to install a planned firmware on a device component.
func NewActionStateMachine ¶
func NewActionStateMachine(actionID string, transitionRules []sw.TransitionRule) (*ActionStateMachine, error)
NewActionStateMachine initializes an action state machine to install firmware on a component.
func (*ActionStateMachine) ActionID ¶
func (a *ActionStateMachine) ActionID() string
ActionID returns the action this statemachine was planned for.
func (*ActionStateMachine) AddStateTransitionDocumentation ¶
func (a *ActionStateMachine) AddStateTransitionDocumentation(stateDocumentation []sw.StateDoc, transitionDocumentation []sw.TransitionTypeDoc)
AddStateTransitionDocumentation adds the given state, transition documentation to the action state machine
func (*ActionStateMachine) ConditionalFault ¶ added in v0.2.6
func (a *ActionStateMachine) ConditionalFault(task *model.Task, transitionType sw.TransitionType) error
ConditionalFault is invoked before each transition to induce a fault if specified.
func (*ActionStateMachine) DescribeAsJSON ¶
func (a *ActionStateMachine) DescribeAsJSON() ([]byte, error)
DescribeAsJSON returns a JSON output describing the action statemachine.
func (*ActionStateMachine) Run ¶
func (a *ActionStateMachine) Run(ctx context.Context, action *model.Action, tctx *HandlerContext) error
Run executes the transitions in the action statemachine while handling errors returned from any failed actions.
func (*ActionStateMachine) SetTransitionOrder ¶
func (a *ActionStateMachine) SetTransitionOrder(transitions []sw.TransitionType)
SetTransitionOrder sets the expected order of transition execution.
func (*ActionStateMachine) TransitionOrder ¶
func (a *ActionStateMachine) TransitionOrder() []sw.TransitionType
TransitionOrder returns the current order of transition execution.
func (*ActionStateMachine) TransitionsCompleted ¶
func (a *ActionStateMachine) TransitionsCompleted() []sw.TransitionType
TransitionsCompleted returns the transitions that completed successfully.
type ActionStateMachines ¶
type ActionStateMachines []*ActionStateMachine
ActionStateMachines is an ordered list of actions planned
func (ActionStateMachines) ByActionID ¶
func (a ActionStateMachines) ByActionID(id string) *ActionStateMachine
ByActionID returns the Action statemachine identified by id.
type ErrAction ¶
type ErrAction struct {
// contains filtered or unexported fields
}
ErrAction is an error type containing information on the Action failure.
type HandlerContext ¶
type HandlerContext struct { // ctx is the parent cancellation context Ctx context.Context // Task is the task being executed. Task *model.Task // Publisher provides the Publish method to publish Task status changes. Publisher Publisher // err is set when a transition fails to complete its transitions in run() // the err value is then passed into the task information // as the state machine transitions into a failed state. Err error // DeviceQueryor is the interface to query target device under firmware install. DeviceQueryor model.DeviceQueryor // Store is the asset inventory store. Store store.Repository // Data is an arbitrary key values map available to all task, action handler methods. Data map[string]string // Asset holds attributes about the device under firmware install. Asset *model.Asset // FacilityCode limits the task handler to Assets in the given facility. FacilityCode string // Logger is the task, action handler logger. Logger *logrus.Entry // WorkerID is the identifier for the worker executing this task. WorkerID registry.ControllerID // ActionStateMachines are sub-statemachines of this Task // each firmware applicable has a Action statemachine that is // executed as part of this task. ActionStateMachines ActionStateMachines // Dryrun skips any disruptive actions on the device - power on/off, bmc resets, firmware installs, // the task and its actions run as expected, and the device state in the inventory is updated as well, // although the firmware is not installed. // // It is upto the Action handler implementations to ensure the dry run works as described. Dryrun bool // LastRev is the last revision of the status data for this task stored in NATS KV LastRev uint64 }
HandlerContext holds references to objects required to complete firmware install task and action transitions.
The HandlerContext is passed to every transition handler.
type MockTaskHandler ¶
type MockTaskHandler struct{}
MockTaskHandler implements the TaskTransitioner interface
func (*MockTaskHandler) ConditionalFault ¶
func (h *MockTaskHandler) ConditionalFault(_ *HandlerContext, _ *model.Task, _ sw.TransitionType) error
func (*MockTaskHandler) Init ¶
func (h *MockTaskHandler) Init(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) Plan ¶
func (h *MockTaskHandler) Plan(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) PublishStatus ¶
func (h *MockTaskHandler) PublishStatus(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) Query ¶
func (h *MockTaskHandler) Query(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) Run ¶
func (h *MockTaskHandler) Run(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) TaskFailed ¶
func (h *MockTaskHandler) TaskFailed(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) TaskSuccessful ¶
func (h *MockTaskHandler) TaskSuccessful(_ sw.StateSwitch, _ sw.TransitionArgs) error
func (*MockTaskHandler) ValidatePlan ¶
func (h *MockTaskHandler) ValidatePlan(_ sw.StateSwitch, _ sw.TransitionArgs) (bool, error)
type Publisher ¶
type Publisher interface {
Publish(ctx *HandlerContext)
}
Publisher defines methods to publish task information.