Feature Highlights
Modular Java Workflow Environment
Triana Cloud Job Queuing
10 Plus Years of Proven Technology
Sophisticated Drag & Drop Composition
Web Services
Comprehensive Toolbox Libraries


Introduction

In this tutorial we outline the basic operations required to generate and display a workflow (taskgraph) programmatically within Triana. The conclusion of this tutorial contains the code for a simple example workflow wizard which can be built upon to create more advanced workflow wizards.

The basic operations for generating a workflow (taskgraph) in Triana are as follows:

  • Acquire the tools required within the taskgraph
  • Create an empty taskgraph
  • Populate the taskgraph with tasks
  • Connect these tasks
  • Display the taskgraph

Note that in Triana we refer to the data structure used to store a workflow as a taskgraph, the components within that workflow as tasks, and uninstantiated components as tools.

Step 1 - Acquiring Tools

In order to instantiate a component in a workflow you first need the tool that represents that component. There are multiple ways of acquiring the tool for a component, the following is an outline of the most useful:

  • Acquiring a Tool from the ToolTable

    If the tool for the component you wish to use is already displayed in the tool tree, then this tool can be retrieved programmatically using the ToolTable. For example, if the qualified tool name (package + tool name) is Common.String.StringViewer:

    ToolTable tooltable = TaskGraphManager.getToolTable();
    ToolInterface tool = tooltable.getTool("Common.String.StringViewer");

  • Importing Web Services or other Remote Tools

    If the tool you with to use does not exist in the ToolTable, it can be imported into the ToolTable using:

    triana.server.ServiceManager.importServices(location);

    Where location is the location of the remote tool. For web services this is the WSDL location.

    Note that this method imports tools into the ToolTable asynchronously and the tool you require will not be available from the ToolTable instantly. The isTool method in ToolTable can be used to poll whether the required tool exists in the ToolTable yet.

  • Importing a Web Service Tool Directly

    An alternative to the two stage process of importing a Web Service outlined above is to directly acquire the tools for a Web Service from its WSDL location. This can be done as follows:

    triana.proxies.gap.ws.WSServiceImporter.importWebService(url);

  • Discovering Web Services or other Remote Tools

    Where the location of a web service or other remote tool is unknown, a lookup can be done for the service using UDDI or similar discovery service. This is done as follows:

    triana.server.ServiceManager.discoverServices(serachstr);

    Where searchstr is the search string used to locate the service. The nature of the search string, such as whether wildcards are allowed, depends on the discovery service being used.

 

Step 2 - Creating a TaskGraph

The following method in TaskGraphManager is used to create an empty taskgraph

TaskGraph taskgraph = TaskGraphManager.createTaskGraph();

 

Step 3 - Populating a TaskGraph

Once tools for the components required within a taskgraph have been acquired, they can be instantiated within the taskgraph. This can be done using the following taskgraph method:

TaskInterface task = taskgraph.createTask(tool);

 

Step 4 - Connecting Tasks

The next step is to connect the tasks within a taskgraph together to create a workflow. However, as tasks can have multiple input/output nodes, it must be identified which of these nodes are being connected. To do this there are getDataInputNode and getDataOutputNode methods in the task interface that allow you to select individual nodes. Note that the first input/output node on a task is at index 0. For example, to connect output node 0 on task1 to input node 3 on task2 is as follows:

NodeInterface outnode = task1.getDataOutputNode(0);
NodeInterface innode = task2.getDataInputNode(3);
taskgraph.connect(outnode, innode);

 

Step 4 - Displying a Taskgraph

Once a taskgraph has been created and poplutated, it can be displayed in the Triana workspace using the following method:

GUIEnv.getApplicationFrame().addParentTaskGraphPanel(taskgraph);

Note: The addParentTaskGraphPanel method creates and returns a new instance of the TaskGraph with a 'runnable' backend. If you wish to update the taskgraph after it has been displayed, alterations should be done to this 'runnable' taskgraph not the original taskgraph.

 

Putting it all Together

The following is an example wizard that creates and displays a workflow containing a StringGen task connected to a StringViewer task:

import triana.taskgraph.*;
import triana.gui.hci.GUIEnv;
import triana.util.ToolTable;

public class SimpleWizard {

  public void createWorkflow() {
    ToolTable tooltable = TaskGraphManager.getToolTable();

    ToolInterface gentool = tooltable.getTool("Common.String.StringGen");
    ToolInterface viewtool = tooltable.getTool("Common.String.StringViewer");

    TaskGraph taskgraph = TaskGraphManager.createTaskGraph();

    TaskInterface gentask = taskgraph.createTask(gentool);
    TaskInterface viewtask = taskgraph.createTask(viewtool);

    NodeInterface outnode = gentask.getDataOutputNode(0);
    NodeInterface innode = viewtask.getDataInputNode(0);

    taskgraph.connect(outnode, innode);

    GUIEnv.getApplicationFrame().addParentTaskGraphPanel(taskgraph);
  }
}

 

Example Workflow Wizard (including GUI)

The code for an example workflow wizard is available at ExampleWizardAction.java. This example is implemented as a Java action, which allows it to be included as an option within the Triana menus (both static and pop-up). To add the example workflow wizard to the main Triana menus you need to amend the createMenus() method in the triana.gui.hci.TrianaMainMenu class. To add the example worklow wizard to the tools menu, add the following line:

toolsMenu.add(new JMenuItem(new examples.ExampleWizardAction()));

To use the example workflow wizard simply select the wizard from the tools menu. A dialog will be displayed asking for an input tool and an output tool. Enter the qualified name (package + name) of the input and output tools you required here, for example Common.String.StringGen as the input tool and Common.String.StringViewer as the output tool.