Search in sources :

Example 56 with DataPort

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

the class GraphUtil method validateConnection.

/**
 * @param edge
 * @throws GraphException
 */
public static void validateConnection(Edge edge) throws GraphException {
    Port fromPort = edge.getFromPort();
    Port toPort = edge.getToPort();
    if (edge instanceof ControlEdge) {
        if (!(fromPort instanceof ControlPort && toPort instanceof ControlPort)) {
            throw new GraphException(MessageConstants.UNEXPECTED_ERROR);
        }
    } else if (edge instanceof DataEdge) {
        if (fromPort instanceof EPRPort) {
            // TODO
            return;
        }
        if (!(fromPort instanceof DataPort || fromPort instanceof EPRPort) || !(toPort instanceof DataPort)) {
            throw new GraphException(MessageConstants.UNEXPECTED_ERROR);
        }
        DataPort fromDataPort = (DataPort) fromPort;
        DataPort toDataPort = (DataPort) toPort;
        DataType fromType = fromDataPort.getType();
        DataType toType = toDataPort.getType();
        if (toDataPort.getEdges().size() > 1) {
            throw new GraphException(MessageConstants.MORE_THAN_ONE_CONNECTIONS);
        }
        // ok
        if (fromPort.getNode() instanceof WSNode) {
            if ("registerStream".equals(((WSNode) fromPort.getNode()).getOperationName())) {
                return;
            }
        }
        if (!(fromType == null || fromType.equals(WSConstants.XSD_ANY_TYPE) || fromType.equals(new QName(WSConstants.XSD_NS_URI, "anyType")) || toType == null || toType.equals(WSConstants.XSD_ANY_TYPE) || toType.equals(new QName(WSConstants.XSD_NS_URI, "anyType")) || fromType.equals(toType)) && (fromType == null || fromType.equals(WSConstants.LEAD_ANY_TYPE) || fromType.equals(new QName(WSConstants.LEAD_NS_URI, "anyType")) || toType == null || toType.equals(WSConstants.LEAD_ANY_TYPE) || toType.equals(new QName(WSConstants.LEAD_NS_URI, "anyType")) || fromType.equals(toType))) {
            throw new GraphException("Cannot connect ports with different types:" + " \nfrom=\t" + fromType + " \nto=\t" + toType + "");
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) DataPort(org.apache.airavata.workflow.model.graph.DataPort) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) QName(javax.xml.namespace.QName) DataPort(org.apache.airavata.workflow.model.graph.DataPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) Port(org.apache.airavata.workflow.model.graph.Port) WSPort(org.apache.airavata.workflow.model.graph.ws.WSPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) DataType(org.apache.airavata.model.appcatalog.appinterface.DataType) ControlEdge(org.apache.airavata.workflow.model.graph.ControlEdge)

Example 57 with DataPort

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

the class WSGraph method topologicalSort.

/**
 * @return
 * @throws GraphException
 */
private LinkedList<Node> topologicalSort() throws GraphException {
    List<EdgeImpl> alledges = this.getEdges();
    HashSet<EdgeImpl> edgeSet = new HashSet<EdgeImpl>(alledges);
    List<Node> workQueue = new LinkedList<Node>(GraphUtil.getInputNodes(this));
    workQueue.addAll(GraphUtil.getStreamSourceNodes(this));
    LinkedList<Node> sortedOrder = new LinkedList<Node>();
    while (!workQueue.isEmpty()) {
        Node currentNode = workQueue.remove(0);
        sortedOrder.add(currentNode);
        List<DataPort> outputPorts = currentNode.getOutputPorts();
        for (DataPort dataPort : outputPorts) {
            List<DataEdge> curentEdges = dataPort.getEdges();
            for (DataEdge dataEdge : curentEdges) {
                edgeSet.remove(dataEdge);
                if (isAllEdgesRemoved(edgeSet, dataEdge.getToPort().getNode())) {
                    workQueue.add(dataEdge.getToPort().getNode());
                }
            }
        }
    }
    if (edgeSet.isEmpty()) {
        return sortedOrder;
    } else {
        throw new GraphException("Graph Topological sorting failed, Graph has at least one cycle");
    }
}
Also used : Node(org.apache.airavata.workflow.model.graph.Node) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) LinkedList(java.util.LinkedList) DataPort(org.apache.airavata.workflow.model.graph.DataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) HashSet(java.util.HashSet)

Example 58 with DataPort

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

the class InputNode method getParameterType.

/**
 * Returns the type of the parameter
 *
 * @return The type of the parameter (e.g. string, int)
 */
@Override
public DataType getParameterType() {
    List<DataEdge> edges = getEdges();
    DataType parameterType = super.getParameterType();
    if (parameterType == null && getEdges().size() > 0) {
        // This happens when the graph XML doesn't have parameterType.
        DataEdge edge = edges.get(0);
        DataPort toPort = edge.getToPort();
    // parameterType = toPort.getType();
    }
    return parameterType;
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) DataType(org.apache.airavata.model.appcatalog.appinterface.DataType)

Example 59 with DataPort

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

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

Aggregations

DataPort (org.apache.airavata.workflow.model.graph.DataPort)100 ComponentDataPort (org.apache.airavata.workflow.model.component.ComponentDataPort)39 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)26 Node (org.apache.airavata.workflow.model.graph.Node)26 DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)20 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)16 GraphException (org.apache.airavata.workflow.model.graph.GraphException)15 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)13 DataType (org.apache.airavata.model.application.io.DataType)12 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)12 Port (org.apache.airavata.workflow.model.graph.Port)11 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)10 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)9 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)8 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)8 LinkedList (java.util.LinkedList)7 ControlPort (org.apache.airavata.workflow.model.graph.ControlPort)7 EPRPort (org.apache.airavata.workflow.model.graph.EPRPort)7 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)6 ForEachNode (org.apache.airavata.workflow.model.graph.system.ForEachNode)6