use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowInterpreter method getReadyOutputNodesDynamically.
private ArrayList<Node> getReadyOutputNodesDynamically() {
ArrayList<Node> list = new ArrayList<Node>();
List<NodeImpl> nodes = this.getGraph().getNodes();
for (Node node : nodes) {
if (node instanceof OutputNode && node.getState() == NodeExecutionState.WAITING && node.getInputPort(0).getFromNode().getState() == NodeExecutionState.FINISHED) {
list.add(node);
}
}
return list;
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowInterpreter method sendOutputsDynamically.
private void sendOutputsDynamically() throws WorkflowException, RegistryException, AiravataException {
ArrayList<Node> outputNodes = getReadyOutputNodesDynamically();
if (outputNodes.size() != 0) {
LinkedList<Object> outputValues = new LinkedList<Object>();
LinkedList<String> outputKeywords = new LinkedList<String>();
for (Node node : outputNodes) {
// Change it to processing state so we will not pic it up in the
// next run
// even if the next run runs before the notification arrives
WorkflowNodeDetails workflowNodeDetails = createWorkflowNodeDetails(node);
// workflowNodeDetails.setNodeInstanceId((String)getExperimentCatalog().add(ChildDataType.WORKFLOW_NODE_DETAIL, workflowNodeDetails, getExperiment().getExperimentID()));
node.setState(NodeExecutionState.EXECUTING);
updateWorkflowNodeStatus(workflowNodeDetails, WorkflowNodeState.EXECUTING);
publishNodeStatusChange(WorkflowNodeState.EXECUTING, node.getID(), experiment.getExperimentID());
// OutputNode node = (OutputNode) outputNode;
List<DataPort> inputPorts = node.getInputPorts();
for (DataPort dataPort : inputPorts) {
Object val = InterpreterUtil.findInputFromPort(dataPort);
if (null == val) {
throw new WorkFlowInterpreterException("Unable to find output for the node:" + node.getID());
}
// input
if (val instanceof org.xmlpull.v1.builder.XmlElement) {
((OutputNode) node).setDescription(XMLUtil.xmlElementToString((org.xmlpull.v1.builder.XmlElement) val));
} else {
((OutputNode) node).setDescription(val.toString());
}
// Saving output Node data in to database
// WorkflowNodeType workflowNodeType = new WorkflowNodeType();
// workflowNodeType.setNodeType(WorkflowNodeType.WorkflowNode.OUTPUTNODE);
// WorkflowInstanceNode workflowInstanceNode = new WorkflowInstanceNode(new WorkflowExecution(config.getTopic(), config.getTopic()), node.getID());
String portname = node.getName();
String portValue = ((OutputNode) node).getDescription();
// this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().setWorkflowInstanceNodeOutput(workflowInstanceNode, portname + "=" + portValue);
// this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().setWorkflowNodeType(workflowInstanceNode, workflowNodeType);
OutputDataObjectType elem = new OutputDataObjectType();
elem.setName(portname);
elem.setValue(portValue);
workflowNodeDetails.addToNodeOutputs(elem);
getExperimentCatalog().update(ExperimentCatalogModelType.WORKFLOW_NODE_DETAIL, workflowNodeDetails, workflowNodeDetails.getNodeInstanceId());
if (this.config.isActOnProvenance()) {
// TODO do provanence thing
// try {
// if (val instanceof String) {
// this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager()
// .saveWorkflowExecutionOutput(this.config.getTopic(), node.getName(), val.toString());
// } else if (val instanceof org.xmlpull.v1.builder.XmlElement) {
// this.getConfig()
// .getConfiguration()
// .getAiravataAPI().getProvenanceManager()
// .saveWorkflowExecutionOutput(this.config.getTopic(), node.getName(),
// XMLUtil.xmlElementToString((org.xmlpull.v1.builder.XmlElement) val));
// }
// outputValues.add(val);
// outputKeywords.add(dataPort.getID());
// } catch (AiravataAPIInvocationException e) {
// e.printStackTrace(); // To change body of catch
// // statement use File |
// // Settings | File
// // Templates.
// }
}
}
node.setState(NodeExecutionState.FINISHED);
publishNodeStatusChange(WorkflowNodeState.COMPLETED, node.getID(), experiment.getExperimentID());
updateWorkflowNodeStatus(workflowNodeDetails, WorkflowNodeState.COMPLETED);
notifyViaInteractor(WorkflowExecutionMessage.NODE_STATE_CHANGED, null);
}
}
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class InterpreterUtil method findInputFromPort.
public static Object findInputFromPort(DataPort inputPort) throws WorkflowException {
Object outputVal = null;
Node fromNode = inputPort.getFromNode();
if (fromNode instanceof InputNode) {
outputVal = ((InputNode) fromNode).getDefaultValue();
// } else if (fromNode instanceof ConstantNode) {
// outputVal = ((ConstantNode) fromNode).getValue();
// } else if (fromNode instanceof DifferedInputNode && ((DifferedInputNode) fromNode).isConfigured()) {
// outputVal = ((DifferedInputNode) fromNode).getDefaultValue();
// } else if (fromNode instanceof EndifNode || fromNode instanceof DoWhileNode || fromNode instanceof EndDoWhileNode) {
// Invoker fromInvoker = invokerMap.get(fromNode);
// outputVal = fromInvoker.getOutput(inputPort.getFromPort().getID());
// } else if (fromNode instanceof InstanceNode) {
// return ((InstanceNode) fromNode).getOutputInstanceId();
// } else if (fromNode instanceof EndForEachNode) {
// outputVal = "";
// Invoker workflowInvoker = invokerMap.get(fromNode);
// String outputName = "";
// if (inputPort instanceof SystemDataPort) {
// outputName = ((SystemDataPort) inputPort).getWSComponentPort().getName();
//
// } else if (inputPort instanceof WSPort) {
// outputName = ((SystemDataPort) fromNode.getInputPort(fromNode.getOutputPorts().indexOf(inputPort.getEdge(0).getFromPort())))
// .getWSComponentPort().getName();
// }
// XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString("<temp>" + workflowInvoker.getOutput(outputName) + "</temp>");
// Iterator valItr = msgElmt.children().iterator();
// while (valItr.hasNext()) {
// Object object2 = valItr.next();
// if (object2 instanceof XmlElement) {
//
// if (((XmlElement) object2).children().iterator().hasNext()) {
// outputVal = outputVal + StringUtil.DELIMETER + StringUtil.quoteString(((XmlElement) object2).children().iterator().next().toString());
// }
// }
// }
//
// if (((String) outputVal).length() == 0) {
// throw new WorkflowException("Empty Output Generated");
// }
// outputVal = ((String) outputVal).substring(1, ((String) outputVal).length());
// } else {
// Invoker fromInvoker = invokerMap.get(fromNode);
// try {
// if (fromInvoker != null)
// outputVal = fromInvoker.getOutput(inputPort.getFromPort().getName());
//
// } catch (Exception e) {
// // if the value is still null look it up from the inputport name
// // because the value is set to the input port name at some point
// // there is no harm in doing this
// if (null == outputVal) {
// outputVal = fromInvoker.getOutput(inputPort.getName());
// }
// }
}
return outputVal;
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class InterpreterUtil method getNumberOfInputsForForEachNode.
public static Integer[] getNumberOfInputsForForEachNode(final ForEachNode forEachNode, Map<Node, Invoker> invokerMap) throws WorkflowException {
List<DataPort> inputPorts = forEachNode.getInputPorts();
Integer[] inputNumbers = new Integer[inputPorts.size()];
for (DataPort forEachInputPort : inputPorts) {
// if input node for for-each is WSNode
Node forEachInputNode = forEachInputPort.getFromNode();
int index = 0;
Object returnValForProvenance = null;
if (forEachInputNode instanceof InputNode) {
returnValForProvenance = InterpreterUtil.findInputFromPort(forEachInputPort, invokerMap);
if (null == returnValForProvenance) {
throw new WorkFlowInterpreterException("Unable to find input for the node:" + forEachNode.getID());
}
String[] vals = StringUtil.getElementsFromString(returnValForProvenance.toString());
inputNumbers[inputPorts.indexOf(forEachInputPort)] = vals.length;
}
}
return inputNumbers;
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class XBayaUtil method findEndForEachFor.
/**
* @param node
* @return
*/
public static Node findEndForEachFor(ForEachNode node) {
Collection<Node> toNodes = node.getOutputPort(0).getToNodes();
if (toNodes.size() != 1) {
throw new WorkflowRuntimeException("ForEach output does not contain single out-edge");
}
Node middleNode = toNodes.iterator().next();
List<DataPort> outputPorts = middleNode.getOutputPorts();
for (DataPort dataPort : outputPorts) {
if (dataPort.getToNodes().size() == 1) {
Node possibleEndForEachNode = dataPort.getToNodes().get(0);
if (possibleEndForEachNode instanceof EndForEachNode) {
return possibleEndForEachNode;
}
}
}
throw new WorkflowRuntimeException("EndForEachNode not found");
}
Aggregations