Search in sources :

Example 6 with GraphException

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

the class GraphCanvas method connect.

/**
 * Connects two ports specified.
 *
 * @param fromPort
 * @param toPort
 */
private void connect(Port fromPort, Port toPort) {
    try {
        // check the validity of the connection.
        Edge edge = this.graph.addEdge(fromPort, toPort);
        selectEdge(edge);
    } catch (GraphException e) {
        logger.error(e.getMessage(), e);
        this.engine.getGUI().getErrorWindow().warning(e.getMessage());
    } catch (RuntimeException e) {
        logger.error(e.getMessage(), e);
        this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR);
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) Edge(org.apache.airavata.workflow.model.graph.Edge)

Example 7 with GraphException

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

the class GraphCanvas method mouseReleased.

private void mouseReleased(MouseEvent event) {
    Point point = event.getPoint();
    if (this.draggedNode != null) {
        NodeController.getGUI(this.draggedNode).setDraggedFlag(false);
        this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
        // Check if it s stream grouping
        if (draggedNode instanceof InputNode) {
            StreamSourceNode streamNode = NodeController.getGUI(this.graph).getStreamSourceAt(point);
            if (streamNode != null) {
                streamNode.addInputNode((InputNode) draggedNode);
            }
        }
        this.draggedNode = null;
    }
    if (this.draggedPort != null) {
        GraphPiece graphPiece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
        if (graphPiece instanceof DynamicNode) {
            if (this.draggedPort.getKind() == Kind.DATA_OUT && draggedPort instanceof DataPort) {
                this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                DynamicNode dynamicNode = (DynamicNode) graphPiece;
                dynamicNode.getComponent();
                DataPort freePort = dynamicNode.getFreeInPort();
                try {
                    freePort.copyType((DataPort) draggedPort);
                } catch (GraphException e) {
                    engine.getGUI().getErrorWindow().error(e);
                    return;
                }
                // selectInputPort(freePort);
                connect(this.draggedPort, freePort);
                this.dynamicNodeWithFreePort = null;
            }
        } else if (graphPiece instanceof Port) {
            Port port = (Port) graphPiece;
            if (this.draggedPort.getKind() == Kind.DATA_OUT && port.getKind() == Kind.DATA_IN) {
                connect(this.draggedPort, port);
            } else if (port.getKind() == Kind.DATA_OUT && this.draggedPort.getKind() == Kind.DATA_IN) {
                connect(port, this.draggedPort);
            } else if (this.draggedPort.getKind() == Kind.CONTROL_OUT && port.getKind() == Kind.CONTROL_IN) {
                connect(this.draggedPort, port);
            } else if (this.draggedPort.getKind() == Kind.CONTROL_IN && port.getKind() == Kind.CONTROL_OUT) {
                connect(port, this.draggedPort);
            } else if (this.draggedPort.getKind() == Kind.EPR && port.getKind() == Kind.DATA_IN) {
                connect(this.draggedPort, port);
            } else if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.EPR) {
                connect(port, this.draggedPort);
            }
        }
        this.draggedPort = null;
    }
    if (this.dynamicNodeWithFreePort != null) {
        try {
            this.dynamicNodeWithFreePort.removeLastDynamicallyAddedInPort();
        } catch (GraphException e) {
            this.engine.getGUI().getErrorWindow().error(e);
        }
    }
    /*
         * Multiple selected
         */
    if (this.mousePointForSelection != null) {
        double width = Math.abs(this.mousePoint.getX() - this.mousePointForSelection.getX());
        double height = Math.abs(this.mousePoint.getY() - this.mousePointForSelection.getY());
        int x = (int) (this.mousePoint.getX() > this.mousePointForSelection.getX() ? this.mousePointForSelection.getX() : this.mousePoint.getX());
        int y = (int) (this.mousePoint.getY() > this.mousePointForSelection.getY() ? this.mousePointForSelection.getY() : this.mousePoint.getY());
        this.multipleSelectedNodes = NodeController.getGUI(this.graph).getNodesIn(new Rectangle(x, y, (int) width, (int) height));
        selectNodes(this.multipleSelectedNodes);
        // clear mousepoint
        this.mousePointForSelection = null;
    }
    if (this.multipleSelectedNodes != null) {
        this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
    }
    maybeShowPopup(event);
    updateSize();
    this.panel.repaint();
    event.consume();
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Rectangle(java.awt.Rectangle) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Point(java.awt.Point) Point(java.awt.Point)

Example 8 with GraphException

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

the class GraphCanvas method createNodePopupMenu.

private void createNodePopupMenu() {
    this.nodePopup = new JPopupMenu();
    if (editable) {
        JMenuItem deleteItem = new JMenuItem("Delete");
        deleteItem.addActionListener(new AbstractAction() {

            public void actionPerformed(ActionEvent event) {
                try {
                    removeSelectedNode();
                } catch (GraphException e) {
                    // Should not happen
                    logger.error(e.getMessage(), e);
                    GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
                } catch (RuntimeException e) {
                    logger.error(e.getMessage(), e);
                    GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
                } catch (Error e) {
                    logger.error(e.getMessage(), e);
                    GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
                }
            }
        });
        this.nodePopup.add(deleteItem);
    }
    rerunItem = new JMenuItem("ReRun");
    rerunItem.addActionListener(new AbstractAction() {

        public void actionPerformed(ActionEvent event) {
            try {
                rerunSelectedNode();
            } catch (RuntimeException e) {
                logger.error(e.getMessage(), e);
                GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
            } catch (Error e) {
                logger.error(e.getMessage(), e);
                GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
            }
        }
    });
    breakPointItem = new JMenuItem("Add break Point");
    breakPointItem.addActionListener(new AbstractAction() {

        public void actionPerformed(ActionEvent event) {
            try {
                toggleBreakPointToNode();
            } catch (RuntimeException e) {
                logger.error(e.getMessage(), e);
                GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
            } catch (Error e) {
                logger.error(e.getMessage(), e);
                GraphCanvas.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
            }
        }
    });
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JPopupMenu(javax.swing.JPopupMenu)

Example 9 with GraphException

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

the class EndBlockNode 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 10 with GraphException

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

the class BPELScript method getSpecialBlock.

/**
 * @param node
 * @param depth
 * @param block
 *            It's a set so that duplicated nodes won't be added.
 * @param startClass
 * @param endClass
 * @throws GraphException
 */
private void getSpecialBlock(Node node, int depth, Set<Node> block, Class startClass, Class endClass) throws GraphException {
    List<Node> nextNodes = GraphUtil.getNextNodes(node);
    for (Node nextNode : nextNodes) {
        if (nextNode instanceof OutputNode) {
            throw new GraphException("Nodes after " + startClass.getName() + " cannot be connected to the output without going through " + endClass.getName() + ".");
        } else if (endClass.isInstance(nextNode)) {
            block.add(nextNode);
            if (depth == 0) {
            // Stop the recursion here.
            } else {
                getSpecialBlock(nextNode, depth - 1, block, startClass, endClass);
            }
        } else if (startClass.isInstance(nextNode)) {
            // handle embedded forEach
            block.add(nextNode);
            getSpecialBlock(nextNode, depth + 1, block, startClass, endClass);
        } else {
            block.add(nextNode);
            getSpecialBlock(nextNode, depth, block, startClass, endClass);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) OutputNode(org.apache.airavata.workflow.model.graph.system.OutputNode) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) BlockNode(org.apache.airavata.workflow.model.graph.system.BlockNode) IfNode(org.apache.airavata.workflow.model.graph.system.IfNode) EndBlockNode(org.apache.airavata.workflow.model.graph.system.EndBlockNode) MemoNode(org.apache.airavata.workflow.model.graph.system.MemoNode) Node(org.apache.airavata.workflow.model.graph.Node) EndForEachNode(org.apache.airavata.workflow.model.graph.system.EndForEachNode) ForEachNode(org.apache.airavata.workflow.model.graph.system.ForEachNode) 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)

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