machines

package
v0.0.0-...-9e9d5e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInvalidTransitionCode      = "1541"
	ErrInvalidTransitionEventCode = "1542"
	ErrInititalizeK8sMachineCode  = "1543"
	ErrAssetMachineCtxCode        = "1544"
	ErrInvalidTypeCode            = "1551"
)
View Source
const (
	Discovery  EventType = "discovery"
	Register   EventType = "register"
	Connect    EventType = "connect"
	Disconnect EventType = "disconnect"
	Ignore     EventType = "ignore"
	NotFound   EventType = "not found"
	Delete     EventType = "delete"
	NoOp       EventType = "noop"
	Exit       EventType = "exit"

	DISCOVERED   StateType = "discovered"
	REGISTERED   StateType = "registered"
	CONNECTED    StateType = "connected"
	IGNORED      StateType = "ignored"
	MAINTENANCE  StateType = "maintenance"
	DISCONNECTED StateType = "disconnected"
	DELETED      StateType = "deleted"
	NOTFOUND     StateType = "not found"

	Init EventType = "initialize"
)

Variables

This section is empty.

Functions

func ErrAssertMachineCtx

func ErrAssertMachineCtx(err error) error

func ErrInititalizeK8sMachine

func ErrInititalizeK8sMachine(err error) error

func ErrInvalidTransition

func ErrInvalidTransition(from, to StateType) error

func ErrInvalidTransitionEvent

func ErrInvalidTransitionEvent(from StateType, event EventType) error

func ErrInvalidType

func ErrInvalidType(err error) error

Types

type Action

type Action interface {

	// Used as guards/prerequisites checks and actions to be performed when the machine enters a given state.
	ExecuteOnEntry(context context.Context, machinectx interface{}, data interface{}) (EventType, *events.Event, error)

	Execute(context context.Context, machinectx interface{}, data interface{}) (EventType, *events.Event, error)

	// Used for cleanup actions to perform when the machine exits a given state
	ExecuteOnExit(context context.Context, machinectx interface{}, data interface{}) (EventType, *events.Event, error)
}

Action to be executed in a given state.

type ConnectionToStateMachineInstanceTracker

type ConnectionToStateMachineInstanceTracker struct {
	ConnectToInstanceMap map[uuid.UUID]*StateMachine
	// contains filtered or unexported fields
}

func (*ConnectionToStateMachineInstanceTracker) Add

func (*ConnectionToStateMachineInstanceTracker) Get

func (*ConnectionToStateMachineInstanceTracker) Remove

type DefaultConnectAction

type DefaultConnectAction struct{}

func (*DefaultConnectAction) Execute

func (da *DefaultConnectAction) Execute(ctx context.Context, machineCtx interface{}, data interface{}) (EventType, *events.Event, error)

func (*DefaultConnectAction) ExecuteOnEntry

func (da *DefaultConnectAction) ExecuteOnEntry(ctx context.Context, machineCtx interface{}, data interface{}) (EventType, *events.Event, error)

func (*DefaultConnectAction) ExecuteOnExit

func (da *DefaultConnectAction) ExecuteOnExit(ctx context.Context, machineCtx interface{}, data interface{}) (EventType, *events.Event, error)

type EventType

type EventType string

Represents an event in the system/machine

type Events

type Events map[EventType]StateType

Represents the mapping between event and the next state in the event's response

type Payload

type Payload struct {
	Connection connections.Connection
	Credential models.Credential
}

type State

type State struct {
	Events Events
	Action Action
}

func Connected

func Connected() State

func Disconnected

func Disconnected() State

func Discovered

func Discovered() State

func Initial

func Initial() State

func Registered

func Registered() State

func (*State) RegisterAction

func (s *State) RegisterAction(action Action) *State

func (*State) RegisterEvent

func (s *State) RegisterEvent(eventType EventType, stateType StateType) *State

type StateMachine

type StateMachine struct {
	// ID to trace the events originated from the machine, also used in logs
	ID uuid.UUID

	UserID uuid.UUID

	// Given name for the machine, used in logs to track issues
	Name string

	// Configuration of states managed by the machine
	States States

	// Represent the previous state of the machine
	PreviousState StateType

	// The current state of the machine
	CurrentState StateType

	// The initial state at which machine gets initialized
	InitialState StateType

	// Machine specific parameters/context.
	// Provided at initialization of the machine.
	Context interface{}

	Log logger.Handler

	Provider models.Provider
	// contains filtered or unexported fields
}

func New

func New(initialState StateType, ID string, userID uuid.UUID, log logger.Handler, mtype string) (*StateMachine, error)

func (*StateMachine) AssignProvider

func (sm *StateMachine) AssignProvider(provider models.Provider) *StateMachine

func (*StateMachine) ResetState

func (sm *StateMachine) ResetState()

func (*StateMachine) SendEvent

func (sm *StateMachine) SendEvent(ctx context.Context, eventType EventType, payload interface{}) (*events.Event, error)

Returns events.Event and error. The func invoking the SendEvent should handle the error and publish the event. wherever possible use the userID and systemID from context as the events can be created from other comps or actors and not only user actors. In cases when the event is received as part of some other event and not explicitly created by an actor, use the useID and systemID of the actor who initially invoked the machine.

func (*StateMachine) Start

func (sm *StateMachine) Start(ctx context.Context, machinectx interface{}, log logger.Handler, init connections.InitFunc) (*events.Event, error)

type StateType

type StateType string

Represents an state in the system/machine

var (
	DefaultState StateType = ""
	InitialState StateType = "initialized"
)

type States

type States map[StateType]State

Represents mapping between state name and the state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL