Search in sources :

Example 1 with DataEdge

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

the class GraphUtil method propagateTypes.

/**
 * @param graph
 * @throws GraphException
 */
public static void propagateTypes(Graph graph) throws GraphException {
    List<WSPort> wsPorts = getPorts(graph, WSPort.class);
    for (WSPort wsPort : wsPorts) {
        List<DataEdge> edges = wsPort.getEdges();
        for (DataEdge edge : edges) {
            DataPort fromPort = edge.getFromPort();
            DataPort toPort = edge.getToPort();
            if (fromPort == wsPort) {
                toPort.copyType(wsPort);
            } else if (toPort == wsPort) {
                fromPort.copyType(wsPort);
            } else {
                throw new WorkflowRuntimeException();
            }
        }
    }
}
Also used : WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) DataPort(org.apache.airavata.workflow.model.graph.DataPort) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)

Example 2 with DataEdge

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

the class EndDoWhileNode method edgeWasAdded.

/**
 * @throws GraphException
 * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.Edge)
 */
@Override
protected void edgeWasAdded(Edge edge) throws GraphException {
    // XXX cannot detect if the type is array or not from WSDL at this
    // point. so no check here.
    // super.edgeWasAdded(edge);
    Port fromPort = edge.getFromPort();
    Port toPort = edge.getToPort();
    if (edge instanceof DataEdge) {
        if (fromPort instanceof EPRPort) {
            // TODO
            return;
        }
        DataPort fromDataPort = (DataPort) fromPort;
        DataPort toDataPort = (DataPort) toPort;
        DataType fromType = fromDataPort.getType();
        DataType toType = toDataPort.getType();
        if (fromDataPort.getNode() == this) {
            if (!(toType == null || toType.equals(WSConstants.XSD_ANY_TYPE))) {
                fromDataPort.copyType(toDataPort);
            }
        } else if (toDataPort.getNode() == this) {
            if (!(fromType == null || fromType.equals(WSConstants.XSD_ANY_TYPE))) {
                toDataPort.copyType(fromDataPort);
            }
        } else {
            throw new WorkflowRuntimeException();
        }
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) ComponentDataPort(org.apache.airavata.workflow.model.component.ComponentDataPort) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) DataPort(org.apache.airavata.workflow.model.graph.DataPort) ComponentDataPort(org.apache.airavata.workflow.model.component.ComponentDataPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) Port(org.apache.airavata.workflow.model.graph.Port) DataType(org.apache.airavata.model.application.io.DataType) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)

Example 3 with DataEdge

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

the class GraphImpl method removeNode.

/**
 * @see org.apache.airavata.workflow.model.graph.Graph#removeNode(org.apache.airavata.workflow.model.graph.Node)
 */
public void removeNode(Node node) throws GraphException {
    if (node == null) {
        throw new IllegalArgumentException("null");
    }
    if (!this.nodes.contains(node)) {
        throw new GraphException("The graph doesn't contain the node that is being removed.");
    }
    NodeImpl nodeImpl = (NodeImpl) node;
    // Remove edges connected to input ports.
    for (Iterator<DataPort> portItr = nodeImpl.getInputPorts().iterator(); portItr.hasNext(); ) {
        DataPort port = portItr.next();
        for (Iterator<DataEdge> edgeItr = port.getEdges().iterator(); edgeItr.hasNext(); ) {
            DataEdge edge = edgeItr.next();
            // Remove the edge from from-port.
            DataPort fromPort = edge.getFromPort();
            fromPort.removeEdge(edge);
            // remove the edge from this port. This is necessary so that
            // type update works properly.
            edgeItr.remove();
            // Remove the edge from the graph.
            this.edges.remove(edge);
            fromPort.getNode().edgeWasRemoved(edge);
        }
        // Remove the port from the node.
        portItr.remove();
        // Remove the port from the graph.
        this.ports.remove(port);
    }
    // Remove edges connected to output ports.
    for (Iterator<DataPort> portItr = nodeImpl.getOutputPorts().iterator(); portItr.hasNext(); ) {
        DataPort port = portItr.next();
        for (Iterator<DataEdge> edgeItr = port.getEdges().iterator(); edgeItr.hasNext(); ) {
            DataEdge edge = edgeItr.next();
            DataPort toPort = edge.getToPort();
            toPort.removeEdge(edge);
            edgeItr.remove();
            this.edges.remove(edge);
            toPort.getNode().edgeWasRemoved(edge);
        }
        portItr.remove();
        this.ports.remove(port);
    }
    for (Iterator<ControlPort> portItr = nodeImpl.getControlOutPorts().iterator(); portItr.hasNext(); ) {
        PortImpl port = portItr.next();
        for (Iterator<? extends EdgeImpl> edgeItr = port.getEdges().iterator(); edgeItr.hasNext(); ) {
            EdgeImpl edge = edgeItr.next();
            PortImpl toPort = edge.getToPort();
            toPort.removeEdge(edge);
            edgeItr.remove();
            this.edges.remove(edge);
            toPort.getNode().edgeWasRemoved(edge);
        }
        portItr.remove();
        this.ports.remove(port);
    }
    PortImpl controlInPort = nodeImpl.getControlInPort();
    if (controlInPort != null) {
        for (Iterator<? extends EdgeImpl> edgeItr = controlInPort.getEdges().iterator(); edgeItr.hasNext(); ) {
            EdgeImpl edge = edgeItr.next();
            PortImpl fromPort = edge.getFromPort();
            fromPort.removeEdge(edge);
            edgeItr.remove();
            this.edges.remove(edge);
            fromPort.getNode().edgeWasRemoved(edge);
        }
        this.ports.remove(controlInPort);
    }
    PortImpl eprPort = nodeImpl.getEPRPort();
    if (eprPort != null) {
        for (Iterator<? extends EdgeImpl> edgeItr = eprPort.getEdges().iterator(); edgeItr.hasNext(); ) {
            EdgeImpl edge = edgeItr.next();
            PortImpl toPort = edge.getToPort();
            toPort.removeEdge(edge);
            edgeItr.remove();
            this.edges.remove(edge);
            toPort.getNode().edgeWasRemoved(edge);
        }
        this.ports.remove(eprPort);
    }
    this.nodes.remove(node);
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) SystemDataPort(org.apache.airavata.workflow.model.graph.system.SystemDataPort) DataPort(org.apache.airavata.workflow.model.graph.DataPort) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort)

Example 4 with DataEdge

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

the class ConstantNode 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 this method can be removed.
    Port toPort = edge.getToPort();
    if (edge instanceof DataEdge) {
        DataPort toDataPort = (DataPort) toPort;
        DataType toType = toDataPort.getType();
        List edges = getEdges();
        if (edges.size() == 1) {
            // The first edge.
            this.type = toType;
        } else if (edges.size() > 1) {
            // Not the first edge.
            if (!toType.equals(WSConstants.XSD_ANY_TYPE) && !this.type.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) GraphException(org.apache.airavata.workflow.model.graph.GraphException) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) DataType(org.apache.airavata.model.application.io.DataType) List(java.util.List) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)

Example 5 with DataEdge

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

the class InputNode method edgeWasRemoved.

/**
 * Called whan an Edge was removed from the parameter port. Change the name of the node.
 *
 * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasRemoved(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
 */
@Override
protected void edgeWasRemoved(Edge removedEdge) {
    super.edgeWasRemoved(removedEdge);
    // TODO organize this.
    List<DataEdge> edges = getEdges();
    if (edges.size() == 0) {
        setParameterType(null);
        if (!isConfigured()) {
            // Reset
            setName(getComponent().getName());
            setDescription("");
            setDefaultValue(null);
            setMetadata(null);
        }
    } else {
        Edge edge = edges.get(0);
        Port toPort = edge.getToPort();
        WSPort toWsPort = (WSPort) toPort;
        DataType toType = toWsPort.getType();
        setParameterType(toType);
        if (!isConfigured()) {
            // Copy
            copyDefaultConfiguration(toWsPort);
        }
    }
}
Also used : WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) 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.appcatalog.appinterface.DataType) Edge(org.apache.airavata.workflow.model.graph.Edge) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge)

Aggregations

DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)29 DataPort (org.apache.airavata.workflow.model.graph.DataPort)23 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)12 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)12 Port (org.apache.airavata.workflow.model.graph.Port)11 DataType (org.apache.airavata.model.application.io.DataType)10 GraphException (org.apache.airavata.workflow.model.graph.GraphException)9 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)8 EPRPort (org.apache.airavata.workflow.model.graph.EPRPort)5 WSComponentPort (org.apache.airavata.workflow.model.component.ws.WSComponentPort)4 ControlEdge (org.apache.airavata.workflow.model.graph.ControlEdge)4 Edge (org.apache.airavata.workflow.model.graph.Edge)4 EdgeImpl (org.apache.airavata.workflow.model.graph.impl.EdgeImpl)4 ComponentDataPort (org.apache.airavata.workflow.model.component.ComponentDataPort)3 ControlPort (org.apache.airavata.workflow.model.graph.ControlPort)2 Node (org.apache.airavata.workflow.model.graph.Node)2 SystemDataPort (org.apache.airavata.workflow.model.graph.system.SystemDataPort)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1