instance

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpStart   = iota // 0
	OpResume         // 1
	OpRestart        // 2
)

Variables

This section is empty.

Functions

func ApplyExecOptions

func ApplyExecOptions(instance *Instance, execOptions *ExecOptions)

ApplyExecOptions applies any execution options to the flow instance

func DefaultConfig

func DefaultConfig() *util.ServiceConfig

func NewFixedTaskScope

func NewFixedTaskScope(refAttrs map[string]*data.Attribute, task *definition.Task, isInput bool) data.Scope

NewFixedTaskScope creates a FixedTaskScope

func NewWorkingDataScope

func NewWorkingDataScope(parentScope data.Scope, workingData map[string]*data.Attribute) data.Scope

NewFixedTaskScope creates a FixedTaskScope

Types

type ActionCtx

type ActionCtx struct {
	// contains filtered or unexported fields
}

func (*ActionCtx) GetResolver

func (ac *ActionCtx) GetResolver() data.Resolver

func (*ActionCtx) ID

func (ac *ActionCtx) ID() string

func (*ActionCtx) InstanceMetadata

func (ac *ActionCtx) InstanceMetadata() *action.ConfigMetadata

func (*ActionCtx) Ref

func (ac *ActionCtx) Ref() string

func (*ActionCtx) Reply

func (ac *ActionCtx) Reply(replyData map[string]*data.Attribute, err error)

func (*ActionCtx) Return

func (ac *ActionCtx) Return(returnData map[string]*data.Attribute, err error)

func (*ActionCtx) WorkingData

func (ac *ActionCtx) WorkingData() data.Scope

type ActivityEvalError

type ActivityEvalError struct {
	// contains filtered or unexported fields
}

func NewActivityEvalError

func NewActivityEvalError(taskName string, errorType string, errorText string) *ActivityEvalError

func (*ActivityEvalError) Error

func (e *ActivityEvalError) Error() string

func (*ActivityEvalError) TaskName

func (e *ActivityEvalError) TaskName() string

func (*ActivityEvalError) Type

func (e *ActivityEvalError) Type() string

type AttributeChange

type AttributeChange struct {
	ChgType   ChgType
	Attribute *data.Attribute
}

AttributeChange represents a change to an Attribute

type ChgType

type ChgType int

ChgType denotes the type of change for an object in an instance

const (
	// CtAdd denotes an addition
	CtAdd ChgType = 1
	// CtUpd denotes an update
	CtUpd ChgType = 2
	// CtDel denotes an deletion
	CtDel ChgType = 3
)

type ExecOptions

type ExecOptions struct {
	Patch       *support.Patch
	Interceptor *support.Interceptor
}

ExecOptions are optional Patch & Interceptor to be used during instance execution

type ExecType

type ExecType int

ExecType is the type of execution to perform

const (
	// EtEval denoted the Eval execution type
	EtEval ExecType = 10

	// EtPostEval denoted the PostEval execution type
	EtPostEval ExecType = 20
)

type FixedTaskScope

type FixedTaskScope struct {
	// contains filtered or unexported fields
}

FixedTaskScope is scope restricted by the set of reference attrs and backed by the specified Task

func (*FixedTaskScope) GetAttr

func (s *FixedTaskScope) GetAttr(attrName string) (attr *data.Attribute, exists bool)

GetAttr implements Scope.GetAttr

func (*FixedTaskScope) SetAttrValue

func (s *FixedTaskScope) SetAttrValue(attrName string, value interface{}) error

SetAttrValue implements Scope.SetAttrValue

type IDGenerator

type IDGenerator interface {
	//NewFlowInstanceID generate a new instance ID
	NewFlowInstanceID() string
}

IDGenerator generates IDs for flow instances

type IDResponse

type IDResponse struct {
	ID string `json:"id"`
}

IDResponse is a response object consists of an ID

type Instance

type Instance struct {
	FlowURI     string
	Flow        *definition.Definition
	RootTaskEnv *TaskEnv
	EhTaskEnv   *TaskEnv
	FlowModel   *model.FlowModel
	Attrs       map[string]*data.Attribute
	Patch       *support.Patch
	Interceptor *support.Interceptor

	WorkItemQueue *util.SyncQueue //todo: change to faster non-threadsafe queue

	ChangeTracker *InstanceChangeTracker `json:"-"`
	// contains filtered or unexported fields
}

Instance is a structure for representing an instance of a Flow

func New

func New(instanceID string, flowURI string, flow *definition.Definition, flowModel *model.FlowModel) *Instance

New creates a new Flow Instance from the specified Flow

func (*Instance) ActionContext

func (pi *Instance) ActionContext() action.Context

func (*Instance) AddAttr

func (pi *Instance) AddAttr(attrName string, attrType data.Type, value interface{}) *data.Attribute

AddAttr add a new attribute to the instance

func (*Instance) DoStep

func (pi *Instance) DoStep() bool

DoStep performs a single execution 'step' of the Flow Instance

func (*Instance) FlowDefinition

func (pi *Instance) FlowDefinition() *definition.Definition

FlowDefinition returns the Flow that the instance is of

func (*Instance) GetAttr

func (pi *Instance) GetAttr(attrName string) (value *data.Attribute, exists bool)

GetAttr implements data.Scope.GetAttr

func (*Instance) GetChanges

func (pi *Instance) GetChanges() *InstanceChangeTracker

GetChanges returns the Change Tracker object

func (*Instance) GetReturnData

func (pi *Instance) GetReturnData() (map[string]*data.Attribute, error)

func (*Instance) HandleGlobalError

func (pi *Instance) HandleGlobalError()

HandleGlobalError handles instance errors

func (*Instance) ID

func (pi *Instance) ID() string

ID returns the ID of the Flow Instance

func (*Instance) InitActionContext

func (pi *Instance) InitActionContext(config *action.Config, handler action.ResultHandler)

InitActionContext initialize the action context, should be initialized before execution

func (*Instance) MarshalJSON

func (pi *Instance) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default MarshalJSON for FlowInstance

func (*Instance) Name

func (pi *Instance) Name() string

Name implements activity.FlowDetails.Name method

func (*Instance) ReplyHandler

func (pi *Instance) ReplyHandler() activity.ReplyHandler

ReplyHandler returns the reply handler for the instance

func (*Instance) ResetChanges

func (pi *Instance) ResetChanges()

ResetChanges resets an changes that were being tracked

func (*Instance) Restart

func (pi *Instance) Restart(id string, provider provider.Provider)

Restart indicates that this FlowInstance was restarted

func (*Instance) SetAttrValue

func (pi *Instance) SetAttrValue(attrName string, value interface{}) error

SetAttrValue implements api.Scope.SetAttrValue

func (*Instance) SetFlowProvider

func (pi *Instance) SetFlowProvider(provider provider.Provider)

SetFlowProvider sets the process.Provider that the instance should use

func (*Instance) SetState

func (pi *Instance) SetState(state int)

SetState sets the state indicator of the Flow Instance

func (*Instance) Start

func (pi *Instance) Start(startAttrs []*data.Attribute) bool

Start will start the Flow Instance, returns a boolean indicating if it was able to start

func (*Instance) State

func (pi *Instance) State() int

State returns the state indicator of the Flow Instance

func (*Instance) Status

func (pi *Instance) Status() Status

Status returns the current status of the Flow Instance

func (*Instance) StepID

func (pi *Instance) StepID() int

StepID returns the current step ID of the Flow Instance

func (*Instance) UnmarshalJSON

func (pi *Instance) UnmarshalJSON(d []byte) error

UnmarshalJSON overrides the default UnmarshalJSON for FlowInstance

func (*Instance) UpdateAttrs

func (pi *Instance) UpdateAttrs(attrs []*data.Attribute)

UpdateAttrs updates the attributes of the Flow Instance

type InstanceChange

type InstanceChange struct {
	State       int
	Status      Status
	Changes     int
	AttrChanges []*AttributeChange
}

InstanceChange represents a change to the instance

type InstanceChangeTracker

type InstanceChangeTracker struct {
	// contains filtered or unexported fields
}

InstanceChangeTracker is used to track all changes to an instance

func NewInstanceChangeTracker

func NewInstanceChangeTracker() *InstanceChangeTracker

NewInstanceChangeTracker creates an InstanceChangeTracker

func (*InstanceChangeTracker) AttrChange

func (ict *InstanceChangeTracker) AttrChange(chgType ChgType, attribute *data.Attribute)

AttrChange is called to track a status change of an Attribute

func (*InstanceChangeTracker) MarshalJSON

func (ict *InstanceChangeTracker) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default MarshalJSON for InstanceChangeTracker

func (*InstanceChangeTracker) ResetChanges

func (ict *InstanceChangeTracker) ResetChanges()

ResetChanges is used to reset any tracking data stored on instance objects

func (*InstanceChangeTracker) SetState

func (ict *InstanceChangeTracker) SetState(state int)

SetState is called to track a state change on an instance

func (*InstanceChangeTracker) SetStatus

func (ict *InstanceChangeTracker) SetStatus(status Status)

SetStatus is called to track a status change on an instance

type LinkData

type LinkData struct {
	// contains filtered or unexported fields
}

LinkData represents data associated with an instance of a Link

func NewLinkData

func NewLinkData(taskEnv *TaskEnv, link *definition.Link) *LinkData

NewLinkData creates a LinkData for the specified link in the specified task environment

func (ld *LinkData) Link() *definition.Link

Link returns the Link associated with ld context

func (*LinkData) MarshalJSON

func (ld *LinkData) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default MarshalJSON for LinkData

func (*LinkData) SetState

func (ld *LinkData) SetState(state int)

SetState sets the current state indicator for the LinkData

func (*LinkData) State

func (ld *LinkData) State() int

State returns the current state indicator for the LinkData

func (*LinkData) UnmarshalJSON

func (ld *LinkData) UnmarshalJSON(d []byte) error

UnmarshalJSON overrides the default UnmarshalJSON for LinkData

type LinkDataChange

type LinkDataChange struct {
	ChgType  ChgType
	ID       int
	LinkData *LinkData
}

LinkDataChange represents a change to a LinkData

type RecordSnapshotReq

type RecordSnapshotReq struct {
	ID     int    `json:"id"`
	FlowID string `json:"flowID"`
	State  int    `json:"state"`
	Status int    `json:"status"`

	SnapshotData *Instance `json:"snapshotData"`
}

RecordSnapshotReq serializable representation of the RecordSnapshot request

type RecordStepReq

type RecordStepReq struct {
	ID     int    `json:"id"`
	FlowID string `json:"flowID"`
	State  int    `json:"state"`
	Status int    `json:"status"`

	StepData *InstanceChangeTracker `json:"stepData"`
}

RecordStepReq serializable representation of the RecordStep request

type RemoteStateRecorder

type RemoteStateRecorder struct {
	// contains filtered or unexported fields
}

RemoteStateRecorder is an implementation of StateRecorder service that can access flows via URI

func NewRemoteStateRecorder

func NewRemoteStateRecorder(config *util.ServiceConfig) *RemoteStateRecorder

NewRemoteStateRecorder creates a new RemoteStateRecorder

func (*RemoteStateRecorder) Enabled

func (sr *RemoteStateRecorder) Enabled() bool

func (*RemoteStateRecorder) Name

func (sr *RemoteStateRecorder) Name() string

func (*RemoteStateRecorder) RecordSnapshot

func (sr *RemoteStateRecorder) RecordSnapshot(instance *Instance)

RecordSnapshot implements instance.StateRecorder.RecordSnapshot

func (*RemoteStateRecorder) RecordStep

func (sr *RemoteStateRecorder) RecordStep(instance *Instance)

RecordStep implements instance.StateRecorder.RecordStep

func (*RemoteStateRecorder) Start

func (sr *RemoteStateRecorder) Start() error

Start implements util.Managed.Start()

func (*RemoteStateRecorder) Stop

func (sr *RemoteStateRecorder) Stop() error

Stop implements util.Managed.Stop()

type RunOptions

type RunOptions struct {
	Op           int
	ReturnID     bool
	FlowURI      string
	InitialState *Instance
	ExecOptions  *ExecOptions
}

RunOptions the options when running a FlowAction

type SimpleReplyHandler

type SimpleReplyHandler struct {
	// contains filtered or unexported fields
}

SimpleReplyHandler is a simple ReplyHandler that is pass-thru to the action ResultHandler

func (*SimpleReplyHandler) Reply

func (rh *SimpleReplyHandler) Reply(code int, replyData interface{}, err error)

Reply implements ReplyHandler.Reply

type StateRecorder

type StateRecorder interface {
	// RecordSnapshot records a Snapshot of the FlowInstance
	RecordSnapshot(instance *Instance)

	// RecordStep records the changes for the current Step of the Flow Instance
	RecordStep(instance *Instance)
}

StateRecorder is the interface that describes a service that can record snapshots and steps of a Flow Instance

type Status

type Status int

Status is value that indicates the status of a Flow Instance

const (
	// StatusNotStarted indicates that the FlowInstance has not started
	StatusNotStarted Status = 0

	// StatusActive indicates that the FlowInstance is active
	StatusActive Status = 100

	// StatusCompleted indicates that the FlowInstance has been completed
	StatusCompleted Status = 500

	// StatusCancelled indicates that the FlowInstance has been cancelled
	StatusCancelled Status = 600

	// StatusFailed indicates that the FlowInstance has failed
	StatusFailed Status = 700
)

type TaskData

type TaskData struct {
	// contains filtered or unexported fields
}

TaskData represents data associated with an instance of a Task

func NewTaskData

func NewTaskData(taskEnv *TaskEnv, task *definition.Task) *TaskData

NewTaskData creates a TaskData for the specified task in the specified task environment

func (*TaskData) ActionContext

func (td *TaskData) ActionContext() action.Context

FlowDetails implements activity.Context.FlowName method

func (*TaskData) AddWorkingData

func (td *TaskData) AddWorkingData(attr *data.Attribute)

func (*TaskData) ChildTaskInsts

func (td *TaskData) ChildTaskInsts() (taskInsts []model.TaskInst, hasChildTasks bool)

ChildTaskInsts implements activity.ActivityContext.ChildTaskInsts method

func (*TaskData) EnterChildren

func (td *TaskData) EnterChildren(taskEntries []*model.TaskEntry)

EnterChildren implements activity.ActivityContext.EnterChildren method

func (*TaskData) EnterLeadingChildren

func (td *TaskData) EnterLeadingChildren(enterCode int)

EnterLeadingChildren implements activity.ActivityContext.EnterLeadingChildren method

func (*TaskData) EvalActivity

func (td *TaskData) EvalActivity() (done bool, evalErr error)

EvalActivity implements activity.ActivityContext.EvalActivity method

func (td *TaskData) EvalLink(link *definition.Link) (result bool, err error)

EvalLink implements activity.ActivityContext.EvalLink method

func (*TaskData) Failed

func (td *TaskData) Failed(err error)

Failed marks the Activity as failed

func (*TaskData) FlowDetails

func (td *TaskData) FlowDetails() activity.FlowDetails

FlowDetails implements activity.Context.FlowName method

func (td *TaskData) FromInstLinks() []model.LinkInst

FromInstLinks implements model.TaskContext.FromInstLinks

func (*TaskData) GetInput

func (td *TaskData) GetInput(name string) interface{}

GetInput implements activity.Context.GetInput

func (*TaskData) GetOutput

func (td *TaskData) GetOutput(name string) interface{}

GetOutput implements activity.Context.GetOutput

func (*TaskData) GetSetting

func (td *TaskData) GetSetting(setting string) (value interface{}, exists bool)

func (*TaskData) GetWorkingData

func (td *TaskData) GetWorkingData(key string) (*data.Attribute, bool)

func (*TaskData) HasActivity

func (td *TaskData) HasActivity() bool

HasActivity implements activity.ActivityContext.HasActivity method

func (*TaskData) HasAttrs

func (td *TaskData) HasAttrs() bool

HasAttrs indicates if the task has attributes

func (*TaskData) HasWorkingData

func (td *TaskData) HasWorkingData() bool

func (*TaskData) InputScope

func (td *TaskData) InputScope() data.Scope

InputScope get the InputScope of the task instance

func (*TaskData) MarshalJSON

func (td *TaskData) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default MarshalJSON for TaskData

func (*TaskData) OutputScope

func (td *TaskData) OutputScope() data.Scope

OutputScope get the InputScope of the task instance

func (*TaskData) SetOutput

func (td *TaskData) SetOutput(name string, value interface{})

SetOutput implements activity.Context.SetOutput

func (*TaskData) SetState

func (td *TaskData) SetState(state int)

SetState implements flow.TaskContext.SetState

func (*TaskData) State

func (td *TaskData) State() int

State implements flow.TaskContext.GetState

func (*TaskData) Task

func (td *TaskData) Task() *definition.Task

Task implements model.TaskContext.Task, by returning the Task associated with this TaskData object

func (*TaskData) TaskName

func (td *TaskData) TaskName() string

TaskName implements activity.Context.TaskName method

func (td *TaskData) ToInstLinks() []model.LinkInst

ToInstLinks implements model.TaskContext.ToInstLinks,

func (*TaskData) UnmarshalJSON

func (td *TaskData) UnmarshalJSON(d []byte) error

UnmarshalJSON overrides the default UnmarshalJSON for TaskData

func (*TaskData) UpdateWorkingData

func (td *TaskData) UpdateWorkingData(key string, value interface{}) error

type TaskDataChange

type TaskDataChange struct {
	ChgType  ChgType
	ID       string
	TaskData *TaskData
}

TaskDataChange represents a change to a TaskData

type TaskEnv

type TaskEnv struct {
	ID        int
	Task      *definition.Task
	Instance  *Instance
	ParentEnv *TaskEnv

	TaskDatas map[string]*TaskData
	LinkDatas map[int]*LinkData
	// contains filtered or unexported fields
}

TaskEnv is a structure that describes the execution environment for a set of tasks

func (*TaskEnv) FindOrCreateLinkData

func (te *TaskEnv) FindOrCreateLinkData(link *definition.Link) (linkData *LinkData, created bool)

FindOrCreateLinkData finds an existing LinkData or creates ones if not found for the specified link the task environment

func (*TaskEnv) FindOrCreateTaskData

func (te *TaskEnv) FindOrCreateTaskData(task *definition.Task) (taskData *TaskData, created bool)

FindOrCreateTaskData finds an existing TaskData or creates ones if not found for the specified task the task environment

func (*TaskEnv) MarshalJSON

func (te *TaskEnv) MarshalJSON() ([]byte, error)

MarshalJSON overrides the default MarshalJSON for TaskEnv

func (*TaskEnv) NewTaskData

func (te *TaskEnv) NewTaskData(task *definition.Task) *TaskData

NewTaskData creates a new TaskData object

func (*TaskEnv) UnmarshalJSON

func (te *TaskEnv) UnmarshalJSON(data []byte) error

UnmarshalJSON overrides the default UnmarshalJSON for TaskEnv

type WorkItem

type WorkItem struct {
	ID       int       `json:"id"`
	TaskData *TaskData `json:"-"`
	ExecType ExecType  `json:"execType"`
	EvalCode int       `json:"code"`

	TaskID string `json:"taskID"` //for now need for ser

}

WorkItem describes an item of work (event for a Task) that should be executed on Step

func NewWorkItem

func NewWorkItem(id int, taskData *TaskData, execType ExecType, evalCode int) *WorkItem

NewWorkItem constructs a new WorkItem for the specified TaskData

type WorkItemQueueChange

type WorkItemQueueChange struct {
	ChgType  ChgType
	ID       int
	WorkItem *WorkItem
}

WorkItemQueueChange represents a change in the WorkItem Queue

type WorkingDataScope

type WorkingDataScope struct {
	// contains filtered or unexported fields
}

WorkingDataScope is scope restricted by the set of reference attrs and backed by the specified Task

func (*WorkingDataScope) GetAttr

func (s *WorkingDataScope) GetAttr(attrName string) (attr *data.Attribute, exists bool)

GetAttr implements Scope.GetAttr

func (*WorkingDataScope) SetAttrValue

func (s *WorkingDataScope) SetAttrValue(attrName string, value interface{}) error

SetAttrValue implements Scope.SetAttrValue

Jump to

Keyboard shortcuts

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