Tutorial 6. Script Actors

tmcphillips edited this page Feb 15, 2013 · 2 revisions

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
      step: |
        for ((i=1; i<=$count; i++))
        count: 1

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:


  - 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
      actor: !ref BashMultipleConcatenator
        count: 3
        stringOne: /messages/greeting/
        stringTwo: /messages/emphasis/
        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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.