In the previous sections, we used two applications:
billsetuptaskconfigures the database for the
billrunreads usage information from a file and generates a billing statement record for each entry from a usage file.
Previously, we ran the
billsetuptask application and then the
billrun application in sequence manually.
This certainly works for the small case where we want to run two applications back to back and where the first app runs in a few seconds.
But what about the cases where there are five, ten, twenty or even more applications that need to be run in a sequence and the run time of some the applications may be hours?
Also, what do we do in cases where one of the apps returns a non zero exit code? Spring Cloud Data Flow provides a solution for this issue through the use of composed tasks.
A composed task is a directed graph where each node of the graph is a task application. For the two applications (
billrun) that we have used in the previous examples, the graph would look something like this:
In this section, we show how to create a composed task by using Spring Cloud Data Flow's UI and then launch the composed task to Cloud Foundry, Kubernetes, and your local machine.
Before you start on this sample, you need to do two things:
- Install Spring Cloud Data Flow.
- Install the Spring Cloud Task project that we use in this project.
You must you have installed Spring Cloud Data Flow to one of the following platforms:
To register the composed task runner:
If you have not already done so, import the Spring Cloud Task App Starters, which will give you the
composed-task-runnerapplication. To do so, click Apps in the left navigation bar
Select Add Applications(s).
When the Add Application(s) page appears, select Bulk import application coordinates from an HTTP URI location.
In the URI field, enter either (based on the resource from which you will be pulling your apps):
Select Import the application(s).
To create a composed task:
Tasksfrom the left navigation bar.
Create task(s). The task creation view, shown in the following image, appears: This displays a graphical editor that you can use to compose tasks. The initial canvas contains
ENDnodes. To the left of the canvas, you can see the available task applications, including the
billsetuptaskapplication to the canvas.
Connect the START node to the
billrunapplication to the canvas.
billsetuptaskapplication to the
billrunapplication to the END node to complete the composed task definition. In this case, the composed task definition consists of two task apps (
billrun). If there are application-defined configuration properties, we would set them here.
Create Task. This prompts you to name the task definition, which is the logical name for the runtime configuration we want to deploy. In this case, we use the same name as the task application, which is
ct-statement. The task confirmation view, shown in the following image, appears:
Create the task.
Doing so displays the main
TIP: To see all the things that you can do with the Composed Task Graph, see the Composed Task section of the reference documentation.
Once we return to the task list (shown in the following image), we can see that we now have three task definitions:
We see that the following three task definitions were created when we created the ct-statement task:
ct-statement: This definition represents the composed task runner that runs the tasks in the composed task graph.
ct-statement-billsetuptask: This definition represents the
billsetuptaskapp that is run.
ct-statement-billrun: This definition represents the
billrunapp that is to be run.
Now we can launch "ct-statement" by pressing the "play" button (the middle icon that looks like an arrowhead pointing right). Doing so takes you to a form where you can add command line arguments and deployment parameters, but we do not need any for this composed task. Click Launch the task, as the following image shows:
Doing so runs the composed task runner on the Data Flow server's task platform, which manages the execution of the composed task graph.
TIP: If a composed task needs to be run multiple times, you need to set the
increment-instance-enabled property to
true for each launch.
When the execution is complete, the status for each of the task definitions turns to a green color and shows
You can select the Executions tab (shown in the following image) to view a summary of executions for this task.
As shown earlier, a composed task creates a definition for each application in the graph. To delete all the definitions that were created as a part of the composed task, we can delete the composed task runner definition. To do so:
Select the checkbox next to the ct-statement definition
Actionsbutton at the upper left hand corner
Destroy Tasksoption (shown in the following image).
Doing so deletes the definitions that comprised the ct-statement composed task.