Search in sources :

Example 11 with WorkflowException

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

the class WorkflowInterpreter method createInputValues.

private List<String> createInputValues(LinkedList<String> listOfValues, Integer[] inputNumbers) throws WorkflowException {
    List<String> inputValues = null;
    try {
        inputValues = new ArrayList<String>();
        if (inputNumbers.length == 1) {
            return listOfValues;
        }
        if (this.config.isRunWithCrossProduct()) {
            for (int i = 0; i < inputNumbers[0]; i++) {
                for (int j = 0; j < inputNumbers[1]; j++) {
                    inputValues.add(listOfValues.get(i) + StringUtil.DELIMETER + listOfValues.get(inputNumbers[0] + j));
                }
            }
        } else {
            List<String[]> inputList = new ArrayList<String[]>();
            int startIndex = 0;
            for (int input = 0; input < inputNumbers.length; input++) {
                String[] inputArray = new String[inputNumbers[input]];
                for (int travers = 0; travers < inputNumbers[input]; travers++) {
                    inputArray[travers] = listOfValues.get(startIndex++);
                }
                inputList.add(inputArray);
            }
            int inputSize = 1;
            for (String[] inputArrays : inputList) {
                if (inputArrays.length != 1) {
                    inputSize = inputArrays.length;
                }
            }
            List<String[]> finalInputList = new ArrayList<String[]>();
            for (String[] inputArrays : inputList) {
                if (inputArrays.length == 1) {
                    String[] fullArray = new String[inputSize];
                    for (int i = 0; i < fullArray.length; i++) {
                        fullArray[i] = inputArrays[0];
                    }
                    finalInputList.add(fullArray);
                } else {
                    finalInputList.add(inputArrays);
                }
            }
            for (int i = 0; i < inputSize; i++) {
                String inputValue = "";
                for (String[] array : finalInputList) {
                    inputValue = inputValue + StringUtil.DELIMETER + StringUtil.quoteString(array[i]);
                }
                inputValue = inputValue.replaceFirst(StringUtil.DELIMETER, "");
                inputValues.add(inputValue);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new WorkflowException("Wrong number of Inputs to For EachNode");
    }
    return inputValues;
}
Also used : WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException)

Example 12 with WorkflowException

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

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

Aggregations

WorkflowException (org.apache.airavata.workflow.model.exceptions.WorkflowException)13 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)5 AiravataException (org.apache.airavata.common.exception.AiravataException)4 RegistryException (org.apache.airavata.registry.cpi.RegistryException)4 Node (org.apache.airavata.workflow.model.graph.Node)3 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)3 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)3 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)3 Workflow (org.apache.airavata.workflow.model.wf.Workflow)3 TException (org.apache.thrift.TException)3 Method (java.lang.reflect.Method)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 DataPort (org.apache.airavata.workflow.model.graph.DataPort)2 XmlElement (org.xmlpull.infoset.XmlElement)2 WSIFMessage (xsul.wsif.WSIFMessage)2 Dimension (java.awt.Dimension)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1