Search in sources :

Example 1 with ControlPort

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

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

the class ExitComponent method createPorts.

protected void createPorts(NodeImpl node) {
    for (ComponentDataPort input : getInputPorts()) {
        DataPort port = input.createPort();
        node.addInputPort(port);
    }
    for (ComponentDataPort output : getOutputPorts()) {
        DataPort port = output.createPort();
        node.addOutputPort(port);
    }
    if (this.controlInPort != null) {
        ControlPort port = this.controlInPort.createPort();
        node.setControlInPort(port);
    }
    for (ComponentControlPort componentPort : this.controlOutPorts) {
        ControlPort port = componentPort.createPort();
        node.addControlOutPort(port);
    }
    if (this.eprPort != null) {
        EPRPort port = this.eprPort.createPort();
        node.setEPRPort(port);
    }
}
Also used : SystemComponentDataPort(org.apache.airavata.workflow.model.component.system.SystemComponentDataPort) DataPort(org.apache.airavata.workflow.model.graph.DataPort) ComponentDataPort(org.apache.airavata.workflow.model.component.ComponentDataPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) ComponentControlPort(org.apache.airavata.workflow.model.component.ComponentControlPort) ComponentControlPort(org.apache.airavata.workflow.model.component.ComponentControlPort) SystemComponentDataPort(org.apache.airavata.workflow.model.component.system.SystemComponentDataPort) ComponentDataPort(org.apache.airavata.workflow.model.component.ComponentDataPort)

Example 3 with ControlPort

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

the class WSGraphFactory method createPort.

public PortImpl createPort(XmlElement portElement) {
    String type = portElement.attributeValue(GraphSchema.NS, GraphSchema.PORT_TYPE_ATTRIBUTE);
    if (type == null) {
        // Old graphs don't have the namespace for the attribute.
        type = portElement.attributeValue(GraphSchema.PORT_TYPE_ATTRIBUTE);
    }
    PortImpl port;
    if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
        port = new WSPort(portElement);
    } else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
        port = new SystemDataPort(portElement);
    } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
        port = new ControlPort(portElement);
    } else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
        port = new EPRPort(portElement);
    } else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
        port = new InstanceDataPort(portElement);
    } else {
        // Default is WsPort because of backword compatibility
        port = new WSPort(portElement);
    }
    return port;
}
Also used : EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) InstanceDataPort(org.apache.airavata.workflow.model.graph.amazon.InstanceDataPort) SystemDataPort(org.apache.airavata.workflow.model.graph.system.SystemDataPort) PortImpl(org.apache.airavata.workflow.model.graph.impl.PortImpl)

Example 4 with ControlPort

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

the class WSGraphFactory method createPort.

/**
 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createPort(org.xmlpull.infoset.XmlElement)
 */
public PortImpl createPort(JsonObject portObject) {
    String type = portObject.getAsJsonPrimitive(GraphSchema.PORT_TYPE_ATTRIBUTE).getAsString();
    PortImpl port;
    if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
        port = new WSPort(portObject);
    } else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
        port = new SystemDataPort(portObject);
    } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
        port = new ControlPort(portObject);
    /*        } else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
            port = new EPRPort(portElement);
        } else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
            port = new InstanceDataPort(portElement);*/
    } else {
        // Default is WsPort because of backword compatibility
        port = new WSPort(portObject);
    }
    return port;
}
Also used : ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) SystemDataPort(org.apache.airavata.workflow.model.graph.system.SystemDataPort) PortImpl(org.apache.airavata.workflow.model.graph.impl.PortImpl)

Example 5 with ControlPort

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

Aggregations

ControlPort (org.apache.airavata.workflow.model.graph.ControlPort)10 DataPort (org.apache.airavata.workflow.model.graph.DataPort)7 EPRPort (org.apache.airavata.workflow.model.graph.EPRPort)4 SystemDataPort (org.apache.airavata.workflow.model.graph.system.SystemDataPort)3 Component (org.apache.airavata.workflow.model.component.Component)2 WSComponent (org.apache.airavata.workflow.model.component.ws.WSComponent)2 DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)2 GraphException (org.apache.airavata.workflow.model.graph.GraphException)2 Node (org.apache.airavata.workflow.model.graph.Node)2 EdgeImpl (org.apache.airavata.workflow.model.graph.impl.EdgeImpl)2 PortImpl (org.apache.airavata.workflow.model.graph.impl.PortImpl)2 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XPathFactory (javax.xml.xpath.XPathFactory)1 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)1 ComponentControlPort (org.apache.airavata.workflow.model.component.ComponentControlPort)1 ComponentDataPort (org.apache.airavata.workflow.model.component.ComponentDataPort)1