-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial 6. Script Actors
In the previous tutorial we implemented new actors using the Groovy programming language. Because full Groovy language support is included within RestFlow, actors written in Groovy will run on all platforms that RestFlow supports. RestFlow also makes it easy to write actors using scripting languages not bundled with RestFlow. These include Bash, Perl, Python, and Tcl. Actors implemented in these languages only will work on computers on which the required language support has been installed. However, if you are familiar with one or more of these languages or already have numerous scripts on hand, this likely will be the fastest way to incorporate new actors into your workflows.
###Writing an actor in Bash
If you are using a Unix, Linux, or Mac system for this tutorial (or have installed Cygwin on a Windows system), you can try reimplementing the MultipleConcatenator actor from Chapter 5 using a Bash script. Add the following component definition to the components section of your myActors.yaml file
- id: BashMultipleConcatenator
type: BashActor
properties:
step: |
concatenatedString="${stringOne}"
for ((i=1; i<=$count; i++))
do
concatenatedString="${concatenatedString}${stringTwo}"
done
inputs:
stringOne:
stringTwo:
count: 1
outputs:
concatenatedString:
Note that this component is of type BashActor. The step property defines the bash script implementing the actor. The variables listed in the actor's inputs property are preloaded with values prior to executing the step script. This is why stringOne, stringTwo, and count can be used in the script immediately. Similarly, the values of output variables are automatically extracted following the execution of the script. All the script needs to do is leave its results in the variables listed as the actor's outputs.
Add an imports section to myActors.yaml so that the definition of BashScriptActor is available:
imports:
- classpath:/common/scriptActors.yaml
Finally, update hello7.yaml, modifying the line highlighted below so that the EmphasizeGreeting node uses the BashMultipleConcatenator actor instead of the (Groovy) MultipleConcatenator actor:
- id: EmphasizeGreeting
type: Node
properties:
actor: !ref BashMultipleConcatenator
parameters:
count: 3
inflows:
stringOne: /messages/greeting/
stringTwo: /messages/emphasis/
outflows:
concatenatedString: /messages/emphasizedGreeting/
Save the modified workflow as hello8.yaml, and run it. You should see output identical to that of hello7.yaml:
$ restflow -f hello8.yaml
Hello World!!!
Good Afternoon, Cosmos!!!!!!
Good night, and good luck!!!!!!!!!
$
The bash script defined in BashMultipleConcatenator was executed as an external process (outside of RestFlow) three times during the run of this workflow.