Search in sources :

Example 21 with Workflow

use of org.apache.airavata.workflow.model.wf.Workflow 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)

Aggregations

Workflow (org.apache.airavata.workflow.model.wf.Workflow)21 GraphException (org.apache.airavata.workflow.model.graph.GraphException)9 File (java.io.File)6 GraphCanvas (org.apache.airavata.xbaya.ui.graph.GraphCanvas)6 ComponentException (org.apache.airavata.workflow.model.component.ComponentException)5 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)5 Node (org.apache.airavata.workflow.model.graph.Node)5 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 WorkflowException (org.apache.airavata.workflow.model.exceptions.WorkflowException)4 DataPort (org.apache.airavata.workflow.model.graph.DataPort)4 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)4 WSGraph (org.apache.airavata.workflow.model.graph.ws.WSGraph)4 LinkedList (java.util.LinkedList)3 Port (org.apache.airavata.workflow.model.graph.Port)3 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)3 TException (org.apache.thrift.TException)3 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2