Documentation ¶
Overview ¶
Package statemachine contains the state machine logic for a pipeline in the form of an acyclic graph
Index ¶
- type ActionNode
- func (n *ActionNode) Accept(v Visitor, traversalCtx *TraversalContext) error
- func (n *ActionNode) Cancel() error
- func (n *ActionNode) ChildrenNodes() []Node
- func (n *ActionNode) Copy() *ActionNode
- func (n *ActionNode) GetDependencies() []string
- func (n *ActionNode) GetInitialStatus() NodeStatus
- func (n *ActionNode) GetStatusChanges() []NodeStatusChange
- func (n *ActionNode) Parent() Node
- func (n *ActionNode) Path() string
- func (n *ActionNode) SetStatus(status NodeStatus) error
- func (n *ActionNode) Status() NodeStatus
- func (n *ActionNode) Type() NodeType
- type GetNodesInput
- type NewPipelineNodeInput
- type NewTaskNodeInput
- type Node
- type NodeStatus
- type NodeStatusChange
- type NodeType
- type PartialVisitor
- func (v *PartialVisitor) VisitForAction(_ *ActionNode, _ *TraversalContext) error
- func (v *PartialVisitor) VisitForAny(_ Node, _ *TraversalContext) error
- func (v *PartialVisitor) VisitForPipeline(_ *PipelineNode) error
- func (v *PartialVisitor) VisitForStage(_ *StageNode) error
- func (v *PartialVisitor) VisitForTask(_ *TaskNode, _ *TraversalContext) error
- type PipelineNode
- func (n *PipelineNode) Accept(v Visitor, traversalCtx *TraversalContext) error
- func (n *PipelineNode) AddStageNode(s *StageNode)
- func (n *PipelineNode) Cancel() error
- func (n *PipelineNode) ChildrenNodes() []Node
- func (n *PipelineNode) Copy() *PipelineNode
- func (n *PipelineNode) GetDependencies() []string
- func (n *PipelineNode) GetInitialStatus() NodeStatus
- func (n *PipelineNode) GetStatusChanges() []NodeStatusChange
- func (n *PipelineNode) Parent() Node
- func (n *PipelineNode) Path() string
- func (n *PipelineNode) SetStatus(status NodeStatus) error
- func (n *PipelineNode) Status() NodeStatus
- func (n *PipelineNode) Type() NodeType
- type PrettyPrintVisitor
- func (v *PrettyPrintVisitor) VisitForAction(action *ActionNode, traversalCtx *TraversalContext) error
- func (v *PrettyPrintVisitor) VisitForPipeline(pipeline *PipelineNode) error
- func (v *PrettyPrintVisitor) VisitForStage(stage *StageNode) error
- func (v *PrettyPrintVisitor) VisitForTask(task *TaskNode, _ *TraversalContext) error
- type SimpleTraverser
- type SimulatedTraverser
- type StageNode
- func (n *StageNode) Accept(v Visitor, traversalCtx *TraversalContext) error
- func (n *StageNode) AddNestedPipelineNode(p *PipelineNode)
- func (n *StageNode) AddTaskNode(t *TaskNode)
- func (n *StageNode) Cancel() error
- func (n *StageNode) ChildrenNodes() []Node
- func (n *StageNode) Copy() *StageNode
- func (n *StageNode) GetDependencies() []string
- func (n *StageNode) GetInitialStatus() NodeStatus
- func (n *StageNode) GetStatusChanges() []NodeStatusChange
- func (n *StageNode) Parent() Node
- func (n *StageNode) Path() string
- func (n *StageNode) SetStatus(status NodeStatus) error
- func (n *StageNode) Status() NodeStatus
- func (n *StageNode) Type() NodeType
- type StateMachine
- func (s *StateMachine) Copy() *StateMachine
- func (s *StateMachine) GetNode(path string) (Node, bool)
- func (s *StateMachine) GetNodes(input *GetNodesInput) ([]Node, error)
- func (s *StateMachine) GetPipelineNode() *PipelineNode
- func (s *StateMachine) GetStatusChanges() ([]NodeStatusChange, error)
- func (s *StateMachine) GetTraversalContextForNode(nodePath string) (*TraversalContext, error)
- func (s *StateMachine) Reset() error
- type TaskNode
- func (n *TaskNode) Accept(v Visitor, traversalCtx *TraversalContext) error
- func (n *TaskNode) Actions() []*ActionNode
- func (n *TaskNode) AddActionNode(a *ActionNode)
- func (n *TaskNode) Cancel() error
- func (n *TaskNode) ChildrenNodes() []Node
- func (n *TaskNode) Copy() *TaskNode
- func (n *TaskNode) GetDependencies() []string
- func (n *TaskNode) GetInitialStatus() NodeStatus
- func (n *TaskNode) GetStatusChanges() []NodeStatusChange
- func (n *TaskNode) Parent() Node
- func (n *TaskNode) Path() string
- func (n *TaskNode) SetStatus(status NodeStatus) error
- func (n *TaskNode) Status() NodeStatus
- func (n *TaskNode) Type() NodeType
- type TraversalContext
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionNode ¶
type ActionNode struct { Name string // contains filtered or unexported fields }
ActionNode represents a pipeline action
func NewActionNode ¶
func NewActionNode(path string, nodeName string, parent Node, status NodeStatus) *ActionNode
NewActionNode creates a new action node
func (*ActionNode) Accept ¶
func (n *ActionNode) Accept(v Visitor, traversalCtx *TraversalContext) error
Accept a visitor
func (*ActionNode) ChildrenNodes ¶
func (n *ActionNode) ChildrenNodes() []Node
ChildrenNodes returns a list of child nodes
func (*ActionNode) GetDependencies ¶
func (n *ActionNode) GetDependencies() []string
func (*ActionNode) GetInitialStatus ¶
func (n *ActionNode) GetInitialStatus() NodeStatus
func (*ActionNode) GetStatusChanges ¶
func (n *ActionNode) GetStatusChanges() []NodeStatusChange
func (*ActionNode) SetStatus ¶
func (n *ActionNode) SetStatus(status NodeStatus) error
func (*ActionNode) Status ¶
func (n *ActionNode) Status() NodeStatus
type GetNodesInput ¶
type GetNodesInput struct { Status *NodeStatus NodeTypes []NodeType }
GetNodesInput defines the input for GetNodes
type NewPipelineNodeInput ¶
type NewPipelineNodeInput struct { Parent Node Status NodeStatus Path string Dependencies []string ApprovalPending bool }
NewPipelineNodeInput is the input for creating a new pipeline node
type NewTaskNodeInput ¶
type NewTaskNodeInput struct { Parent Node Status *NodeStatus Path string Name string Dependencies []string ApprovalPending bool }
NewTaskNodeInput defines the input for creating a new task node
type Node ¶
type Node interface { Path() string Type() NodeType Status() NodeStatus Cancel() error GetStatusChanges() []NodeStatusChange GetDependencies() []string SetStatus(status NodeStatus) error Parent() Node ChildrenNodes() []Node GetInitialStatus() NodeStatus Accept(v Visitor, traversalCtx *TraversalContext) error // contains filtered or unexported methods }
Node represents a node in the pipeline graph
type NodeStatus ¶
type NodeStatus string
NodeStatus constant defines the possible states for a node in a pipeline
const ( CreatedNodeStatus NodeStatus = "CREATED" ApprovalPendingNodeStatus NodeStatus = "APPROVAL_PENDING" WaitingNodeStatus NodeStatus = "WAITING" ReadyNodeStatus NodeStatus = "READY" PendingNodeStatus NodeStatus = "PENDING" RunningNodeStatus NodeStatus = "RUNNING" FailedNodeStatus NodeStatus = "FAILED" SkippedNodeStatus NodeStatus = "SKIPPED" SucceededNodeStatus NodeStatus = "SUCCEEDED" CanceledNodeStatus NodeStatus = "CANCELED" CancelingNodeStatus NodeStatus = "CANCELING" )
NodeStatusConstants
func (NodeStatus) Equals ¶
func (n NodeStatus) Equals(s NodeStatus) bool
Equals returns true if the status is equal to the given status
func (NodeStatus) IsFinalStatus ¶
func (n NodeStatus) IsFinalStatus() bool
IsFinalStatus returns true if the status is a final status
func (NodeStatus) IsRetryableStatus ¶
func (n NodeStatus) IsRetryableStatus() bool
IsRetryableStatus returns true if status allows a node to be retried
type NodeStatusChange ¶
type NodeStatusChange struct { OldStatus NodeStatus NewStatus NodeStatus NodePath string NodeType NodeType }
NodeStatusChange represents a change in the status of a node
type PartialVisitor ¶
type PartialVisitor struct{}
PartialVisitor provides a noop implementation of the required visitor functions for visitors that only want to implement a subset of the functions
func (*PartialVisitor) VisitForAction ¶
func (v *PartialVisitor) VisitForAction(_ *ActionNode, _ *TraversalContext) error
VisitForAction visits an action node
func (*PartialVisitor) VisitForAny ¶
func (v *PartialVisitor) VisitForAny(_ Node, _ *TraversalContext) error
VisitForAny visits all nodes
func (*PartialVisitor) VisitForPipeline ¶
func (v *PartialVisitor) VisitForPipeline(_ *PipelineNode) error
VisitForPipeline visits a pipeline node
func (*PartialVisitor) VisitForStage ¶
func (v *PartialVisitor) VisitForStage(_ *StageNode) error
VisitForStage visits a stage node
func (*PartialVisitor) VisitForTask ¶
func (v *PartialVisitor) VisitForTask(_ *TaskNode, _ *TraversalContext) error
VisitForTask visits a task node
type PipelineNode ¶
type PipelineNode struct {
// contains filtered or unexported fields
}
PipelineNode represents a pipeline node
func NewPipelineNode ¶
func NewPipelineNode(input *NewPipelineNodeInput) *PipelineNode
NewPipelineNode creates a new pipeline node
func (*PipelineNode) Accept ¶
func (n *PipelineNode) Accept(v Visitor, traversalCtx *TraversalContext) error
Accept a visitor
func (*PipelineNode) AddStageNode ¶
func (n *PipelineNode) AddStageNode(s *StageNode)
AddStageNode adds a new stage node to the pipeline
func (*PipelineNode) ChildrenNodes ¶
func (n *PipelineNode) ChildrenNodes() []Node
ChildrenNodes returns a list of this nodes children
func (*PipelineNode) Copy ¶
func (n *PipelineNode) Copy() *PipelineNode
Copy returns a copy of the node
func (*PipelineNode) GetDependencies ¶
func (n *PipelineNode) GetDependencies() []string
GetDependencies returns the dependencies for this node
func (*PipelineNode) GetInitialStatus ¶
func (n *PipelineNode) GetInitialStatus() NodeStatus
GetInitialStatus returns the initial status of the node
func (*PipelineNode) GetStatusChanges ¶
func (n *PipelineNode) GetStatusChanges() []NodeStatusChange
func (*PipelineNode) SetStatus ¶
func (n *PipelineNode) SetStatus(status NodeStatus) error
SetStatus sets the node status
func (*PipelineNode) Status ¶
func (n *PipelineNode) Status() NodeStatus
type PrettyPrintVisitor ¶
type PrettyPrintVisitor struct { PartialVisitor // contains filtered or unexported fields }
PrettyPrintVisitor prints the state of each node in the pipeline graph
func (*PrettyPrintVisitor) VisitForAction ¶
func (v *PrettyPrintVisitor) VisitForAction(action *ActionNode, traversalCtx *TraversalContext) error
VisitForAction visits an action node
func (*PrettyPrintVisitor) VisitForPipeline ¶
func (v *PrettyPrintVisitor) VisitForPipeline(pipeline *PipelineNode) error
VisitForPipeline visits a pipeline node
func (*PrettyPrintVisitor) VisitForStage ¶
func (v *PrettyPrintVisitor) VisitForStage(stage *StageNode) error
VisitForStage visits a stage node
func (*PrettyPrintVisitor) VisitForTask ¶
func (v *PrettyPrintVisitor) VisitForTask(task *TaskNode, _ *TraversalContext) error
VisitForTask visits a task node
type SimpleTraverser ¶
type SimpleTraverser struct {
// contains filtered or unexported fields
}
SimpleTraverser will visit each node in the graph
func (*SimpleTraverser) Accept ¶
func (t *SimpleTraverser) Accept(v Visitor) error
Accept accepts a visitor
type SimulatedTraverser ¶
type SimulatedTraverser struct {
// contains filtered or unexported fields
}
SimulatedTraverser is a traverser that simulates a traversal of the pipeline graph in the order that the nodes would be executed in a real pipeline run
func NewSimulatedTraverser ¶
func NewSimulatedTraverser(stateMachine *StateMachine) *SimulatedTraverser
NewSimulatedTraverser creates a new simulated traverser
func (*SimulatedTraverser) Accept ¶
func (t *SimulatedTraverser) Accept(v Visitor) error
Accept accepts a visitor and visits each node in the graph
type StageNode ¶
type StageNode struct { Name string // contains filtered or unexported fields }
StageNode represents a stage in a pipeline
func NewStageNode ¶
func NewStageNode(path string, nodeName string, parent Node, status NodeStatus) *StageNode
NewStageNode creates a new stage node
func (*StageNode) Accept ¶
func (n *StageNode) Accept(v Visitor, traversalCtx *TraversalContext) error
Accept a visitor
func (*StageNode) AddNestedPipelineNode ¶
func (n *StageNode) AddNestedPipelineNode(p *PipelineNode)
AddNestedPipelineNode adds a nested pipeline
func (*StageNode) AddTaskNode ¶
AddTaskNode adds a task node
func (*StageNode) ChildrenNodes ¶
ChildrenNodes returns a list of this node's children
func (*StageNode) GetDependencies ¶
func (n *StageNode) GetDependencies() []string
func (*StageNode) GetInitialStatus ¶
func (n *StageNode) GetInitialStatus() NodeStatus
func (*StageNode) GetStatusChanges ¶
func (n *StageNode) GetStatusChanges() []NodeStatusChange
func (*StageNode) SetStatus ¶
func (n *StageNode) SetStatus(status NodeStatus) error
SetStatus sets the node status
func (*StageNode) Status ¶
func (n *StageNode) Status() NodeStatus
type StateMachine ¶
type StateMachine struct {
// contains filtered or unexported fields
}
StateMachine encapsulates pipeline state updates
func (*StateMachine) Copy ¶
func (s *StateMachine) Copy() *StateMachine
Copy creates a copy of the state machine
func (*StateMachine) GetNode ¶
func (s *StateMachine) GetNode(path string) (Node, bool)
GetNode returns a node by path
func (*StateMachine) GetNodes ¶
func (s *StateMachine) GetNodes(input *GetNodesInput) ([]Node, error)
GetNodes returns a list of nodes based on the provided node type and state
func (*StateMachine) GetPipelineNode ¶
func (s *StateMachine) GetPipelineNode() *PipelineNode
GetPipelineNode returns the pipeline node
func (*StateMachine) GetStatusChanges ¶
func (s *StateMachine) GetStatusChanges() ([]NodeStatusChange, error)
GetStatusChanges traverses the state machine and returns all status changes
func (*StateMachine) GetTraversalContextForNode ¶
func (s *StateMachine) GetTraversalContextForNode(nodePath string) (*TraversalContext, error)
GetTraversalContextForNode returns the traversal context for a given node
func (*StateMachine) Reset ¶
func (s *StateMachine) Reset() error
Reset resets the status of each node in the state machine to CreatedNodeStatus
type TaskNode ¶
type TaskNode struct { Name string // contains filtered or unexported fields }
TaskNode represents a task in a pipeline
func NewTaskNode ¶
func NewTaskNode(input *NewTaskNodeInput) *TaskNode
NewTaskNode creates a new task node
func (*TaskNode) Accept ¶
func (n *TaskNode) Accept(v Visitor, traversalCtx *TraversalContext) error
Accept a visitor
func (*TaskNode) Actions ¶
func (n *TaskNode) Actions() []*ActionNode
Actions returns a list of actions for this task
func (*TaskNode) AddActionNode ¶
func (n *TaskNode) AddActionNode(a *ActionNode)
AddActionNode adds a new action node
func (*TaskNode) ChildrenNodes ¶
ChildrenNodes returns a list of this nodes children
func (*TaskNode) GetDependencies ¶
GetDependencies returns the dependencies for this node.
func (*TaskNode) GetInitialStatus ¶
func (n *TaskNode) GetInitialStatus() NodeStatus
GetInitialStatus returns the initial status of the node
func (*TaskNode) GetStatusChanges ¶
func (n *TaskNode) GetStatusChanges() []NodeStatusChange
func (*TaskNode) SetStatus ¶
func (n *TaskNode) SetStatus(status NodeStatus) error
SetStatus sets the node status
func (*TaskNode) Status ¶
func (n *TaskNode) Status() NodeStatus
type TraversalContext ¶
type TraversalContext struct {
// contains filtered or unexported fields
}
TraversalContext tracks state as a visitor traverses the pipeline graph
func (*TraversalContext) Copy ¶
func (t *TraversalContext) Copy() *TraversalContext
Copy creates a copy of the traversal context
func (*TraversalContext) VisitedActions ¶
func (t *TraversalContext) VisitedActions() []*ActionNode
VisitedActions returns a list of visited actions
type Visitor ¶
type Visitor interface { VisitForPipeline(pipeline *PipelineNode) error VisitForStage(stage *StageNode) error VisitForTask(task *TaskNode, traversalCtx *TraversalContext) error VisitForAction(action *ActionNode, traversalCtx *TraversalContext) error VisitForAny(node Node, traversalCtx *TraversalContext) error }
Visitor is used to visit each node in the pipeline graph