Search in sources :

Example 16 with DataEdge

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

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

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

the class WSGraphFactory method createEdge.

/**
 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createEdge(org.xmlpull.infoset.XmlElement)
 */
public EdgeImpl createEdge(XmlElement edgeElement) {
    String type = edgeElement.attributeValue(GraphSchema.NS, GraphSchema.EDGE_TYPE_ATTRIBUTE);
    EdgeImpl edge;
    if (GraphSchema.EDGE_TYPE_DATA.equals(type)) {
        edge = new DataEdge(edgeElement);
    } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
        edge = new ControlEdge(edgeElement);
    } else {
        // Default is WsPort because of backword compatibility
        edge = new DataEdge(edgeElement);
    }
    return edge;
}
Also used : DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) ControlEdge(org.apache.airavata.workflow.model.graph.ControlEdge)

Example 19 with DataEdge

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

the class WSGraphFactory method createEdge.

public EdgeImpl createEdge(JsonObject edgeObject) {
    String type = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_TYPE_ATTRIBUTE).getAsString();
    EdgeImpl edge;
    if (GraphSchema.EDGE_TYPE_DATA.equals(type)) {
        edge = new DataEdge(edgeObject);
    } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
        edge = new ControlEdge(edgeObject);
    } else {
        // Default is WsPort because of backword compatibility
        edge = new DataEdge(edgeObject);
    }
    return edge;
}
Also used : DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) ControlEdge(org.apache.airavata.workflow.model.graph.ControlEdge)

Example 20 with DataEdge

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

the class WSGraphFactory method createEdge.

/**
 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createEdge(org.apache.airavata.workflow.model.graph.Port,
 *      org.apache.airavata.workflow.model.graph.Port)
 */
public EdgeImpl createEdge(Port fromPort, Port toPort) {
    Kind fromKind = fromPort.getKind();
    Kind toKind = toPort.getKind();
    if (!((fromKind == Kind.DATA_OUT && toKind == Kind.DATA_IN) || (fromKind == Kind.CONTROL_OUT && toKind == Kind.CONTROL_IN) || (fromKind == Kind.EPR && toKind == Kind.DATA_IN))) {
        throw new WorkflowRuntimeException();
    }
    EdgeImpl edge;
    if (toKind == Kind.DATA_IN) {
        edge = new DataEdge();
    } else if (toKind == Kind.CONTROL_IN) {
        edge = new ControlEdge();
    } else {
        // Should not happen.
        throw new WorkflowRuntimeException();
    }
    return edge;
}
Also used : DataEdge(org.apache.airavata.workflow.model.graph.DataEdge) Kind(org.apache.airavata.workflow.model.graph.Port.Kind) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) ControlEdge(org.apache.airavata.workflow.model.graph.ControlEdge)

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