Search code examples
spring-cloud-dataflowspring-cloud-task

Launching composed task built by DSL from stream application


Every example I've seen (task-launcher sink and triggertask source ) shows how to launch the task defined by uri attribute. My tasks definitions look like this :

sampleTask  <t2: timestamp || t1: timestamp> 
sampleTask-t1   timestamp   
sampleTask-t2   timestamp   
sampleTaskRunner    composed-task-runner --graph=sampleTask

My question is how do I launch the composed task runner (sampleTaskRunner, defined by DSL) from stream application.

Thanks

UPDATE

I ended up with the below solution that triggers task using SCDF REST API :

composedTask definition :

<timestamp || mySampleTask>

Stream definition :

http | httpclient | log

Deployment properties :

app.http.port=81
app.httpclient.body=name=composedTask&arguments=--increment-instance-enabled=true
app.httpclient.http-method=POST
app.httpclient.url=http://localhost:9393/tasks/executions
app.httpclient.headers-expression={'Content-Type':'application/x-www-form-urlencoded'}

Though it's easy to implement http sink component, would be great if stream application starters will provide one out of the box.

Another concern I have is about discovering the SCDF REST URL when deployed in distributed environment.


Solution

  • Here's a quick take from one of the SCDF's R&D team members (Glenn Renfro).

    stream create foozer --definition "trigger --fixed-delay=5 | tasklaunchrequest-transform --uri=maven://org.springframework.cloud.task.app:composedtaskrunner-task:1.1.0.BUILD-SNAPSHOT --command-line-arguments='--graph=sampleTask-t1||sampleTask-t2 --increment-instance-enabled=true --spring.datasource.url=jdbc:mariadb://localhost:3306/test --spring.datasource.username=root --spring.datasource.password=password --spring.datasource.driverClassName=org.mariadb.jdbc.Driver' | task-launcher-local" --deploy

    In the foozer stream definition,

    1) "trigger" source happens to trigger an upstream event every 5s

    2) "tasklaunchrequest-transform" processor takes a few arguments; more specifically, it uses "composedtaskrunner-task:1.1.0.BUILD-SNAPSHOT" to launch a composed-task graph (i.e., sampleTask-t1||sampleTask-t2)

    3) Pay attention to --increment-instance-enabled. This was recently added to CTR application and this provides the ability to re-launch a composed-task in a recurring cadence

    4) Since the CTR and SCDF must share the same database, we are also passing datasource properties as command-line args. (SCDF-server is already started with the same datasource credentials)

    Hope this helps.

    Lastly, we will add a sample to the reference guide via: spring-cloud/spring-cloud-dataflow#1780