Search in sources :

Example 31 with GraphException

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

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

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

the class Workflow method parse.

private void parse(JsonObject workflowObject) throws GraphException, ComponentException {
    // Graph
    if (workflowObject.getAsJsonObject(WORKFLOW_TAG) == null) {
        throw new GraphException("Failed to parse the json object, workflow object doesn't exist");
    }
    JsonObject workflowObj = workflowObject.getAsJsonObject(WORKFLOW_TAG);
    JsonObject graphObject = workflowObj.getAsJsonObject(GraphSchema.GRAPH_TAG);
    this.graph = WSGraphFactory.createGraph(graphObject);
    bindComponents();
    // Image
    JsonPrimitive imagePrimitive = workflowObj.getAsJsonPrimitive(IMAGE_TAG);
    if (imagePrimitive != null) {
        String base64 = imagePrimitive.getAsString();
        byte[] bytes = Base64.decodeBase64(base64.getBytes());
        try {
            this.image = ImageIO.read(new ByteArrayInputStream(bytes));
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) JsonPrimitive(com.google.gson.JsonPrimitive) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 34 with GraphException

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

the class Workflow method parse.

/**
 * @param workflowElement
 * @throws GraphException
 * @throws ComponentException
 */
private void parse(XmlElement workflowElement) throws GraphException, ComponentException {
    // Graph
    XmlElement graphElement = workflowElement.element(GraphSchema.GRAPH_TAG);
    this.graph = WSGraphFactory.createGraph(graphElement);
    // WsdlDefinitions wsdl = null;
    // XmlElement wsdlsElement = workflowElement.element(WSDLS_TAG);
    // for (XmlElement wsdlElement : wsdlsElement.elements(null, WSDL_TAG)) {
    // String wsdlText = wsdlElement.requiredText();
    // try {
    // wsdl = WSDLUtil.stringToWSDL(wsdlText);
    // } catch (UtilsException e) {
    // logger.error(e.getMessage(), e);
    // }
    // String id = wsdlElement.attributeValue(NS_XWF, ID_ATTRIBUTE);
    // if (id == null || id.length() == 0) {
    // // xwf up to 2.2.6_2 doesn't have ID.
    // id = WSDLUtil.getWSDLQName(wsdl).toString();
    // }
    // addWSDL(id, wsdl);
    // }
    bindComponents();
    // Image
    XmlElement imageElement = workflowElement.element(IMAGE_TAG);
    if (imageElement != null) {
        String base64 = imageElement.requiredText();
        byte[] bytes = Base64.decodeBase64(base64.getBytes());
        try {
            this.image = ImageIO.read(new ByteArrayInputStream(bytes));
        } catch (IOException e) {
            // This should not happen and it's OK that image is broken. We
            // can reproduce it anytime.
            logger.error(e.getMessage(), e);
        }
    }
    XmlElement bpelElement = workflowElement.element(BPEL_TAG);
    if (bpelElement != null) {
        try {
            String bpelString = bpelElement.requiredText();
            XmlNamespace gpelNS = XmlInfosetBuilder.newInstance().newNamespace(BPELScript.GPEL, BPELScript.GPELNS);
        // GpelConstants.GPEL_NS = gpelNS;
        // this.gpelProcess = new GpelProcess(XMLUtil.stringToXmlElement(bpelString));
        } catch (RuntimeException e) {
            String error = "Failed to parse the BPEL document.";
            throw new GraphException(error, e);
        }
    }
    XmlElement workflowWSDLElement = workflowElement.element(WORKFLOW_WSDL_TAG);
    if (workflowWSDLElement != null) {
        try {
            String wsdlText = workflowWSDLElement.requiredText();
        // this.workflowWSDL = new WsdlDefinitions(XMLUtil.stringToXmlElement(wsdlText));
        } catch (RuntimeException e) {
            String error = "Failed to parse the workflow WSDL.";
            throw new GraphException(error, e);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlNamespace(org.xmlpull.infoset.XmlNamespace) XmlElement(org.xmlpull.infoset.XmlElement) IOException(java.io.IOException)

Example 35 with GraphException

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

Aggregations

GraphException (org.apache.airavata.workflow.model.graph.GraphException)38 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)18 DataPort (org.apache.airavata.workflow.model.graph.DataPort)15 Node (org.apache.airavata.workflow.model.graph.Node)11 DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)10 Port (org.apache.airavata.workflow.model.graph.Port)9 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)9 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)9 Workflow (org.apache.airavata.workflow.model.wf.Workflow)9 IOException (java.io.IOException)6 DataType (org.apache.airavata.model.application.io.DataType)6 LinkedList (java.util.LinkedList)5 ComponentException (org.apache.airavata.workflow.model.component.ComponentException)5 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)5 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)5 XmlElement (org.xmlpull.infoset.XmlElement)5 Point (java.awt.Point)4 File (java.io.File)4 JsonObject (com.google.gson.JsonObject)3 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)3