Search in sources :

Example 1 with Edge

use of org.apache.airavata.workflow.core.dag.edge.Edge in project airavata by apache.

the class JsonWorkflowParser method buildWorkflowGraph.

private void buildWorkflowGraph() throws Exception {
    // TODO construct runtime model
    Queue<WorkflowNode> queue = new LinkedList<>();
    queue.addAll(inputs);
    Map<String, List<Link>> linkMap = getEdgesMap(links);
    Map<String, InPort> nodeInportMap = getNodeInPortsMap(getApplicationNodes());
    nodeInportMap.putAll(getNodeInPortMap(getOutputNodes()));
    Set<String> processedNodes = new HashSet<>();
    while (!queue.isEmpty()) {
        WorkflowNode node = queue.poll();
        if (processedNodes.contains(node.getId())) {
            continue;
        }
        if (node instanceof InputNode) {
            InputNode input = ((InputNode) node);
            OutPort outPort = ((OutPort) node);
            Map<String, Edge> edgeMap = addEdges(outPort, linkMap.get(outPort.getNodeId() + "," + outPort.getId()));
            for (Map.Entry<String, Edge> entry : edgeMap.entrySet()) {
                InPort inPort = nodeInportMap.get(entry.getKey());
                if (inPort != null) {
                    // inPort.addEdge(entry.getValue());
                    entry.getValue().setToPort(inPort);
                    queue.add(inPort.getNode());
                }
            }
        } else if (node instanceof ApplicationNode) {
            ApplicationNode appNode = ((ApplicationNode) node);
            for (OutPort outPort : appNode.getOutputPorts()) {
                outPort.setNode(appNode);
                Map<String, Edge> edgeMap = addEdges(outPort, linkMap.get(outPort.getNodeId() + "," + outPort.getId()));
                for (Map.Entry<String, Edge> entry : edgeMap.entrySet()) {
                    InPort inPort = nodeInportMap.get(entry.getKey());
                    if (inPort != null) {
                        // inPort.addEdge(entry.getValue());
                        entry.getValue().setToPort(inPort);
                        queue.add(inPort.getNode());
                    }
                }
            }
        } else if (node instanceof OutputNode) {
            OutputNode outputNode = ((OutputNode) node);
            InPort inPort = ((InPort) node);
            outputNode.setInputObject(inPort.getInputObject());
        }
        // marke node as precessed node, we don't need to process it again.
        processedNodes.add(node.getId());
    }
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) OutputNode(org.apache.airavata.workflow.core.dag.nodes.OutputNode) InPort(org.apache.airavata.workflow.core.dag.port.InPort) ApplicationNode(org.apache.airavata.workflow.core.dag.nodes.ApplicationNode) WorkflowNode(org.apache.airavata.workflow.core.dag.nodes.WorkflowNode) LinkedList(java.util.LinkedList) OutPort(org.apache.airavata.workflow.core.dag.port.OutPort) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) DirectedEdge(org.apache.airavata.workflow.core.dag.edge.DirectedEdge) Edge(org.apache.airavata.workflow.core.dag.edge.Edge) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with Edge

use of org.apache.airavata.workflow.core.dag.edge.Edge in project airavata by apache.

the class WorkflowInterpreter method processWorkflowInputNodes.

private void processWorkflowInputNodes(List<InputNode> inputNodes) {
    Set<WorkflowNode> tempNodeSet = new HashSet<>();
    for (InputNode inputNode : inputNodes) {
        if (inputNode.isReady()) {
            log.debug("Workflow node : " + inputNode.getId() + " is ready to execute");
            for (Edge edge : inputNode.getOutPort().getEdges()) {
                edge.getToPort().getInputObject().setValue(inputNode.getInputObject().getValue());
                if (edge.getToPort().getNode().isReady()) {
                    addToReadyQueue(edge.getToPort().getNode());
                    log.debug("Added workflow node : " + edge.getToPort().getNode().getId() + " to the readyQueue");
                } else {
                    addToWaitingQueue(edge.getToPort().getNode());
                    log.debug("Added workflow node " + edge.getToPort().getNode().getId() + " to the waitingQueue");
                }
            }
        }
    }
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) WorkflowNode(org.apache.airavata.workflow.core.dag.nodes.WorkflowNode) Edge(org.apache.airavata.workflow.core.dag.edge.Edge) HashSet(java.util.HashSet)

Example 3 with Edge

use of org.apache.airavata.workflow.core.dag.edge.Edge in project airavata by apache.

the class JsonWorkflowParser method addEdges.

/**
 * @param outPort -
 * @param links  -
 * @return key: nodeId,inportId  value : link
 */
private Map<String, Edge> addEdges(OutPort outPort, List<Link> links) {
    Map<String, Edge> inPortMap = new HashMap<>();
    if (links != null) {
        for (Link link : links) {
            EdgeModel edgeModel = new EdgeModel(link.getId());
            Edge edge = new DirectedEdge(edgeModel);
            // edge.setFromPort(outPort);
            outPort.addEdge(edge);
            inPortMap.put(link.getTo().getNodeId() + "," + link.getTo().getPortId(), edge);
        }
    }
    return inPortMap;
}
Also used : DirectedEdge(org.apache.airavata.workflow.core.dag.edge.DirectedEdge) HashMap(java.util.HashMap) DirectedEdge(org.apache.airavata.workflow.core.dag.edge.DirectedEdge) Edge(org.apache.airavata.workflow.core.dag.edge.Edge) EdgeModel(org.apache.airavata.model.EdgeModel)

Aggregations

Edge (org.apache.airavata.workflow.core.dag.edge.Edge)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 DirectedEdge (org.apache.airavata.workflow.core.dag.edge.DirectedEdge)2 InputNode (org.apache.airavata.workflow.core.dag.nodes.InputNode)2 WorkflowNode (org.apache.airavata.workflow.core.dag.nodes.WorkflowNode)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 EdgeModel (org.apache.airavata.model.EdgeModel)1 ApplicationNode (org.apache.airavata.workflow.core.dag.nodes.ApplicationNode)1 OutputNode (org.apache.airavata.workflow.core.dag.nodes.OutputNode)1 InPort (org.apache.airavata.workflow.core.dag.port.InPort)1 OutPort (org.apache.airavata.workflow.core.dag.port.OutPort)1