use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class JythonScript method writeOutput.
private void writeOutput(OutputNode node, PrintWriter pw) throws GraphException {
String id = node.getID();
Port port = node.getPort();
Node fromNode = port.getFromNode();
if (fromNode == null) {
throw new GraphException("Output parameter has to be connected to some node.");
}
Port fromPort = port.getFromPort();
if (fromNode instanceof InputNode) {
// The OutputNode is directly connected to an InputNode.
pw.println(TAB + id + VALUE_SUFFIX + " = " + PROPERTIES_VARIABLE + "." + GET_PROPERTY_METHOD + "('" + fromNode.getID() + "')");
} else {
pw.println(TAB + "# Wait output " + id);
pw.println(TAB + id + VALUE_SUFFIX + " = " + fromNode.getID() + INVOKER_SUFFIX + "." + GET_OUTPUT_METHOD + "('" + fromPort.getName() + "')");
}
pw.println(TAB + "print '" + id + " = ', " + id + VALUE_SUFFIX);
// This might try to remove a node that has been removed
// already, but it's OK.
this.executingNodes.remove(fromNode);
pw.println();
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class JythonScript method writeWaitAll.
/**
* @param pw
*/
private void writeWaitAll(PrintWriter pw) {
pw.println(TAB + "# Wait all executing services.");
for (Node node : this.executingNodes) {
writeWait(node, pw);
}
pw.println();
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class JythonScript method writeInvocations.
/**
* @param pw
* @throws GraphException
*/
private void writeInvocations(PrintWriter pw) throws GraphException {
Collection<Node> nextNodes = getNextNodes();
while (nextNodes.size() > 0) {
// If there are more than one nodes to invoke, they can run
// concurrently using threads.
boolean thread = (nextNodes.size() > 1);
for (Node node : nextNodes) {
if (node instanceof WSNode) {
WSNode wsNode = (WSNode) node;
writeInvocation(wsNode, thread, pw);
} else {
// TODO conditions, loops might come here.
}
this.notYetInvokedNodes.remove(node);
}
nextNodes = getNextNodes();
}
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowModifier method createDifference.
/**
* @return The workflow that needs to be executed.
* @throws GraphException
* @throws MonitorException
*/
public Workflow createDifference() throws GraphException, MonitorException {
WSGraph originalGraph = this.modifiedWorkflow.getGraph();
Workflow workflow = this.modifiedWorkflow.clone();
String name = workflow.getName();
name += " (diff)";
workflow.setName(name);
WSGraph graph = workflow.getGraph();
// Remove the finished node.
removeFinishedNodes(originalGraph, graph);
Set<WSPort> originalFromPorts = getFinalOutputPorts(originalGraph, graph);
// Create input nodes for unconnected input ports.
createInputNodes(graph, originalFromPorts);
// Set default values.
for (WSPort originalFromPort : originalFromPorts) {
// TODO handle the case that node is not WSNode.
Node originalFromNode = originalFromPort.getNode();
String fromNodeID = originalFromNode.getID();
String output;
if (originalFromNode instanceof InputNode) {
// notification that includes the input of the workflow.
output = getWorkflowInput(fromNodeID);
} else if (originalFromNode instanceof WSNode) {
// Retrieve input value from notification.
WSComponent component = ((WSNode) originalFromNode).getComponent();
String messageName = component.getOutputTypeName();
String parameterName = originalFromPort.getComponentPort().getName();
output = getOutput(fromNodeID, messageName, parameterName);
} else {
// This should not happen.
throw new WorkflowRuntimeException(originalFromNode.getClass().getName());
}
Port originalToPort = originalFromPort.getToPorts().get(0);
PortImpl toPort = graph.getPort(originalToPort.getID());
InputNode inputNode = (InputNode) toPort.getFromNode();
inputNode.setDefaultValue(output);
}
return workflow;
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowHarvester method cleanLeftOverInputNodes.
/**
* @param clone
*/
private void cleanLeftOverInputNodes(Workflow clone) {
List<NodeImpl> nodes = clone.getGraph().getNodes();
LinkedList<Node> removeList = new LinkedList<Node>();
for (Node nodeImpl : nodes) {
if (nodeImpl instanceof InputNode) {
if (nodeImpl.getOutputPort(0).getToNodes().size() == 0) {
removeList.add(nodeImpl);
}
}
}
for (Node node : removeList) {
try {
clone.removeNode(node);
} catch (GraphException e) {
throw new WorkflowRuntimeException(e);
}
}
}
Aggregations