This topic describes the basics of the Flow Definition Language (FDL) of CloudFlow. This topic also provides examples of the FDL.
Basics
In CloudFlow, the FDL in the YAML format is used to describe and define business logic as flows. To execute a flow, CloudFlow parses and executes states based on the flow definition.
A flow contains multiple states. These states can be simple atomic states, such as Task, Succeed, Fail, Wait, and Pass, or complex control states, such as Choice, Parallel, and Map. You can combine and nest states to build complex business logic. For example, a branch of a Parallel state can be a Choice state.
Errors may occur during the execution of states. CloudFlow provides the OnErrors capability that allows you to retry a state or go to another state upon an error.
States in CloudFlow are similar to functions in programming languages. State combinations are similar to function invocations. Data is passed between states based on the Input and Output variables. Each state uses a Context variable to store data. States can be combined and nested. If a state contains another state, the outer state is the scope of the inner state.
When you define a flow, you can use the following states:
Task: invokes an integrated service.
Pass: serves as a placeholder to plan the basic structure of the flow.
Wait: pauses the flow execution for a period of time.
Choice: defines different execution paths.
Parallel: executes multiple branches in parallel. The branches share the input.
Map: processes elements in an array in parallel.
Succeed: terminates the flow in advance.
Fail: terminates the flow in advance.
Flow attributes
The following table describes the attributes that a flow contains.
Attribute | Type | Required | Description | Example |
Type | String | Yes | The type of Domain Specific Language (DSL) of the flow definition. | StateMachine |
SpecVersion | String | Yes | The version of the Spec. | v1 |
States | Array | Yes | The array of states that are contained in the flow. | See the Examples section in this topic. |
StartAt | String | Yes | The state from which the execution of the flow starts. | my start task |
Name | String | Yes | The name of the flow. | my-wkfl |
Description | String | No | The description of the flow. | test workflow definition |
Timeout | Int | No | The timeout period of the flow. | 600 |
Common attributes of states
This section describes the common attributes of all states.
Attribute | Type | Required | Description | Example |
Name | string | Yes | The name of the state. | my-state-name |
Description | string | No | The description of the state. | describe it here |
Type | string | Yes | The type of the state. | Task |
Next | string | No | The next state that is executed after the current state is complete. If the End attribute is true, you do not need to specify this attribute. | my-next-state |
End | bool | No | Specifies whether to end the current scope. | true |
In a flow definition in the YAML format, the value of the Name field must be unique. Therefore, the name of the flow and the name of each state must be unique.
Scopes of states
In CloudFlow, states can be nested in unlimited levels based on scopes. If a state contains another state, the outer state is the scope of the inner state. If two states are at the same level, the two states share the same scope. An example of scopes:
Type: StateMachine
Name: my-wkfl
SpecVersion: v1
StartAt: Parallel1
States:
- Type: Parallel
Name: Parallel1
Next: Pass4
Branches:
- StartAt: Pass1
States:
- Type: Pass
Name: Pass1
Next: Pass2
OutputConstructor:
FieldA: 123
- Type: Pass
Name: Pass2
End: true
- StartAt: Pass3
States:
- Type: Pass
InputConstructor:
FieldA: 321
Name: Pass3
End: true
- Type: Pass
Name: Pass4
End: true
In this example, the following scopes are involved:
Parallel1 and Pass4 share the my-wkfl scope.
ParallelBranch #0 and ParallelBranch #1 share the Parallel1 scope.
Pass1 and Pass2 share the ParallelBranch #0 scope.
After a state whose End attribute is true is complete, the scope of the state is marked as complete. The following items list the details:
After Pass2 is complete, ParallelBranch #0 is marked as complete.
After ParallelBranch #0 and ParallelBranch #1 are complete, Parallel1 is marked as complete.
After Pass4 is complete, my-wkfl is marked as complete.
Sample flows
Example 1
The following sample flow contains a Pass state that performs no actual operation.
Type: StateMachine
Name: my-wkfl
Description: test workflow definition
SpecVersion: v1
Timeout: 600
StartAt: Pass
States:
- Type: Pass
Name: Pass
End: true
Example 2
The following sample flow contains three states: Pass1, Parallel1, and Pass4.
The flow starts from Pass1 and goes to Parallel1. Parallel1 contains two branches that start from Pass2 and Pass3. After Parallel1 is executed, the flow goes to Pass4. After Pass4 is executed, the flow ends.
Type: StateMachine
Name: my-wkfl
SpecVersion: v1
StartAt: Pass1
States:
- Type: Pass
Name: Pass1
Next: Parallel1
- Type: Parallel
Name: Parallel1
Next: Pass4
Branches:
- StartAt: Pass2
States:
- Type: Pass
Name: Pass2
End: true
- StartAt: Pass3
States:
- Type: Pass
Name: Pass3
End: true
- Type: Pass
Name: Pass4
End: true