Search in sources :

Example 6 with Node

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;
}
Also used : NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode)

Example 7 with Node

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);
        }
    }
}
Also used : DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType)

Example 8 with Node

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;
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) Node(org.apache.airavata.workflow.model.graph.Node)

Example 9 with Node

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;
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) Node(org.apache.airavata.workflow.model.graph.Node) WorkFlowInterpreterException(org.apache.airavata.workflow.engine.interpretor.WorkFlowInterpreterException)

Example 10 with Node

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");
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) Node(org.apache.airavata.workflow.model.graph.Node) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode)

Aggregations

Node (org.apache.airavata.workflow.model.graph.Node)74 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)46 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)40 DataPort (org.apache.airavata.workflow.model.graph.DataPort)31 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)24 Port (org.apache.airavata.workflow.model.graph.Port)20 OutputNode (org.apache.airavata.workflow.model.graph.system.OutputNode)20 StreamSourceNode (org.apache.airavata.workflow.model.graph.system.StreamSourceNode)18 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)16 ForEachNode (org.apache.airavata.workflow.model.graph.system.ForEachNode)16 MemoNode (org.apache.airavata.workflow.model.graph.system.MemoNode)15 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)14 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)14 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)13 ConstantNode (org.apache.airavata.workflow.model.graph.system.ConstantNode)12 EndifNode (org.apache.airavata.workflow.model.graph.system.EndifNode)12 IfNode (org.apache.airavata.workflow.model.graph.system.IfNode)12 GraphException (org.apache.airavata.workflow.model.graph.GraphException)11 LinkedList (java.util.LinkedList)9 ArrayList (java.util.ArrayList)8