Search in sources :

Example 71 with Node

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

the class DoWhileHandler method handleDowhile.

/**
 * To get only web service components attached to dowhile
 *
 * @param waitingNode
 * @return list
 */
private ArrayList<Node> handleDowhile(ArrayList<Node> waitingNode, ArrayList<Node> finishedNodes) {
    ArrayList<Node> list = new ArrayList<Node>();
    for (Node node : waitingNode) {
        Component component = node.getComponent();
        if (component instanceof WSComponent) {
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && (finishedNodes.contains(edge.getFromPort().getNode()) || ((ControlPort) edge.getFromPort()).isConditionMet());
                }
            }
            /*
				 * Check for input ports
				 */
            List<DataPort> inputPorts = node.getInputPorts();
            boolean inputsDone = true;
            for (DataPort dataPort : inputPorts) {
                inputsDone = inputsDone && finishedNodes.contains(dataPort.getFromNode());
            }
            if (inputsDone && controlDone) {
                list.add(node);
            }
        }
    }
    return list;
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) EndDoWhileNode(org.apache.airavata.workflow.model.graph.system.EndDoWhileNode) Node(org.apache.airavata.workflow.model.graph.Node) DoWhileNode(org.apache.airavata.workflow.model.graph.system.DoWhileNode) ArrayList(java.util.ArrayList) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) Component(org.apache.airavata.workflow.model.component.Component)

Example 72 with Node

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

the class WorkflowHarvester method removeUnnecessaryNodes.

/**
 * @param pair
 * @param clone
 */
private void removeUnnecessaryNodes(Node node, Port candidatePort, Workflow workflow) {
    if (candidatePort.getFromPort().getEdges().size() == 1) {
        Node fromNode = candidatePort.getFromNode();
        try {
            List<DataPort> inputPorts = fromNode.getInputPorts();
            for (DataPort dataPort : inputPorts) {
                removeUnnecessaryNodes(fromNode, dataPort, workflow);
            }
            workflow.removeNode(fromNode);
        } catch (GraphException e) {
            throw new WorkflowRuntimeException(e);
        }
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) 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)

Example 73 with Node

use of org.apache.airavata.workflow.model.graph.Node 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 74 with Node

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);
        }
    }
}
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

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