Search in sources :

Example 1 with EdgeImpl

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

the class WorkflowInterpreter method getReadyNodesDynamically.

private ArrayList<Node> getReadyNodesDynamically() {
    ArrayList<Node> list = new ArrayList<Node>();
    ArrayList<Node> waiting = InterpreterUtil.getWaitingNodesDynamically(this.getGraph());
    // ArrayList<Node> finishedNodes = InterpreterUtil.getFinishedNodesDynamically(this.getGraph());
    // This is to support repeat the same application in the workflow.
    List<String> finishedNodeIds = InterpreterUtil.getFinishedNodesIds(this.getGraph());
    for (Node node : waiting) {
        Component component = node.getComponent();
        if (component instanceof WSComponent || component instanceof DynamicComponent || component instanceof SubWorkflowComponent || component instanceof ForEachComponent || component instanceof EndForEachComponent || component instanceof IfComponent || component instanceof InstanceComponent) {
            /*
				 * Check for control ports from other node
				 */
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && (finishedNodeIds.contains(edge.getFromPort().getNode().getID()) || // that makes sense and if anyone found a scenario it should be otherwise pls fix
                    ((ControlPort) edge.getFromPort()).isConditionMet());
                }
            }
            /*
				 * Check for input ports
				 */
            List<DataPort> inputPorts = node.getInputPorts();
            boolean inputsDone = true;
            for (DataPort dataPort : inputPorts) {
                inputsDone = inputsDone && finishedNodeIds.contains(dataPort.getFromNode().getID());
            }
            if (inputsDone && controlDone) {
                list.add(node);
            }
        } else if (component instanceof EndifComponent) {
            /*
				 * EndIfComponent can run if number of input equals to number of
				 * output that it expects
				 */
            int expectedOutput = node.getOutputPorts().size();
            int actualInput = 0;
            List<DataPort> inputPorts = node.getInputPorts();
            for (DataPort dataPort : inputPorts) {
                if (finishedNodeIds.contains(dataPort.getFromNode().getID()))
                    actualInput++;
            }
            if (expectedOutput == actualInput) {
                list.add(node);
            }
        } else if (component instanceof TerminateInstanceComponent) {
            /*
				 * All node connected to controlIn port must be done
				 */
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && finishedNodeIds.contains(edge.getFromPort().getFromNode().getID());
                }
            }
            /*
				 * Check for input ports
				 */
            List<DataPort> inputPorts = node.getInputPorts();
            boolean inputsDone = true;
            for (DataPort dataPort : inputPorts) {
                inputsDone = inputsDone && finishedNodeIds.contains(dataPort.getFromNode().getID());
            }
            if (inputsDone && controlDone) {
                list.add(node);
            }
        } else if (InputComponent.NAME.equals(component.getName()) || DifferedInputComponent.NAME.equals(component.getName()) || S3InputComponent.NAME.equals(component.getName()) || OutputComponent.NAME.equals(component.getName()) || MemoComponent.NAME.equals(component.getName()) || component instanceof EndDoWhileComponent) {
        // no op
        } else if (component instanceof DoWhileComponent) {
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && finishedNodeIds.contains(edge.getFromPort().getFromNode().getID());
                }
            }
            if (controlDone) {
                list.add(node);
            }
        } else {
            throw new WorkFlowInterpreterException("Component Not handled :" + component.getName());
        }
    }
    notifyViaInteractor(WorkflowExecutionMessage.HANDLE_DEPENDENT_NODES_DIFFERED_INPUTS, this.getGraph());
    return list;
}
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) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent) DataPort(org.apache.airavata.workflow.model.graph.DataPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) InstanceComponent(org.apache.airavata.workflow.model.component.amazon.InstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) Component(org.apache.airavata.workflow.model.component.Component) DynamicComponent(org.apache.airavata.workflow.model.component.dynamic.DynamicComponent) InstanceComponent(org.apache.airavata.workflow.model.component.amazon.InstanceComponent) TerminateInstanceComponent(org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent)

Example 2 with EdgeImpl

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

use of org.apache.airavata.workflow.model.graph.impl.EdgeImpl 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 4 with EdgeImpl

use of org.apache.airavata.workflow.model.graph.impl.EdgeImpl 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 5 with EdgeImpl

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

EdgeImpl (org.apache.airavata.workflow.model.graph.impl.EdgeImpl)6 DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)4 ControlEdge (org.apache.airavata.workflow.model.graph.ControlEdge)3 DataPort (org.apache.airavata.workflow.model.graph.DataPort)3 Node (org.apache.airavata.workflow.model.graph.Node)3 Component (org.apache.airavata.workflow.model.component.Component)2 WSComponent (org.apache.airavata.workflow.model.component.ws.WSComponent)2 ControlPort (org.apache.airavata.workflow.model.graph.ControlPort)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 InstanceComponent (org.apache.airavata.workflow.model.component.amazon.InstanceComponent)1 TerminateInstanceComponent (org.apache.airavata.workflow.model.component.amazon.TerminateInstanceComponent)1 DynamicComponent (org.apache.airavata.workflow.model.component.dynamic.DynamicComponent)1 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)1 GraphException (org.apache.airavata.workflow.model.graph.GraphException)1 Kind (org.apache.airavata.workflow.model.graph.Port.Kind)1 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)1 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)1 DoWhileNode (org.apache.airavata.workflow.model.graph.system.DoWhileNode)1