This topic describes the basics of the Flow Definition Language (FDL) of CloudFlow. This topic also provides examples of the FDL. The FDL and examples help you understand how to build and manage flows.
Basics
The FDL of CloudFlow is a state machine definition specification based on the YAML language. The FDL defines a state machine (state set) to describe the business logic as flows. When the flow is executed, the state relationship defined in the flow and the execution result of child flows drive the states to transit and the flow to be executed.
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 OnError 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. You can combine and nest states. If a state contains another state, the outer state is the scope of the inner state.
You can use the following states to define a flow:
Task states are used to call API operations of other integrated services to complete a job.
Pass states are used to debug flows as blank nodes and data preprocessing nodes.
Wait states are used to pause flow execution for a period of time.
Choice states are used to determine the next step in a flow based on specific conditions or logic.
Parallel states are used to execute multiple branches in parallel. The branches share inputs.
Map states allow users to apply the same operation to each element in an array. This facilitates the processing of large amounts of data and management of flows.
Succeed states are used to terminate a flow or child flow before schedule based on specific conditions.
Fail states are used to handle expected or unexpected errors that occur during flow execution.
Flow attributes
The following table describes the attributes that a flow contains.
Attribute | Type | Required | Description | Example |
Type | String | Yes | The type of the flow definition. | StateMachine |
SpecVersion | String | Yes | The version of the flow definition. | v1 |
States | Array | Yes | An array of nested states that contain all the steps of a flow. These steps can be nested to control the execution path of the flow. |
|
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 execution. | 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 flow. | Task |
Next | string | No | The next state that is executed after the current state is complete. If the value of the End attribute is true, you do not need to specify this attribute. | my-next-state |
End | bool | No | Specifies whether the state is the terminal state of 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: Pass2
States:
- Type: Pass
InputConstructor:
FieldA: 321
Name: Pass3
End: true
- Type: Pass
Name: Pass4
End: true
In the preceding 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 describe 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
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