Overview
A process flow is a declarative model of a set of activities that are to be exposed (published) by the fabric. The model contains the details of how the activities are to be executed by the fabric when the process flow is called. The process flow defines one or more states which represent activities (or actions) that the process flow performs when it is invoked. Each state declares its action (which can be a method of a task, a method of a component, or a nested process flow) that the fabric performs during the state, and one or more transitions arcs, one of which is selected based on the outcome of the action. The set of states and arcs declare a finite state machine that can be executed by the fabric when the process flow is invoked.
Each process flow is defined in XML in a single text file. Note: the ordering of child elements within a parent element is enforced.
Executing Process Flows
When the fabric executes a process flow, it first locates a volunteer (a task service) on which it will run the action (see Affinity for more information). Once the volunteer is located, the fabric sends him a request to perform the action outlined by the start state in the process flow definition. The request contains the necessary information for the volunteer to perform the action (user data, task name, execution method, etc). Following task execution, the fabric will invoke the next activity defined by the transition arc in the process flow definition.
There are two additional attributes that let you manipulate the task execution from the process flow definition. You can limit the time given for the task to execute via the 'timeout' attribute. If the task timeout expires, the fabric will consider the task unfinished and take the not-completed arc as defined in the process flow definition. The second attribute 'retries' instructs the fabric to reattempt the execution of a failed task. Once the number of retries is exhausted, the fabric will take the not-completed arc as defined in the process flow definition.
Refer to the following table for details on all supported attributes and elements for process flows.
| Element |
Description |
| process |
This is the root element of the process flow description: one process flow is defined per XML file. The element may contain an optional group-access element and must contain one or more state elements. Each process flow must have a name, and must define at least one state, named start. The following attributes are defined:
| Attribute |
Description |
| name |
The name of the process flow. This element is required and is a FabricIdentifier |
| default_retries |
The number of attempts to execute the activity defined by a state before returning an error. Each state can override this default by specifying its own retry. This attribute is optional and defaults to INFINITE. See Executing Process Flows for more information. |
| default_timeout |
The time, in seconds, that the fabric will give the activity in each state before giving up on the activity. Each state can override this default by specifying its own timeout. This attribute is optional and defaults to INFINITE. A value of INFINITE disables the timeout. See Executing Process Flows for more information. |
The process element defines the following child elements:
| Element |
Cardinality |
Description |
| group-access |
0..1 |
Controls access to the execution of the process flow. |
| state |
1..n |
The set of activities can be performed by the process flow. There must be one and only one state named start, identifying the first state of the process flow. |
An example:
<process name="order_item" default_retries="2" default_timeout="2">
<state name="...">
</state>
</process>
|
| group-access |
This is an optional security-related element that lists the groups that are authorized to run the process flow. By default, all groups are permitted to run the process flow. When this element is present in the process flow, execution of the process flow is limited to any of the listed groups. This element contains one or more group elements.
The group-access element defines a single child element:
| Element |
Cardinality |
Description |
| group |
1..n |
A group that is granted permission to execute the flow. |
A simple process flow with security enabled:
<process name="order_item">
<group-access>
<group name="admin"/>
</group-access>
<state name="...">
</state>
</process>
|
| group |
This element is security-related. It grants permissions to a single group. One attribute is defined:
| Attribute |
Description |
| name |
The name of the group being granted permissions. Groups are defined by the fabric administrator and are specified in the groups.cfg. |
No child elements are defined for group. |
| state |
Each state in the process flow declares a single activity and the details about its execution within the process flow. The state element contains an optional affinity element followed by a required action element followed by one or more arc elements.
The following attributes are defined:
| Attribute |
Description |
| name |
The name is a FabricIdentifier that identifies the state (state names must be unique within a process flow). A state named start is required, identifying the initial state of the process flow. finish is reserved - no state can be named finish. |
| snapshot |
Optional boolean attribute that specifies whether state of the process flow request gets backed up when the activity for the state completes. The attribute defaults to "false". If snapshot is "true", the fabric backs up the "state" of the process flow (the current state in the process flow along with the request data) on two workers before continuing to next activity in the process flow. The benefit of snapshots is that the execution of the process flow can continue from the last snapshot if a fabric worker fails during the execution of a state. If retries are not permitted for the current state, a snapshot will be performed regardless of the snapshot setting. Note that there is overhead associated with performing a snapshot. |
Affinity Elements The state element may optionally contain one affinity element. Affinity elements provide direction to where the fabric should run the state's action, allowing the state's action to execute on a fabric worker that has an application-defined resource. The following affinity elements are defined:
| Element |
Cardinality |
Description |
| component-affinity |
0..1 |
Execute a component method on all fabric workers to determine resource availability. |
| task-affinity |
0..1 |
Execute a task method on all fabric workers to determine resource availability. |
Action elements Following the optional affinity element, the state element must contain one action elements from the following table. The action is the activity that is run while in a given state. The action is either user code or a nested process flow.
| Element |
Cardinality |
Description |
| component-action |
0..1 |
Executes a component method as the state's action. |
| task-action |
0..1 |
Executes a task as the state's action. |
| sub-process |
0..1 |
Executes another process flow as the state's action. Nested process flows act like nested finite state machines. |
Following the action element, the state must contain at least one arc element. The arc element is used to determine the next state of the process flow. The list of arcs is evaluated when the state action completes or is determined to have failed.
| Element |
Cardinality |
Description |
| arc |
1..n |
Indicates the next state based on the results of executing the current action. |
An example process flow with a single start state. Due to the single arc, this process flow will transition to finished regardless of the status or result of the state's action:
<process name="...">
<state name="start">
<component-action component="..." method="...">
</component-action>
<arc status="complete" next-state="finished"/>
</state>
</process>
|
| component-affinity |
Describes the component method to be run on the fabric workers to locate an application resource. Use this element when the method to be used is defined in the Component XML. The following attributes are defined:
| Attribute |
Description |
| component |
A FabricIdentifier naming a component that is defined in the fabric application. |
| method |
A FabricIdentifier naming a method of the component. This method will be run on each worker to determine which workers have a given application resource. The signature of the method must conform to the type of affinity specified by this component-affinity element. See Affinity for more details. |
The following child elements are defined. These elements describe the type of affinity to be used. Each combination affect the required signature of the affinity method (e.g., specific method signatures are required for each affinity type).
| Element |
Cardinality |
Description |
| resource-argument |
0..1 |
Describes the resource parameter to be passed to the affinity method. |
| rank-argument |
0..1 |
Indicates that responses are to be ranked. |
|
| task-affinity |
Describes the task method that will be run on the fabric workers to locate an application resource. Use this element when the method to be called is defined in the Task XML. The following attribute is defined:
| Attribute |
Description |
| task |
A FabricIdentifier naming a task that is defined in the fabric application. The task method will be run on each worker to determine which workers have a given application resource. The signature of the method must conform to the type of affinity specified by this component-affinity element. See details for more. |
The following child elements are defined. These elements describe the type of affinity to be used. Each combination affects the required signature of the affinity method.
| Element |
Cardinality |
Description |
| resource-argument |
0..1 |
Describes the resource parameter to be passed to the affinity method. |
| rank-argument |
0..1 |
Indicates that responses are to be ranked. |
|
| component-action |
This element identifies the component method to be executed. This is one of three possible actions: use it when the process flow state should invoke an application method defined in the Component XML. The following attributes are defined:
| Attribute |
Description |
| component |
The FabricIdentifier of a component defined in the Component XML. |
| method |
The name of a method defined in the implementation class of the component. This method can be discovered |
| retries |
The number of times the action should be reattempted before it considered to have failed. This attribute overrides the process flow default. A retry of 0 defines a non-repeatable action - it should be reserved for methods that cannot be repeated (for example, debiting a bank account a second time). |
| timeout |
The amount of time, in seconds, that the method is permitted to execute before considering it failed. This attribute overrides the process flow default. Actions with a timeout of INFINITE will not be timed out. Note: this timeout can be updated programmatically (see Task APIs) by the application code to change the timeout of a running action. |
The following child elements are defined:
| Element |
Cardinality |
Description |
| arguments |
0..1 |
The list of arguments detailing the data from the request to pass to the component argument. |
| return-value |
0..1 |
An optional mapping of the return value of the method back into the request. |
| result |
0..1 |
An optional mapping of an attribute from the request into the request result (which can be used to arc the process flow. |
|
| task-action |
This element identifies the name of the task executed within the state. This is one of three possible actions: use it when the process flow state should invoke a method defined in the Task XML of the application. The following attributes are defined:
| Attribute |
Description |
| name |
The FabricIdentifier of a task defined in the fabric application (see Task XML). |
| retries |
The number of times a task is reattempted before it considered to have failed. This attribute overrides the process flow default. A task with a retry of 0 defines a non-repeatable task - it should be reserved for tasks that cannot be repeated (for example, debiting a bank account a second time). |
| timeout |
The amount of time, in seconds, that a task is permitted to take before considering in to have failed. This attribute overrides the process flow default. Tasks with a timeout of INFINITE will not be timed out. Note: there is a method in the Task APIs to update the current timeout programmatically, allowing tasks to update the timeout if they need more or less time to complete their work. |
No child elements are defined. |
| sub-process |
This element identifies a process flow to be executed while in the current state. Process flows can be nested to any depth. The parent process flow remains in the current state until the child process flow reaches the finished state, at which point the parent state's arc list is evaluated to determine the next state. The following attribute is defined:
| Attribute |
Description |
| name |
The FabricIdentifier of a process flow. The process flow must be defined in the current fabric application. |
No child elements are defined.
<process name="parent-flow">
...
<state name="...">
<sub-process name="nested-flow"/>
<arc status="..." next-state="..." />
</state>
...
</process>
|
| arc |
An arc defines the transition to the next state in the process flow based on the outcome of the current state. The following attributes are defined:
| Attribute |
Description |
| status |
This attribute refers to the outcome of the current state from the perspective of the fabric. The defined values for this attribute are: complete, not-completed, not-attempted, and in-doubt. This attribute is required. See below for more information on different status values |
| result |
This attribute refers to the outcome of the current state from the perspective of the application. The values for this attribute are application defined. This attribute is optional and is only meaningful when the status of the state's action is complete. The value of result for each arc within a state must be unique. |
| next-state |
The name of the state to which the process flow should transition when the status and result match the actual results. This attribute is required and must name a state that is defined in the current process flow. |
The following table defines the possible values that can be returned by the fabric when executing an action:
Fabric Status Details
| Status |
Description |
| complete |
The user code ran to completion |
| not-completed |
The user code was invoked, but did not run to completion. Examples: the user code threw an unhandled exception, the user code did not complete within the specified timeout, or the worker on which the user code was executing failed and retries were disabled or exhausted |
| not-attempted |
The user code was never invoked. Common examples: affinity was specified and no worker was located with the resource, the action was unable to be called (due to type mismatch, missing user code, etc.) |
| in-doubt |
The user code made updates to the FAM and ran to completion. While attempting to commit the changes, failures occurred which prevented the fabric from validating that the commit was successful. This can happens when the fabric starts a commit and then cannot (re)locate the FAM due to one or more failures. |
Details: The arc allows the application developer to control the execution of the process flow under both normal and error conditions. Error conditions detected by the fabric are reported by the fabric in the request status. By default, the process flow will arc to finished. Arcs can be added to arc to error handling states.
When the action finishes with no errors, the fabric sets status to complete. Actions that run to completion can set the result field in the request, and arcs can specify a result guard - the arc whose result matches the result in the request is taken. Note: an arc that specifies a result implies a status of complete - any other status specified in the arc is erroneous.
In the following example, process flow will transition to next-state when the action completes successfully and the action sets the result to success. If the action completes with a result set to any other value, the process flow will transition to finished. If the action is started but does not complete, the next state will be error-recovery. If the fabric is unable to execute the action, the process flow retries the current state (note: be very careful to not design infinite loops into your process flow). The flow will transition to finished if the status is in-doubt.
<process name="...">
...
<state name="current-state">
<component-action component="..." method="...">
...
</component-action>
<arc result="success" next-state="next-state"/>
<arc status="not-completed"next-state="error-recovery"/>
<arc status="not-attempted"next-state="current-state"/>
</state>
<state name="next-state">
...
</state>
<state name="error-recovery">
...
</state>
...
</process>
|
| resource-argument |
Enables resource affinity (see Affinity for more details). A single attribute is defined:
| Attribute |
Description |
| request-key |
The name of an attribute in the current request. The value of this attribute will be passed to the affinity method as the first parameter. The type of method parameter must be compatible with the type of the request attribute. A runtime type check is performed on each worker. The affinity resource will be considered unavailable on any worker whose method signature is not type compatible with the data from the request. |
|
| rank-argument |
Enables rank affinity (see Affinity for more details). A single attribute is defined:
| Attribute |
Description |
| rank-type |
Specifies the ranking algorithm used when selecting the best fit. The supported values are 'maxWeight' and 'minWeight'. The set of ranks are sorted and the largest or smallest is selected. Future versions of the fabric may define additional algorithms. |
|
| arguments |
This element performs two important roles. It describes 1) the number of arguments (or signature) of a component method, and 2) how data from the request passed to the method. The number of arguments must match the number of arguments the method's signature.
No attributes are defined. A single required child element is defined:
| Element |
Cardinality |
Description |
| argument |
1..n |
The description of an argument of the method. |
|
| argument |
This element describes how data is mapped to/from the method's argument. A single attribute is defined:
| Attribute |
Description |
| expression |
A single MVEL expression that indicates what to pass to the argument. |
No child elements are defined. The following example requires a method checkInventory defined for component my_component that takes two arguments. The method will be call passing two values from the request:
<process name="order_item">
...
<state name="...">
<component-action component="my_component" method="checkInventory">
<arguments>
<argument expression="request['item-id']">
<argument expression="request['quantity']">
</arguments>
</component-action>
<arc status="complete" result="..." next-state="..."/>
</state>
...
</process>
|
| return-value |
This element describes what is done with the return value of the component method. One attribute is defined:
| Attribute |
Description |
| expression |
A single MVEL expression that indicates what request attribute to update with the return value of the method call. |
No child elements are defined. In the following example, the return value of the method is being stored into the request attribute isAvailable:
<process name="order_item">
...
<state name="...">
<component-action component="my_component" method="checkInventory">
<arguments> ... </arguments>
<return-value expression="request['isAvailable']"/>
</component-action>
<arc status="..." next-state="..."/>
</state>
...
</process>
|
| result |
Set the result of the component-action to expression. The value of result is used to select the state transition (arcs) when the method completes. The result of expression will converted to a string (i.e., Java's ToString() method) and compared to find an arc that matches.
| Attribute |
Description |
| expression |
A single MVEL expression that indicates what request attribute to use for the action result. |
No child elements are defined. In the following example, the return value is stored in attribute isAvailable and also converted to a string and stored in the action result. The process flow arcs based on the results. Note: if the action fails to complete (e.g., the method throws an unhandled exception), the process flow goes to finished because there is no arc for not-completed.
<process name="order_item">
...
<state name="...">
<component-action component="my_component" method="checkInventory">
<arguments> ... </arguments>
<return-value expression="request['isAvailable']"/>
<result expression="request['isAvailable']"/>
</component-action>
<arc status="complete" result="true" next-state="processOrder"/>
<arc status="complete" result="false" next-state="handleUnavailable"/>
</state>
...
</process>
|
Deprecated Elements:
The following table lists those elements which are now deprecated. Support for these elements will be removed in a future release.
| Name |
Description |
| task |
Replaced with task-action in EAF 3.8 |
| task-result |
Replaced with result in EAF 3.8 |
| task-status |
Replaced with status in EAF 3.8 |
Below is an example process flow definition file showing some of the basic elements.
<?xml version="1.0"?>
<!DOCTYPE process SYSTEM "ProcessDefinition.dtd">
<process name="name" default_retries="number" default_timeout="number">
<group-access>
<group name="group_name"/>
</group-access>
<state name="start" snapshot="true">
<task-action name="task_name" retries="4" timeout="10"/>
<arc result="success" next-state="second_state"/>
<arc result="failed" next-state="finished"/>
</state>
<state name="second_state" snapshot="false">
<task-affinity task="isAvailableTask">
<resource-argument request-key="name_of_attribute_from_request"/>
<rank-argument rank-type="max-weight"/>
</task-affinity>
<component-action component="some_component" method="some_method">
<arguments>
<argument expression="request['attribute']"/>
</arguments>
</component-action>
<arc result="user defined" next-state="third_state"/>
</state>
<state name="third_state">
<sub-process name="name-of-another-process-flow"/>
<arc status="completed" next-state="finished"/>
</state>
</process>