Search in sources :

Example 26 with GraphException

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

the class InputNode method edgeWasAdded.

/**
 * Called whan an Edge was added to the parameter port. Change the name of this node.
 *
 * @throws GraphException
 *
 * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
 */
@Override
protected void edgeWasAdded(Edge edge) throws GraphException {
    super.edgeWasAdded(edge);
    // TODO organize this.
    if (edge instanceof DataEdge) {
        DataEdge dataEdge = (DataEdge) edge;
        DataPort toPort = dataEdge.getToPort();
        DataType toType = toPort.getType();
        List<DataEdge> edges = getEdges();
        if (edges.size() == 1) {
            // The first edge.
            setParameterType(toType);
            if (!isConfigured() && toPort instanceof WSPort) {
                // Copy
                copyDefaultConfiguration((WSPort) toPort);
            }
        } else if (edges.size() > 1) {
            // Not the first edge.
            DataType parameterType = getParameterType();
            if (!toType.equals(WSConstants.XSD_ANY_TYPE) && !parameterType.equals(toType)) {
                throw new GraphException("Cannot connect ports with different types.");
            }
        } else {
            // Should not happen.
            throw new WorkflowRuntimeException("edges.size(): " + edges.size());
        }
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) DataType(org.apache.airavata.model.appcatalog.appinterface.DataType) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)

Example 27 with GraphException

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

the class OutputNode method edgeWasAdded.

/**
 * Called whan an Edge was added to the parameter port. Change the name of this node.
 *
 * @throws GraphException
 *
 * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
 */
@Override
protected void edgeWasAdded(Edge edge) throws GraphException {
    super.edgeWasAdded(edge);
    // TODO organize
    Port fromPort = edge.getFromPort();
    if (edge instanceof DataEdge) {
        DataPort fromDataPort = (DataPort) fromPort;
        DataType fromType = fromDataPort.getType();
        List<DataEdge> edges = getEdges();
        if (edges.size() == 1) {
            setParameterType(fromType);
            if (!isConfigured() && fromDataPort instanceof WSPort) {
                setName(fromDataPort.getName());
                WSComponentPort componentPort = ((WSPort) fromDataPort).getComponentPort();
                setDescription(componentPort.getDescription());
                setMetadata(componentPort.getAppinfo());
            }
        } else {
            throw new GraphException("Cannot connect more than one output ports to the output parameter.");
        }
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) DataPort(org.apache.airavata.workflow.model.graph.DataPort) WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort) Port(org.apache.airavata.workflow.model.graph.Port) DataType(org.apache.airavata.model.application.io.DataType) WSComponentPort(org.apache.airavata.workflow.model.component.ws.WSComponentPort)

Example 28 with GraphException

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

the class EndifNode method portTypeChanged.

/**
 * @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
 */
@Override
protected void portTypeChanged(SystemDataPort port) throws GraphException {
    super.portTypeChanged(port);
    List<DataPort> inputPorts = getInputPorts();
    List<DataPort> outputPorts = getOutputPorts();
    int size = outputPorts.size();
    Kind kind = port.getKind();
    int index;
    if (kind == Kind.DATA_IN) {
        index = inputPorts.indexOf(port) % size;
    } else if (kind == Kind.DATA_OUT) {
        index = outputPorts.indexOf(port);
    } else {
        throw new WorkflowRuntimeException();
    }
    DataPort inputPort1 = inputPorts.get(index);
    DataPort inputPort2 = inputPorts.get(size + index);
    DataPort outputPort = outputPorts.get(index);
    DataType inputType1 = inputPort1.getType();
    DataType inputType2 = inputPort2.getType();
    DataType outputType = outputPort.getType();
    DataType portType = port.getType();
    if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
        // Do nothing
        return;
    }
    if (port == inputPort1) {
        // input1 -> input2
        if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
            inputPort2.copyType(port);
        } else if (inputType2.equals(portType)) {
        // Do nothing.
        } else {
            String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
            throw new GraphException(message);
        }
        // input1 -> output
        if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
            outputPort.copyType(port);
        } else if (outputType.equals(portType)) {
        // Do nothing.
        } else {
            String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
            throw new GraphException(message);
        }
    } else if (port == inputPort2) {
        // input2 -> input1
        if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
            inputPort1.copyType(port);
        } else if (inputType1.equals(portType)) {
        // Do nothing.
        } else {
            String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
            throw new GraphException(message);
        }
        // input2 -> output
        if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
            outputPort.copyType(port);
        } else if (outputType.equals(portType)) {
        // Do nothing.
        } else {
            String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
            throw new GraphException(message);
        }
    } else if (port == outputPort) {
        // output -> input1
        if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
            inputPort1.copyType(port);
        } else if (inputType1.equals(portType)) {
        // Do nothing.
        } else {
            String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
            throw new GraphException(message);
        }
        // output -> input2
        if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
            inputPort2.copyType(port);
        } else if (inputType2.equals(portType)) {
        // Do nothing.
        } else {
            String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of input " + index + " (" + outputType + ").";
            throw new GraphException(message);
        }
    } else {
        throw new WorkflowRuntimeException();
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) ComponentDataPort(org.apache.airavata.workflow.model.component.ComponentDataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) Kind(org.apache.airavata.workflow.model.graph.Port.Kind) DataType(org.apache.airavata.model.application.io.DataType) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)

Example 29 with GraphException

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

the class JythonScript method writeOutput.

private void writeOutput(OutputNode node, PrintWriter pw) throws GraphException {
    String id = node.getID();
    Port port = node.getPort();
    Node fromNode = port.getFromNode();
    if (fromNode == null) {
        throw new GraphException("Output parameter has to be connected to some node.");
    }
    Port fromPort = port.getFromPort();
    if (fromNode instanceof InputNode) {
        // The OutputNode is directly connected to an InputNode.
        pw.println(TAB + id + VALUE_SUFFIX + " = " + PROPERTIES_VARIABLE + "." + GET_PROPERTY_METHOD + "('" + fromNode.getID() + "')");
    } else {
        pw.println(TAB + "# Wait output " + id);
        pw.println(TAB + id + VALUE_SUFFIX + " = " + fromNode.getID() + INVOKER_SUFFIX + "." + GET_OUTPUT_METHOD + "('" + fromPort.getName() + "')");
    }
    pw.println(TAB + "print '" + id + " = ', " + id + VALUE_SUFFIX);
    // This might try to remove a node that has been removed
    // already, but it's OK.
    this.executingNodes.remove(fromNode);
    pw.println();
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) Port(org.apache.airavata.workflow.model.graph.Port) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) IfNode(org.apache.airavata.workflow.model.graph.system.IfNode) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) Node(org.apache.airavata.workflow.model.graph.Node) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) ConstantNode(org.apache.airavata.workflow.model.graph.system.ConstantNode) EndifNode(org.apache.airavata.workflow.model.graph.system.EndifNode) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode)

Example 30 with GraphException

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

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