Search in sources :

Example 1 with WorkflowException

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

the class WorkflowInterpreter method handleForEach.

private void handleForEach(Node node) throws WorkflowException {
    final ForEachNode forEachNode = (ForEachNode) node;
    EndForEachNode endForEachNode = null;
    Collection<Node> repeatNodes = node.getOutputPort(0).getToNodes();
    // we will support only one for now
    if (repeatNodes.size() != 1) {
        throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
    }
    Iterator<Node> iterator = repeatNodes.iterator();
    if (iterator.hasNext()) {
        Node middleNode = iterator.next();
        // output
        if ((!(middleNode instanceof WSNode)) && (!(middleNode instanceof SubWorkflowNode))) {
            throw new WorkFlowInterpreterException("Encountered Node inside foreach that is not a WSNode" + middleNode);
        } else if (middleNode instanceof SubWorkflowNode) {
            /* Get the EndforEach Node of the Subworkflow */
            Iterator<Node> subWorkflowOut = middleNode.getOutputPort(0).getToNodes().iterator();
            while (subWorkflowOut.hasNext()) {
                Node node2 = subWorkflowOut.next();
                if (node2 instanceof EndForEachNode) {
                    endForEachNode = (EndForEachNode) node2;
                }
            }
            final LinkedList<String> listOfValues = new LinkedList<String>();
            InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
            final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
            Workflow workflow1 = ((SubWorkflowNode) middleNode).getWorkflow();
            List<NodeImpl> nodes = workflow1.getGraph().getNodes();
            List<Node> wsNodes = new ArrayList<Node>();
            /* Take the List of WSNodes in the subworkflow */
            for (NodeImpl subWorkflowNode : nodes) {
                if (subWorkflowNode instanceof WSNode) {
                    wsNodes.add(subWorkflowNode);
                }
            }
            for (int i = 0; i < wsNodes.size(); i++) {
                final WSNode node1 = (WSNode) wsNodes.get(i);
                SystemComponentInvoker systemInvoker = null;
                List<DataPort> outputPorts1 = node1.getOutputPorts();
                List<Node> endForEachNodes = new ArrayList<Node>();
                for (DataPort port : outputPorts1) {
                    Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
                    while (endForEachNodeItr1.hasNext()) {
                        Node node2 = endForEachNodeItr1.next();
                        if (node2 instanceof EndForEachNode) {
                            endForEachNodes.add(node2);
                        } else if (node2 instanceof OutputNode) {
                        // intentionally left noop
                        } else {
                            throw new WorkFlowInterpreterException("Found More than one node inside foreach");
                        }
                    }
                }
                final List<Node> finalEndForEachNodes = endForEachNodes;
                Iterator<Node> endForEachNodeItr1 = node1.getOutputPort(0).getToNodes().iterator();
                while (endForEachNodeItr1.hasNext()) {
                    Node node2 = endForEachNodeItr1.next();
                    // Start reading input came for foreach node
                    int parallelRuns = listOfValues.size() * node1.getOutputPorts().size();
                    if (listOfValues.size() > 0) {
                        forEachNode.setState(NodeExecutionState.EXECUTING);
                        node1.setState(NodeExecutionState.EXECUTING);
                        List<DataPort> outputPorts = node1.getOutputPorts();
                        final AtomicInteger counter = new AtomicInteger();
                        for (Node endFor : endForEachNodes) {
                            systemInvoker = new SystemComponentInvoker();
                            this.invokerMap.put(endFor, systemInvoker);
                        }
                        final Map<Node, Invoker> finalMap = this.invokerMap;
                        new Thread() {

                            @Override
                            public void run() {
                                try {
                                    runInThread(listOfValues, forEachNode, node1, finalEndForEachNodes, finalMap, counter, inputNumbers);
                                } catch (WorkflowException e) {
                                    log.error(e.getLocalizedMessage(), e);
                                } catch (RegistryException e) {
                                    log.error(e.getMessage(), e);
                                } catch (TException e) {
                                    log.error(e.getMessage(), e);
                                }
                            }
                        }.start();
                        while (counter.intValue() < parallelRuns) {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                            }
                        }
                    // if (!(node2 instanceof OutputNode)) {
                    // listOfValues.removeAll(listOfValues);
                    // String output = (String) systemInvoker.getOutput(node1.getOutputPort(0).getName());
                    // XmlElement xmlElement = XMLUtil.stringToXmlElement("<result>" + output + "</result>");
                    // Iterator iterator1 = xmlElement.children().iterator();
                    // while (iterator1.hasNext()) {
                    // Object next1 = iterator1.next();
                    // if (next1 instanceof XmlElement) {
                    // listOfValues.add((String) ((XmlElement) next1).children().iterator().next());
                    // }
                    // }
                    // }
                    }
                }
            }
            // we have finished execution so end foreach is finished
            // todo this has to be done in a separate thread
            endForEachNode.setState(NodeExecutionState.FINISHED);
            middleNode.setState(NodeExecutionState.FINISHED);
            node.setState(NodeExecutionState.FINISHED);
        } else {
            // First node after foreach should end with EndForEachNode
            List<DataPort> outputPorts1 = middleNode.getOutputPorts();
            List<Node> endForEachNodes = new ArrayList<Node>();
            for (DataPort port : outputPorts1) {
                Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
                while (endForEachNodeItr1.hasNext()) {
                    Node node2 = endForEachNodeItr1.next();
                    if (node2 instanceof EndForEachNode) {
                        endForEachNodes.add(node2);
                    } else if (node2 instanceof OutputNode) {
                    // intentionally left noop
                    } else {
                        throw new WorkFlowInterpreterException("Found More than one node inside foreach");
                    }
                }
            }
            final List<Node> finalEndForEachNodes = endForEachNodes;
            final Node foreachWSNode = middleNode;
            final LinkedList<String> listOfValues = new LinkedList<String>();
            // Start reading input came for foreach node
            InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
            final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
            int parallelRuns = createInputValues(listOfValues, inputNumbers).size() * outputPorts1.size();
            if (listOfValues.size() > 0) {
                forEachNode.setState(NodeExecutionState.EXECUTING);
                foreachWSNode.setState(NodeExecutionState.EXECUTING);
                List<DataPort> outputPorts = middleNode.getOutputPorts();
                final AtomicInteger counter = new AtomicInteger();
                for (Node endFor : endForEachNodes) {
                    final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
                    this.invokerMap.put(endFor, systemInvoker);
                }
                final Map<Node, Invoker> finalInvokerMap = this.invokerMap;
                new Thread() {

                    @Override
                    public void run() {
                        try {
                            runInThread(listOfValues, forEachNode, foreachWSNode, finalEndForEachNodes, finalInvokerMap, counter, inputNumbers);
                        } catch (WorkflowException e) {
                            log.error(e.getLocalizedMessage(), e);
                        } catch (RegistryException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (TException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }.start();
                while (counter.intValue() < parallelRuns) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
                // we have finished execution so end foreach is finished
                // todo this has to be done in a separate thread
                middleNode.setState(NodeExecutionState.FINISHED);
                for (Node endForEach : endForEachNodes) {
                    endForEach.setState(NodeExecutionState.FINISHED);
                }
            } else {
                throw new WorkFlowInterpreterException("No array values found for foreach");
            }
        }
    }
}
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) DataPort(org.apache.airavata.workflow.model.graph.DataPort) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) Workflow(org.apache.airavata.workflow.model.wf.Workflow) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with WorkflowException

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

the class WorkflowEngineImpl method launchExperiment.

@Override
public void launchExperiment(String experimentId, String token) throws WorkflowEngineException {
    try {
        ExperimentCatalog experimentCatalog = RegistryFactory.getDefaultExpCatalog();
        Experiment experiment = (Experiment) experimentCatalog.get(ExperimentCatalogModelType.EXPERIMENT, experimentId);
        WorkflowCatalog workflowCatalog = WorkflowCatalogFactory.getWorkflowCatalog();
        WorkflowInterpreterConfiguration config = new WorkflowInterpreterConfiguration(new Workflow(workflowCatalog.getWorkflow(experiment.getApplicationId()).getGraph()));
        final WorkflowInterpreter workflowInterpreter = new WorkflowInterpreter(experiment, token, config, getOrchestratorClient(), rabbitMQPublisher);
        new Thread() {

            public void run() {
                try {
                    workflowInterpreter.scheduleDynamically();
                } catch (WorkflowException e) {
                    logger.error(e.getMessage(), e);
                } catch (RegistryException e) {
                    logger.error(e.getMessage(), e);
                } catch (AiravataException e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }.start();
    } catch (Exception e) {
        logger.error("Error while retrieving the experiment", e);
        WorkflowEngineException exception = new WorkflowEngineException("Error while launching the workflow experiment. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : ExperimentCatalog(org.apache.airavata.registry.cpi.ExperimentCatalog) WorkflowInterpreter(org.apache.airavata.workflow.engine.interpretor.WorkflowInterpreter) WorkflowCatalog(org.apache.airavata.registry.cpi.WorkflowCatalog) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) WorkflowInterpreterConfiguration(org.apache.airavata.workflow.engine.interpretor.WorkflowInterpreterConfiguration) Workflow(org.apache.airavata.workflow.model.wf.Workflow) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataClientConnectException(org.apache.airavata.model.error.AiravataClientConnectException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 3 with WorkflowException

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

the class DynamicInvoker method invoke.

/**
 * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#invoke()
 */
public boolean invoke() throws WorkflowException {
    try {
        Class<?> targetClass = Class.forName(this.className);
        Object obj = targetClass.newInstance();
        Method[] methods = targetClass.getDeclaredMethods();
        Method targetMethod = null;
        for (Method method : methods) {
            if (this.operationName.equals(method.getName())) {
                targetMethod = method;
                break;
            }
        }
        if (targetMethod == null) {
            throw new WorkflowException("Could not find the method using reflection: " + this.operationName);
        }
        targetMethod.setAccessible(true);
        this.result = targetMethod.invoke(obj, inputs);
    } catch (Exception e) {
        throw new WorkflowException(e);
    }
    return true;
}
Also used : WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) Method(java.lang.reflect.Method) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException)

Example 4 with WorkflowException

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

the class DynamicInvoker method setup.

/**
 * @see org.apache.airavata.xbaya.invoker.WorkflowInvoker#setup()
 */
public void setup() throws WorkflowException {
    Class[] parameters = new Class[] { URL.class };
    URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Class sysclass = URLClassLoader.class;
    try {
        Method method = sysclass.getDeclaredMethod("addURL", parameters);
        method.setAccessible(true);
        method.invoke(sysloader, new Object[] { this.jarUrl });
    } catch (Throwable t) {
        t.printStackTrace();
        throw new WorkflowException("Error, could not add URL to system classloader");
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) Method(java.lang.reflect.Method) URL(java.net.URL)

Example 5 with WorkflowException

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

the class XBaya method parseArguments.

private void parseArguments(String[] args) {
    try {
        this.config = new XBayaConfiguration();
        int index = 0;
        while (index < args.length) {
            String arg = args[index];
            String possibleValue = "";
            if ((index + 1) < args.length) {
                possibleValue = args[index + 1];
            }
            logger.debug("arg: " + arg + " " + possibleValue);
            if ("-help".equalsIgnoreCase(arg)) {
                printUsage();
                System.exit(0);
            } else if ("-config".equalsIgnoreCase(arg)) {
                index++;
                String configPath = args[index];
                try {
                    this.config.loadConfiguration(configPath);
                } catch (RuntimeException e) {
                    String message = "Error while reading config file, " + configPath;
                    logger.warn(message, e);
                    this.config.addError(new WorkflowException(message, e));
                }
            } else if ("-title".equalsIgnoreCase(arg)) {
                index++;
                this.config.setTitle(args[index]);
            } else if ("-workflow".equalsIgnoreCase(arg)) {
                index++;
                this.config.setWorkflow(args[index]);
            } else if ("-startMonitor".equalsIgnoreCase(arg)) {
                this.config.setStartMonitor(true);
            } else if ("-brokerURL".equalsIgnoreCase(arg)) {
                index++;
                String brokerURL = args[index];
                try {
                    this.config.setBrokerURL(parseURL(brokerURL));
                } catch (URISyntaxException e) {
                    String message = "The broker URL is in wrong format: " + brokerURL;
                    logger.warn(message, e);
                    this.config.addError(new WorkflowException(message, e));
                }
            } else if ("-odeEngine".equalsIgnoreCase(arg)) {
                index++;
                this.config.setOdeURL(args[index]);
            } else if ("-templateID".equalsIgnoreCase(arg)) {
                index++;
                this.config.setWorkflow(args[index]);
            } else if ("-topic".equalsIgnoreCase(arg)) {
                index++;
                this.config.setTopic(args[index]);
            } else if ("-pullMode".equalsIgnoreCase(arg)) {
                if (index < args.length - 1) {
                    String nextArg = args[index + 1];
                    if (nextArg.startsWith("-")) {
                        this.config.setPullMode(true);
                    } else if ("true".equalsIgnoreCase(nextArg)) {
                        index++;
                        this.config.setPullMode(true);
                    } else if ("false".equalsIgnoreCase(nextArg)) {
                        index++;
                        this.config.setPullMode(false);
                    } else {
                        String message = "-pullMode has to be either true or false, not " + nextArg;
                        logger.warn(message);
                        this.config.addError(new WorkflowException(message));
                    }
                } else {
                    // This is the last arg
                    this.config.setPullMode(true);
                }
            } else if ("-messageBoxURL".equalsIgnoreCase(arg) || "-msgBoxURL".equalsIgnoreCase(arg)) {
                index++;
                String messageBoxURL = args[index];
                try {
                    this.config.setMessageBoxURL(parseURL(messageBoxURL));
                } catch (URISyntaxException e) {
                    String message = "The message box URL is in wrong format: " + messageBoxURL;
                    logger.warn(message, e);
                    this.config.addError(new WorkflowException(message, e));
                }
            } else if ("-width".equalsIgnoreCase(arg)) {
                index++;
                String width = args[index];
                try {
                    this.config.setWidth(Integer.parseInt(width));
                } catch (NumberFormatException e) {
                    String message = "The width must be an integer: " + width;
                    logger.warn(message, e);
                    this.config.addError(new WorkflowException(message, e));
                }
            } else if ("-height".equalsIgnoreCase(arg)) {
                index++;
                String height = args[index];
                try {
                    this.config.setHeight(Integer.parseInt(height));
                } catch (NumberFormatException e) {
                    String message = "The height must be an integer: " + height;
                    logger.warn(message, e);
                    this.config.addError(new WorkflowException(message, e));
                }
            } else if ("-exitOnClose".equalsIgnoreCase(arg)) {
                index++;
                String exit = args[index];
                if ("false".equalsIgnoreCase(exit)) {
                    this.config.setCloseOnExit(false);
                }
            } else if ("-enableProvenance".equalsIgnoreCase(arg)) {
                index++;
                String exit = args[index];
                if ("true".equalsIgnoreCase(exit)) {
                    this.config.setCollectProvenance(true);
                }
            } else if ("-enableProvenanceSmartRun".equalsIgnoreCase(arg)) {
                index++;
                String exit = args[index];
                if ("true".equalsIgnoreCase(exit)) {
                    this.config.setProvenanceSmartRun(true);
                }
            } else if ("-runWithCrossProduct".equalsIgnoreCase(arg)) {
                index++;
                String exit = args[index];
                if ("false".equalsIgnoreCase(exit)) {
                    this.config.setRunWithCrossProduct(false);
                }
            } else if ("-mode".equalsIgnoreCase(arg)) {
                index++;
                String modeValue = args[index].toUpperCase();
                this.config.setXbayaExecutionMode(XBayaExecutionMode.valueOf(modeValue));
            } else if ("-x".equalsIgnoreCase(arg)) {
                index++;
                this.config.setX(Integer.parseInt(args[index]));
            } else if ("-y".equalsIgnoreCase(arg)) {
                index++;
                this.config.setY(Integer.parseInt(args[index]));
            } else {
                String message = "Unknown option: " + arg;
                logger.error(message);
                this.config.addError(new WorkflowException(message));
            }
            index++;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        String message = "Argument is missing after " + args[args.length - 1];
        logger.error(message, e);
        this.config.addError(new WorkflowException(message));
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        String message = "Unknown error while parsing the arguments";
        this.config.addError(new WorkflowException(message, e));
    }
}
Also used : WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) URISyntaxException(java.net.URISyntaxException)

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