Search in sources :

Example 16 with Workflow

use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.

the class WorkflowFiler method openWorkflow.

/**
 * Opens a current workflow from the local file.
 */
public void openWorkflow() {
    Workflow workflow = null;
    int returnVal = this.graphFileChooser.showOpenDialog(this.engine.getGUI().getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = this.graphFileChooser.getSelectedFile();
        logger.debug(file.getPath());
        try {
            String path = file.getPath();
            if (path.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
                WSGraph graph = WSGraphFactory.createGraph(file);
                workflow = Workflow.graphToWorkflow(graph);
            } else {
                JsonObject workflowObject = JSONUtil.loadJSON(file);
                // XmlElement workflowElement = XMLUtil.loadXML(file);
                // workflow = new Workflow(workflowElement);
                workflow = new Workflow(workflowObject);
            }
            GraphCanvas newGraphCanvas = engine.getGUI().newGraphCanvas(true);
            newGraphCanvas.setWorkflow(workflow);
            // this.engine.setWorkflow(workflow);
            engine.getGUI().getGraphCanvas().setWorkflowFile(file);
        } catch (IOException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.OPEN_FILE_ERROR, e);
        } catch (GraphException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
        } catch (ComponentException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
        } catch (RuntimeException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
        } catch (Error e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) ComponentException(org.apache.airavata.workflow.model.component.ComponentException) Workflow(org.apache.airavata.workflow.model.wf.Workflow) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) WSGraph(org.apache.airavata.workflow.model.graph.ws.WSGraph) File(java.io.File) GraphCanvas(org.apache.airavata.xbaya.ui.graph.GraphCanvas)

Example 17 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)

Example 18 with Workflow

use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.

the class BPELFiler method exportBPEL.

/**
 * Exports a BPEL process to the local file
 */
public void exportBPEL() {
    Workflow workflow = this.engine.getGUI().getWorkflow();
    BPELScript bpel = new BPELScript(workflow);
    // Check if there is any errors in the workflow first.
    ArrayList<String> warnings = new ArrayList<String>();
    if (!bpel.validate(warnings)) {
        StringBuilder buf = new StringBuilder();
        for (String warning : warnings) {
            buf.append("- ");
            buf.append(warning);
            buf.append("\n");
        }
        this.engine.getGUI().getErrorWindow().warning(buf.toString());
        return;
    }
    int returnVal = this.bpelFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = this.bpelFileChooser.getSelectedFile();
        logger.debug(file.getPath());
        String path = file.getPath();
        // Remove ".bpel" at the end if any
        if (path.endsWith(XBayaConstants.BPEL_SUFFIX)) {
            path = path.substring(0, path.length() - XBayaConstants.BPEL_SUFFIX.length());
        }
        // Add ".bpel" at the end of the file name
        File bpelFile = new File(path + XBayaConstants.BPEL_SUFFIX);
        // Add ".wsdl" at the end of the file name
        File wsdlFile = new File(path + XBayaConstants.WSDL_SUFFIX);
    // try {
    // // Create the script.
    // bpel.create(BPELScriptType.BPEL2);
    // 
    // GpelProcess gpelProcess = bpel.getGpelProcess();
    // XMLUtil.saveXML(gpelProcess.xml(), bpelFile);
    // 
    // WorkflowWSDL workflowWSDL = bpel.getWorkflowWSDL();
    // XMLUtil.saveXML(workflowWSDL.getWsdlDefinitions().xml(), wsdlFile);
    // 
    // } catch (IOException e) {
    // this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
    // } catch (GraphException e) {
    // this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_NOT_READY_ERROR, e);
    // } catch (RuntimeException e) {
    // this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
    // } catch (Error e) {
    // this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
    // }
    }
}
Also used : BPELScript(org.apache.airavata.workflow.model.gpel.script.BPELScript) ArrayList(java.util.ArrayList) Workflow(org.apache.airavata.workflow.model.wf.Workflow) File(java.io.File)

Example 19 with Workflow

use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.

the class JythonFiler method exportJythonScript.

/**
 * Exports a Jython script to the local file
 */
public void exportJythonScript() {
    Workflow workflow = this.engine.getGUI().getWorkflow();
    JythonScript script = new JythonScript(workflow, this.engine.getConfiguration());
    // Check if there is any errors in the workflow first.
    ArrayList<String> warnings = new ArrayList<String>();
    if (!script.validate(warnings)) {
        StringBuilder buf = new StringBuilder();
        for (String warning : warnings) {
            buf.append("- ");
            buf.append(warning);
            buf.append("\n");
        }
        this.engine.getGUI().getErrorWindow().warning(buf.toString());
        return;
    }
    int returnVal = this.jythonFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = this.jythonFileChooser.getSelectedFile();
        logger.debug(file.getPath());
        // Put ".py" at the end of the file name
        String path = file.getPath();
        if (!path.endsWith(XBayaConstants.JYTHON_SCRIPT_SUFFIX)) {
            file = new File(path + XBayaConstants.JYTHON_SCRIPT_SUFFIX);
        }
        try {
            // Create the script.
            script.create();
            // Write to a file
            IOUtil.writeToFile(script.getJythonString(), file);
        } catch (IOException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
        } catch (GraphException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
        } catch (RuntimeException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
        } catch (Error e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) ArrayList(java.util.ArrayList) Workflow(org.apache.airavata.workflow.model.wf.Workflow) IOException(java.io.IOException) JythonScript(org.apache.airavata.xbaya.jython.script.JythonScript) File(java.io.File)

Example 20 with Workflow

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

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