Search in sources :

Example 36 with WorkflowRuntimeException

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

Example 37 with WorkflowRuntimeException

use of org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException 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 38 with WorkflowRuntimeException

use of org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException in project airavata by apache.

the class DoWhileHandler method call.

/**
 * @see java.util.concurrent.Callable#call()
 */
@Override
public Boolean call() throws Exception {
    log.debug("Invoked Dowhile node");
    SystemComponentInvoker dowhileinvoker = new SystemComponentInvoker();
    // TODO check for multiple input case
    Object inputVal1 = InterpreterUtil.findInputFromPort(this.dowhilenode.getInputPort(0), this.invokerMap);
    dowhileinvoker.addOutput(this.dowhilenode.getOutputPort(0).getID(), inputVal1);
    this.invokerMap.put(this.dowhilenode, dowhileinvoker);
    this.finishedNodes.add(this.dowhilenode);
    ArrayList<Node> readyNodes = this.handleDowhile(this.waitingNode, this.finishedNodes);
    // invoking all the webservice components
    if (readyNodes.size() != 1) {
        throw new WorkflowRuntimeException("More than one dowhile execution not supported");
    }
    Node donode = readyNodes.get(0);
    this.interpreter.handleWSComponent(donode);
    log.debug("Invoked service " + donode.getName());
    List<DataPort> inputPorts = this.dowhilenode.getInputPorts();
    boolean runflag = true;
    while (runflag) {
        // while (true) {
        // if (NodeController.isRunning(donode) || NodeController.isWaiting(donode)) {
        // Thread.sleep(500);
        // log.debug("Service " + donode.getName() + " waiting");
        // } else if (NodeController.isFinished(donode)) {
        // log.debug("Service " + donode.getName() + " Finished");
        // List<DataPort> ports = this.dowhilenode.getOutputPorts();
        // for (int outputPortIndex = 0, inputPortIndex = 1; outputPortIndex < ports.size(); outputPortIndex++) {
        // Object inputValue = InterpreterUtil.findInputFromPort(this.dowhilenode.getInputPort(inputPortIndex), this.invokerMap);
        // dowhileinvoker.addOutput(this.dowhilenode.getOutputPort(outputPortIndex).getID(), inputValue);
        // }
        // break;
        // } else if (NodeController.isFailed(donode)) {
        // log.debug("Service " + donode.getName() + " Failed");
        // runflag = false;
        // dowhilenode.setState(NodeExecutionState.FAILED);
        // this.threadExecutor.shutdown();
        // return false;
        // } else if (donode.isBreak()) {
        // log.debug("Service " + donode.getName() + " set to break");
        // runflag = false;
        // break;
        // } else {
        // log.error("Service " + donode.getName() + " have unknow status");
        // throw new WorkFlowInterpreterException("Unknow status of the node");
        // }
        // }
        // this.invokerMap.put(this.dowhilenode, dowhileinvoker);
        log.debug("Going to evaluate do while expression for " + donode.getName());
        if (!evaluate(this.dowhilenode, inputPorts, this.invokerMap)) {
            log.debug("Expression evaluation is false so calling EndDoWhile");
            runflag = false;
        } else {
            if (readyNodes.size() != 1) {
                throw new WorkFlowInterpreterException("More than one dowhile execution not supported");
            }
            Node whileNode = readyNodes.get(0);
            log.debug("Expression evaluation is true so invoking service again " + whileNode.getName());
            this.interpreter.handleWSComponent(whileNode);
        }
    }
    // WS node should be done
    dowhilenode.setState(NodeExecutionState.FINISHED);
    EndDoWhileNode endDoWhileNode = this.dowhilenode.getEndDoWhileNode();
    // /////////////////////////////////////////////////////////
    // // Do WHile finished execution thus we can set the //////
    // //inputs to the EndDOWHile and resume the executions/////
    SystemComponentInvoker invoker = new SystemComponentInvoker();
    List<DataPort> inputports = endDoWhileNode.getInputPorts();
    for (int inputPortIndex = 0; inputPortIndex < inputports.size(); inputPortIndex++) {
        Object inputVal = dowhileinvoker.getOutput(inputports.get(inputPortIndex).getFromPort().getID());
        invoker.addOutput(endDoWhileNode.getOutputPort(inputPortIndex).getID(), inputVal);
    }
    this.invokerMap.put(endDoWhileNode, invoker);
    // TODO send mail once the iterations have converged
    endDoWhileNode.setState(NodeExecutionState.FINISHED);
    this.threadExecutor.shutdown();
    return true;
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) 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) EndDoWhileNode(org.apache.airavata.workflow.model.graph.system.EndDoWhileNode) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)

Example 39 with WorkflowRuntimeException

use of org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException 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 40 with WorkflowRuntimeException

use of org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException 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

WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)41 DataPort (org.apache.airavata.workflow.model.graph.DataPort)25 GraphException (org.apache.airavata.workflow.model.graph.GraphException)13 DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)12 Node (org.apache.airavata.workflow.model.graph.Node)11 DataType (org.apache.airavata.model.application.io.DataType)10 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)9 ComponentDataPort (org.apache.airavata.workflow.model.component.ComponentDataPort)8 Port (org.apache.airavata.workflow.model.graph.Port)8 Kind (org.apache.airavata.workflow.model.graph.Port.Kind)7 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)7 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)6 LinkedList (java.util.LinkedList)4 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)4 EPRPort (org.apache.airavata.workflow.model.graph.EPRPort)4 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)4 Point (java.awt.Point)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)3