Executing a Workflow outside of the Taverna GUI
Taverna 1.4 and 1.5
From the command line
From 1.4 and above, a shellscript provides help launching a workflow without using the GUI:
Executeworkflow runs workflows without popping up the GUI. Nice for running those big
things on some server with lots of memory,
but it also means you won't get much progress feedback while it's running.
The executer works like this:
C:\taverna-1.4> executeworkflow -help
usage: executeworkflow <workflow> [..]
Execute workflow and save outputs. Inputs can
be specified by multiple -input options, or
loaded from an XML input document as saved from
Taverna. By default, a new directory is created
named workflow.xml_output unless the --output
or --outputdoc options are given. All files to
be read can be either a local file or an URL.
-help print this message
-input <name filename> load the named input from file or URL
-inputdoc <document> load inputs from XML document
-output <directory> save outputs as files in directory, default is
to make a new directory workflowName_output
-outputdoc <document> save outputs to a new XML document
-report <file> save progress report in file, default is
progressReport.xml in the output directory
So simple examples would be:
executeworkflow file:myworkflow.xml
executeworkflow -input swiss_in swiss_in.txt file:myworkflow.xml
executeworkflow -inputdoc file:inputdoc.xml file:myworkflow.xml
or in *NIX:
sh ./executeworkflow.sh file:myworkflow.xml
sh ./executeworkflow.sh -input swiss_in swiss_in.txt file:myworkflow.xml
sh ./executeworkflow.sh -inputdoc file:inputdoc.xml file:myworkflow.xml
This would create a new directory
myworkflow.xml_output containing files for the outputs. If you would like, you can add
-outputdoc outputs.xml and view
outputs.xml using dataviewer.
Similary, you can save complex inputs (ie. lists) by making them in Taverna, and saving the input document. This input document can be used as
-inputdoc inputs.xml
Programmatically
To execute a workflow programmatically, the API now includes the helper class
org.embl.ebi.escience.scufl.tools.WorkflowLauncher. This class now simplifies executing a workflow to the following steps:
1) Construct the WorkflowLauncher with either a stream, or a URL to the workflow xml. (For a local file, this url will contain the prefix 'file:').
WorkflowLauncher launcher = new WorkflowLauncher(new URL("file:c:/myworkflow.xml"));
2) Now call the 'execute' method, passing the input Map, and also optionally a WorkflowEventListener.
Map outputs=launcher.execute(inputs);
or
Map outputs=launcher.execute(inputs, myWorkflowEventListener);
3) If required, the access to the progress report is provided.
String progressReport = launcher.getProgressReportXML();
From Taverna 1.5 your application needs to be launched via Raven
This is achieved by deploying your application with Maven, and invoking it through the bootstrap. The scripts executeworkflow and dataviewer give examples of this.
Properties that will need changing include:
- raven.target.groupid - the groupID of the entry point artifact.
- raven.target.artifactid - the artifactID of the entry point artifact.
- raven.target.version - the version of the entry point artifact.
- raven.target.class - the class to be invoked.
- raven.target.method - the method to be invoked that starts the application.
- raven.repository.0 - the location of the repository that the artifact has been deployed.
- MyLauncher.zip: Example Workflow Launcher application with Taverna 1.5.x
The myGrid team are currently looking at simplifying this process
TAV-427.
Taverna 1.3.1
To execute a workflow using the Taverna 1.3.1 'API' the following steps are required:
(Exception handling removed for brevity)
1) Generate the inputs, which are contained in a Map. The key must match the workflow input name, and the value is an instance of
org.embl.ebi.escience.baclava.DataThing which wraps the input value. The safest way to create the DataThing is to use the static bake method on
org.embl.ebi.escience.baclava.factory.DataThingFactory
Map inputs = new HashMap();
inputs.put("anInput",DataThingFactory.bake("inputdata"));
String [] listOfStrings = {"String 1","String 2"};
inputs.put("aList",DataThingFactory.bake(listOfStrings));
2) Create an instance of the
org.embl.ebi.escience.scufl.ScuflModel
ScuflModel model = new ScuflModel();
3) Populate this model by passing an InputStream, JDom Element, URL, or File to the worklow XML to the
org.embl.ebi.escience.scufl.parser.ScuflParser
XScuflParser.populate(xmlStream,model,null);
3b) (Optional)Provide a
org.embl.ebi.escience.scufl.enactor.WorkflowEventListener if handling of events is required, otherwise set to null.
WorkflowEventDispatcher.DISPATCHER.addListener(workflowEventListener);
4) Create an instance of the
org.embl.ebi.escience.scufl.enactor.EnactorProxy, and from this compile a
org.embl.ebi.escience.scufl.enactor.WorkflowInstance from the model and the inputs.
EnactorProxy enactor = FreefluoEnactorProxy.getInstance();
WorkflowInstance workflowInstance = enactor.compileWorkflow(model, inputs, null);
5) Now the workflow can be executed. Execution runs asynchronously, so additional code is required to wait until that thread is complete. The simplest way is to create a sleeping loop, that periodically checks the status until the status is COMPLETE or FAILED.
workflowInstance.run();
while(workflowInstance.getStatus().equals("COMPLETE") && workflowInstance.getStatus().equals("FAILED")) {
Thread.sleep(2000);
}
6) Once the execution is complete (or fails) it is possible to retrieve the outputs, and the progress report from the workflow instance. Similar to the inputs, the outputs are contained in a Map, with the key being the output name and the output data being wrapped by the DataThing class.
Map outputs = workflowInstance.getOutput();
String progressReport = workflowInstance.getProgressReportXMLString();