Search in sources :

Example 1 with DynamicNode

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

the class WorkflowInterpreter method handleDynamicComponent.

private void handleDynamicComponent(Node node) throws WorkflowException {
    DynamicComponent dynamicComponent = (DynamicComponent) node.getComponent();
    String className = dynamicComponent.getClassName();
    String operationName = dynamicComponent.getOperationName();
    URL implJarLocation = dynamicComponent.getImplJarLocation();
    DynamicNode dynamicNode = (DynamicNode) node;
    LinkedList<Object> inputs = new LinkedList<Object>();
    List<DataPort> inputPorts = dynamicNode.getInputPorts();
    for (DataPort dataPort : inputPorts) {
        Object inputVal = InterpreterUtil.findInputFromPort(dataPort, this.invokerMap);
        /*
			 * Set type after get input value, and override inputValue if output
			 * type is array
			 */
        Node fromNode = dataPort.getFromNode();
        DataType type = null;
        if (fromNode instanceof InputNode) {
            type = DataType.STRING;
        } else if (fromNode instanceof ConstantNode) {
            type = ((ConstantNode) fromNode).getType();
        } else if ((dataPort.getFromPort() instanceof WSPort) && BasicTypeMapping.isArrayType(((WSPort) dataPort.getFromPort()).getComponentPort().getElement())) {
            Invoker fromInvoker = this.invokerMap.get(fromNode);
            // inputVal = BasicTypeMapping.getOutputArray(XmlConstants.BUILDER.parseFragmentFromString(fromInvoker.getOutputs().toString()), dataPort
            // .getFromPort().getName(), BasicTypeMapping.getSimpleTypeIndex(((DataPort) dataPort.getFromPort()).getType()));
            type = ((DataPort) dataPort.getFromPort()).getType();
        } else {
            type = ((DataPort) dataPort.getFromPort()).getType();
        }
        if (null == inputVal) {
            throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + node.getID());
        }
    // inputs.add(BasicTypeMapping.getObjectOfType(type, inputVal));
    }
    DynamicInvoker dynamicInvoker = new DynamicInvoker(className, implJarLocation, operationName, inputs.toArray());
    this.invokerMap.put(node, dynamicInvoker);
    dynamicInvoker.setup();
    dynamicInvoker.invoke();
    node.setState(NodeExecutionState.FINISHED);
}
Also used : DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) 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) URL(java.net.URL) DataPort(org.apache.airavata.workflow.model.graph.DataPort) WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) DynamicInvoker(org.apache.airavata.workflow.engine.invoker.DynamicInvoker) Invoker(org.apache.airavata.workflow.engine.invoker.Invoker) DynamicInvoker(org.apache.airavata.workflow.engine.invoker.DynamicInvoker) ExpCatChildDataType(org.apache.airavata.registry.cpi.ExpCatChildDataType) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)

Example 2 with DynamicNode

use of org.apache.airavata.workflow.model.graph.dynamic.DynamicNode 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 3 with DynamicNode

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

the class GraphCanvas method mouseDragged.

private void mouseDragged(MouseEvent event) {
    Point point = event.getPoint();
    if (editable) {
        /*
			 * Move nodes
			 */
        if (this.multipleSelectedNodes != null) {
            if (point.x < 0) {
                point.x = 0;
            }
            if (point.y < 0) {
                point.y = 0;
            }
            int diffX = point.x - this.mousePoint.x;
            int diffY = point.y - this.mousePoint.y;
            for (Node node : this.multipleSelectedNodes) {
                Point newPoint = new Point();
                Point currentPoint = node.getPosition();
                newPoint.x = currentPoint.x + diffX;
                if (newPoint.x < 0) {
                    newPoint.x = 0;
                }
                newPoint.y = currentPoint.y + diffY;
                if (newPoint.y < 0) {
                    newPoint.y = 0;
                }
                node.setPosition(newPoint);
            }
            this.panel.repaint();
            event.consume();
        }
        if (this.draggedNode != null) {
            if (point.x < 0) {
                point.x = 0;
            }
            if (point.y < 0) {
                point.y = 0;
            }
            int diffX = point.x - this.mousePoint.x;
            int diffY = point.y - this.mousePoint.y;
            Point newPoint = new Point();
            Point currentPoint = this.draggedNode.getPosition();
            newPoint.x = currentPoint.x + diffX;
            if (newPoint.x < 0) {
                newPoint.x = 0;
            }
            newPoint.y = currentPoint.y + diffY;
            if (newPoint.y < 0) {
                newPoint.y = 0;
            }
            this.draggedNode.setPosition(newPoint);
            this.panel.repaint();
            event.consume();
        }
        if (this.draggedPort != null) {
            GraphPiece piece = NodeController.getGUI(this.graph).getGraphPieceAt(point);
            if (piece instanceof Port) {
                Port port = (Port) piece;
                // pointer.
                if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.DATA_OUT) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectOutputPort(port);
                } else if (this.draggedPort.getKind() == Kind.DATA_OUT && port.getKind() == Kind.DATA_IN) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectInputPort(port);
                } else if (this.draggedPort.getKind() == Kind.DATA_IN && port.getKind() == Kind.EPR) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectOutputPort(port);
                } else if (this.draggedPort.getKind() == Kind.EPR && port.getKind() == Kind.DATA_IN) {
                    this.panel.setCursor(SwingUtil.CROSSHAIR_CURSOR);
                    selectInputPort(port);
                } else {
                    this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
                }
            } else if (piece instanceof PortAddable) {
                PortAddable dynamicNode = (PortAddable) piece;
                dynamicNode.getFreeInPort();
                this.dynamicNodeWithFreePort = dynamicNode;
            } else {
                this.panel.setCursor(SwingUtil.DEFAULT_CURSOR);
            }
            this.panel.repaint();
            event.consume();
        }
        this.mousePoint = point;
        // draw rectangle
        if (this.mousePointForSelection != null) {
            this.panel.repaint();
        }
    }
}
Also used : PortAddable(org.apache.airavata.workflow.model.graph.dynamic.PortAddable) GraphPiece(org.apache.airavata.workflow.model.graph.GraphPiece) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) StreamSourceNode(org.apache.airavata.workflow.model.graph.system.StreamSourceNode) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) Point(java.awt.Point) Point(java.awt.Point)

Example 4 with DynamicNode

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

the class DynamicComponent method createNode.

public Node createNode(Graph graph) {
    DynamicNode node = new DynamicNode(graph);
    // Copy some infomation from the component
    node.setName(getName());
    node.setComponent(new DynamicComponent());
    // Creates a unique ID for the node. This has to be after setName().
    node.createID();
    // Creat ports
    createPorts(node);
    return node;
}
Also used : DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)

Aggregations

DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)4 DataPort (org.apache.airavata.workflow.model.graph.DataPort)3 Point (java.awt.Point)2 GraphPiece (org.apache.airavata.workflow.model.graph.GraphPiece)2 Node (org.apache.airavata.workflow.model.graph.Node)2 Port (org.apache.airavata.workflow.model.graph.Port)2 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)2 StreamSourceNode (org.apache.airavata.workflow.model.graph.system.StreamSourceNode)2 Rectangle (java.awt.Rectangle)1 URL (java.net.URL)1 ExpCatChildDataType (org.apache.airavata.registry.cpi.ExpCatChildDataType)1 DynamicInvoker (org.apache.airavata.workflow.engine.invoker.DynamicInvoker)1 Invoker (org.apache.airavata.workflow.engine.invoker.Invoker)1 DynamicComponent (org.apache.airavata.workflow.model.component.dynamic.DynamicComponent)1 GraphException (org.apache.airavata.workflow.model.graph.GraphException)1 PortAddable (org.apache.airavata.workflow.model.graph.dynamic.PortAddable)1 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)1 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)1 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)1