Search in sources :

Example 66 with Node

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

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

the class WorkflowInterpreter method handleSubWorkComponent.

private void handleSubWorkComponent(Node node) throws WorkflowException {
    // TODO we will not support this in 0.13
    notifyViaInteractor(WorkflowExecutionMessage.OPEN_SUBWORKFLOW, node);
    // setting the inputs
    Workflow subWorkflow = ((SubWorkflowNode) node).getWorkflow();
    ArrayList<Node> subWorkflowInputNodes = getInputNodes(subWorkflow);
    List<DataPort> inputPorts = node.getInputPorts();
    for (DataPort port : inputPorts) {
        Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);
        if (null == inputVal) {
            throw new WorkFlowInterpreterException("Unable to find inputs for the subworkflow node node:" + node.getID());
        }
        for (Iterator<Node> iterator = subWorkflowInputNodes.iterator(); iterator.hasNext(); ) {
            InputNode inputNode = (InputNode) iterator.next();
            if (inputNode.getName().equals(port.getName())) {
                inputNode.setDefaultValue(inputVal);
            }
        }
    }
    for (Iterator<Node> iterator = subWorkflowInputNodes.iterator(); iterator.hasNext(); ) {
        InputNode inputNode = (InputNode) iterator.next();
        if (inputNode.getDefaultValue() == null) {
            throw new WorkFlowInterpreterException("Input not set for  :" + inputNode.getID());
        }
    }
    try {
        WorkflowInterpreter subworkflowInterpreter = (WorkflowInterpreter) getInputViaInteractor(WorkflowExecutionMessage.INPUT_WORKFLOWINTERPRETER_FOR_WORKFLOW, subWorkflow);
        subworkflowInterpreter.scheduleDynamically();
    } catch (Exception e) {
        throw new WorkflowException(e);
    }
}
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) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) Workflow(org.apache.airavata.workflow.model.wf.Workflow) XPathExpressionException(javax.xml.xpath.XPathExpressionException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) DataPort(org.apache.airavata.workflow.model.graph.DataPort) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)

Example 68 with Node

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

the class WorkflowInterpreter method taskOutputChanged.

@Subscribe
public void taskOutputChanged(TaskOutputChangeEvent taskOutputEvent) {
    String taskId = taskOutputEvent.getTaskIdentity().getTaskId();
    if (isTaskAwaiting(taskId)) {
        ProcessState state = ProcessState.COMPLETED;
        Node node = getAwaitingNodeForTask(taskId);
        List<OutputDataObjectType> applicationOutputs = taskOutputEvent.getOutput();
        Map<String, String> outputData = new HashMap<String, String>();
        for (OutputDataObjectType outputObj : applicationOutputs) {
            List<DataPort> outputPorts = node.getOutputPorts();
            for (DataPort dataPort : outputPorts) {
                if (dataPort.getName().equals(outputObj.getName())) {
                    outputData.put(outputObj.getName(), outputObj.getValue());
                }
            }
        }
        nodeOutputData.put(node, outputData);
        setupNodeDetailsOutput(node);
        node.setState(NodeExecutionState.FINISHED);
        try {
            publishNodeStatusChange(WorkflowNodeState.COMPLETED, node.getID(), experiment.getExperimentID());
            updateWorkflowNodeStatus(nodeInstanceList.get(node), state);
        } catch (RegistryException e) {
            log.error(e.getMessage(), e);
        } catch (AiravataException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : ProcessState(org.apache.airavata.model.status.ProcessState) DataPort(org.apache.airavata.workflow.model.graph.DataPort) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) 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) AiravataException(org.apache.airavata.common.exception.AiravataException) Subscribe(com.google.common.eventbus.Subscribe)

Example 69 with Node

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

the class WorkflowInterpreter method scheduleDynamically.

/**
 * @throws WorkflowException
 * @throws RegistryException
 */
public void scheduleDynamically() throws WorkflowException, RegistryException, AiravataException {
    try {
        this.getWorkflow().setExecutionState(WorkflowExecutionState.RUNNING);
        ArrayList<Node> inputNodes = this.getInputNodesDynamically();
        List<InputDataObjectType> experimentInputs = experiment.getExperimentInputs();
        Map<String, String> inputDataStrings = new HashMap<String, String>();
        for (InputDataObjectType dataObjectType : experimentInputs) {
            inputDataStrings.put(dataObjectType.getName(), dataObjectType.getValue());
        }
        for (Node node : inputNodes) {
            publishNodeStatusChange(WorkflowNodeState.EXECUTING, node.getID(), experiment.getExperimentID());
            if (inputDataStrings.containsKey(node.getID())) {
                ((InputNode) node).setDefaultValue(inputDataStrings.get(node.getID()));
            } else {
                log.warn("value for node not found " + node.getName());
            }
        }
        for (int i = 0; i < inputNodes.size(); ++i) {
            Node node = inputNodes.get(i);
            invokedNode.add(node);
            node.setState(NodeExecutionState.FINISHED);
            publishNodeStatusChange(WorkflowNodeState.INVOKED, node.getID(), experiment.getExperimentID());
            notifyViaInteractor(WorkflowExecutionMessage.NODE_STATE_CHANGED, null);
            String portId = ((InputNode) node).getID();
            Object portValue = ((InputNode) node).getDefaultValue();
            DataType dataType = ((InputNode) node).getDataType();
            // Saving workflow input Node data before running the workflow
            WorkflowNodeDetails workflowNode = createWorkflowNodeDetails(node);
            InputDataObjectType elem = new InputDataObjectType();
            elem.setName(portId);
            elem.setValue(portValue == null ? null : portValue.toString());
            elem.setType(dataType);
            workflowNode.addToNodeInputs(elem);
            getExperimentCatalog().update(ExperimentCatalogModelType.WORKFLOW_NODE_DETAIL, workflowNode, workflowNode.getNodeInstanceId());
            updateWorkflowNodeStatus(workflowNode, WorkflowNodeState.COMPLETED);
            publishNodeStatusChange(WorkflowNodeState.COMPLETED, node.getID(), experiment.getExperimentID());
        }
        while (this.getWorkflow().getExecutionState() != WorkflowExecutionState.STOPPED) {
            ArrayList<Thread> threadList = new ArrayList<Thread>();
            if (getRemainNodesDynamically() == 0) {
                notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_STATE_CHANGED, WorkflowExecutionState.STOPPED);
            }
            // ok we have paused sleep
            if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                log.info("Workflow execution " + experiment.getExperimentID() + " is paused.");
                while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
                    try {
                        Thread.sleep(400);
                    } catch (InterruptedException e) {
                        log.error(e.getMessage(), e);
                    }
                }
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
                    continue;
                }
                log.info("Workflow execution " + experiment.getExperimentID() + " is resumed.");
            }
            // get task list and execute them
            ArrayList<Node> readyNodes = this.getReadyNodesDynamically();
            for (final Node node : readyNodes) {
                if (node.isBreak()) {
                    this.notifyPause();
                    break;
                }
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED || this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
                    break;
                }
                WorkflowNodeDetails workflowNodeDetails = createWorkflowNodeDetails(node);
                // Since this is an independent node execution we can run these nodes in separate threads.
                Thread th = new Thread() {

                    public synchronized void run() {
                        try {
                            executeDynamically(node);
                        } catch (WorkflowException e) {
                            log.error("Error execution workflow Node : " + node.getID());
                            return;
                        } catch (TException e) {
                            log.error(e.getMessage(), e);
                        } catch (RegistryException e) {
                            log.error(e.getMessage(), e);
                        } catch (AiravataException e) {
                            log.error(e.getMessage(), e);
                        }
                    }
                };
                updateWorkflowNodeStatus(workflowNodeDetails, WorkflowNodeState.INVOKED);
                publishNodeStatusChange(WorkflowNodeState.INVOKED, node.getID(), experiment.getExperimentID());
                threadList.add(th);
                th.start();
                if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STEP) {
                    this.getWorkflow().setExecutionState(WorkflowExecutionState.PAUSED);
                    // TODO update experiment state to suspend
                    break;
                }
            }
            // This thread waits until parallel nodes get finished to send the outputs dynamically.
            for (Thread th : threadList) {
                try {
                    th.join();
                } catch (InterruptedException e) {
                    // To change body of catch statement use File | Settings | File Templates.
                    e.printStackTrace();
                }
            }
            // Above statement set the nodeCount back to 0.
            // TODO commented this for foreach, fix this.
            sendOutputsDynamically();
            // Dry run sleep a lil bit to release load
            if (readyNodes.size() == 0) {
                // so we should pause the execution
                if (InterpreterUtil.getRunningNodeCountDynamically(this.getGraph()) == 0) /**
                 *&& InterpreterUtil.getFailedNodeCountDynamically(this.getGraph()) != 0*
                 */
                {
                    // Since airavata only support workflow interpreter server mode we do not want to keep thread in sleep mode
                    // continuously, so we make the workflow stop when there's nothing to do.
                    this.getWorkflow().setExecutionState(WorkflowExecutionState.STOPPED);
                }
                try {
                    Thread.sleep(400);
                } catch (InterruptedException e) {
                    log.error("Workflow Excecution is interrupted !");
                    return;
                }
            }
        }
        if (InterpreterUtil.getFailedNodeCountDynamically(this.getGraph()) == 0) {
            if (this.config.isActOnProvenance()) {
                try {
                    // this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().setWorkflowInstanceStatus(
                    // this.config.getTopic(), this.config.getTopic(), State.FINISHED);
                    updateExperimentStatus(ExperimentState.COMPLETED);
                } catch (Exception e) {
                    throw new WorkflowException(e);
                }
            // System.out.println(this.config.getConfiguration().getJcrComponentRegistry().getExperimentCatalog().getWorkflowStatus(this.topic));
            }
        } else {
            if (this.config.isActOnProvenance()) {
                // this.getConfig().getConfiguration().getAiravataAPI().getProvenanceManager().
                // setWorkflowInstanceStatus(this.config.getTopic(),this.config.getTopic(), State.FAILED);
                updateExperimentStatus(ExperimentState.FAILED);
            }
        }
        UUID uuid = UUID.randomUUID();
        notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_TASK_START, new WorkflowInterpreterInteractor.TaskNotification("Stop Workflow", "Cleaning up resources for Workflow", uuid.toString()));
        // Send Notification for output values
        finish();
        // Sleep to provide for notification delay
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }
        notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_TASK_END, new WorkflowInterpreterInteractor.TaskNotification("Stop Workflow", "Cleaning up resources for Workflow", uuid.toString()));
    } catch (RuntimeException e) {
        // we reset all the state
        cleanup();
        raiseException(e);
    } finally {
        cleanup();
        this.getWorkflow().setExecutionState(WorkflowExecutionState.NONE);
        ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(ExperimentState.COMPLETED, experiment.getExperimentId(), gatewayId);
        MessageContext msgCtx = new MessageContext(event, MessageType.EXPERIMENT, AiravataUtils.getId("EXPERIMENT"), gatewayId);
        msgCtx.setUpdatedTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
        publisher.publish(msgCtx);
    }
}
Also used : TException(org.apache.thrift.TException) 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) Timestamp(java.sql.Timestamp) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) ExpCatChildDataType(org.apache.airavata.registry.cpi.ExpCatChildDataType) MessageContext(org.apache.airavata.messaging.core.MessageContext) AiravataException(org.apache.airavata.common.exception.AiravataException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException)

Example 70 with Node

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

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