Search in sources :

Example 21 with NodeImpl

use of org.apache.airavata.workflow.model.graph.impl.NodeImpl in project airavata by apache.

the class WorkflowInterpreter method finish.

private void finish() throws WorkflowException, RegistryException {
    ArrayList<Node> outoutNodes = new ArrayList<Node>();
    List<NodeImpl> nodes = this.getGraph().getNodes();
    for (Node node : nodes) {
        if (node instanceof OutputNode) {
            if (node.getInputPort(0).getFromNode().getState() == NodeExecutionState.FINISHED) {
                outoutNodes.add(node);
            } else {
                // workflowFinished
                return;
            }
        }
    }
    LinkedList<Object> outputValues = new LinkedList<Object>();
    LinkedList<String> outputKeywords = new LinkedList<String>();
    for (Node outputNode : outoutNodes) {
        OutputNode node = (OutputNode) outputNode;
        List<DataPort> inputPorts = node.getInputPorts();
        for (DataPort dataPort : inputPorts) {
            Object val = InterpreterUtil.findInputFromPort(dataPort, this.invokerMap);
            ;
            if (null == val) {
                throw new WorkFlowInterpreterException("Unable to find output for the node:" + node.getID());
            }
            WorkflowNodeDetails workflowNodeDetails = nodeInstanceList.get(node);
            OutputDataObjectType elem = new OutputDataObjectType();
            elem.setName(node.getName());
            elem.setValue(val.toString());
            workflowNodeDetails.addToNodeOutputs(elem);
            try {
                getExperimentCatalog().update(ExperimentCatalogModelType.WORKFLOW_NODE_DETAIL, workflowNodeDetails, workflowNodeDetails.getNodeInstanceId());
            } catch (RegistryException e) {
                log.error(e.getMessage(), e);
            }
            updateWorkflowNodeStatus(workflowNodeDetails, WorkflowNodeState.COMPLETED);
        }
    }
}
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) RegistryException(org.apache.airavata.registry.cpi.RegistryException) DataPort(org.apache.airavata.workflow.model.graph.DataPort) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType)

Example 22 with NodeImpl

use of org.apache.airavata.workflow.model.graph.impl.NodeImpl in project airavata by apache.

the class WorkflowInterpreter method getNodesWithState.

private ArrayList<Node> getNodesWithState(NodeExecutionState state) {
    ArrayList<Node> list = new ArrayList<Node>();
    List<NodeImpl> nodes = getGraph().getNodes();
    for (Node node : nodes) {
        if (state == node.getState()) {
            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 23 with NodeImpl

use of org.apache.airavata.workflow.model.graph.impl.NodeImpl in project airavata by apache.

the class WorkflowHarvester method harvest.

public Workflow[] harvest(Workflow workflow, QName dataType) {
    LinkedList<Workflow> harvest = new LinkedList<Workflow>();
    LinkedList<Pair<String, String>> candidates = getCandidates(workflow, dataType);
    for (Pair<String, String> pair : candidates) {
        Workflow clone = workflow.clone();
        NodeImpl node = clone.getGraph().getNode(pair.getLeft());
        if (null == node) {
            throw new WorkflowRuntimeException("Specified node not found:" + pair.getLeft());
        }
        Port candidatePort = null;
        List<DataPort> inPorts = node.getInputPorts();
        for (DataPort dataPort : inPorts) {
            if (pair.getRight().equals(dataPort.getID())) {
                candidatePort = dataPort;
                break;
            }
        }
        if (null == candidatePort) {
            throw new WorkflowRuntimeException("Specifies Port was not found:" + pair.getRight());
        }
        if (!(candidatePort.getFromNode() instanceof InputNode)) {
            removeUnnecessaryNodes(node, candidatePort, clone);
            Node input = clone.addNode(new InputComponent());
            input.setPosition(new Point(Math.max(0, node.getPosition().x - 150), node.getPosition().y));
            // original
            if (clone.getGraph().getNodes().size() < workflow.getGraph().getNodes().size() && // its not the same as one already harvested
            !isWorkflowAlreadyHarvested(harvest, clone)) {
                try {
                    clone.getGraph().addEdge(input.getOutputPort(0), candidatePort);
                    cleanLeftOverInputNodes(clone);
                } catch (GraphException e) {
                    throw new RuntimeException(e);
                }
                harvest.add(clone);
            }
        }
    }
    return harvest.toArray(new Workflow[0]);
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) InputComponent(org.apache.airavata.workflow.model.component.system.InputComponent) NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) Node(org.apache.airavata.workflow.model.graph.Node) Workflow(org.apache.airavata.workflow.model.wf.Workflow) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) Point(java.awt.Point) LinkedList(java.util.LinkedList) DataPort(org.apache.airavata.workflow.model.graph.DataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) Pair(org.apache.airavata.common.utils.Pair)

Example 24 with NodeImpl

use of org.apache.airavata.workflow.model.graph.impl.NodeImpl 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);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) Node(org.apache.airavata.workflow.model.graph.Node) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) LinkedList(java.util.LinkedList)

Aggregations

NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)24 Node (org.apache.airavata.workflow.model.graph.Node)14 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)14 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)12 LinkedList (java.util.LinkedList)11 DataPort (org.apache.airavata.workflow.model.graph.DataPort)8 OutputNode (org.apache.airavata.workflow.model.graph.system.OutputNode)6 GraphException (org.apache.airavata.workflow.model.graph.GraphException)5 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)5 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)5 Pair (org.apache.airavata.common.utils.Pair)4 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)4 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)4 ForEachNode (org.apache.airavata.workflow.model.graph.system.ForEachNode)4 StreamSourceNode (org.apache.airavata.workflow.model.graph.system.StreamSourceNode)4 Workflow (org.apache.airavata.workflow.model.wf.Workflow)3 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RegistryException (org.apache.airavata.registry.cpi.RegistryException)2