Search in sources :

Example 6 with ControlPort

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

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

the class Component 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 : DataPort(org.apache.airavata.workflow.model.graph.DataPort) EPRPort(org.apache.airavata.workflow.model.graph.EPRPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort)

Example 8 with ControlPort

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

the class ComponentControlPort method createPort.

/**
 * @see org.apache.airavata.workflow.model.component.ComponentPort#createPort()
 */
@Override
public ControlPort createPort() {
    ControlPort port = new ControlPort();
    port.setName(this.name);
    port.setComponentPort(this);
    return port;
}
Also used : ControlPort(org.apache.airavata.workflow.model.graph.ControlPort)

Example 9 with ControlPort

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

the class WorkflowInterpreter method handleIf.

private void handleIf(Node node) throws WorkflowException {
    IfNode ifNode = (IfNode) node;
    /*
		 * Get all input to check condition
		 */
    String booleanExpression = ifNode.getXPath();
    if (booleanExpression == null) {
        throw new WorkFlowInterpreterException("XPath for if cannot be null");
    }
    List<DataPort> inputPorts = node.getInputPorts();
    int i = 0;
    for (DataPort port : inputPorts) {
        Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);
        if (null == inputVal) {
            throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + node.getID());
        }
        booleanExpression = booleanExpression.replaceAll("\\$" + i, "'" + inputVal + "'");
    }
    // Now the XPath expression
    try {
        XPathFactory xpathFact = XPathFactory.newInstance();
        XPath xpath = xpathFact.newXPath();
        Boolean result = (Boolean) xpath.evaluate(booleanExpression, booleanExpression, XPathConstants.BOOLEAN);
        /*
			 * Set control port to make execution flow continue according to
			 * condition
			 */
        for (ControlPort controlPort : node.getControlOutPorts()) {
            if (controlPort.getName().equals(IfComponent.TRUE_PORT_NAME)) {
                controlPort.setConditionMet(result.booleanValue());
            } else if (controlPort.getName().equals(IfComponent.FALSE_PORT_NAME)) {
                controlPort.setConditionMet(!result.booleanValue());
            }
        }
        node.setState(NodeExecutionState.FINISHED);
    } catch (XPathExpressionException e) {
        throw new WorkFlowInterpreterException("Cannot evaluate XPath in If Condition: " + booleanExpression);
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 10 with ControlPort

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

the class DoWhileHandler method handleDowhile.

/**
 * To get only web service components attached to dowhile
 *
 * @param waitingNode
 * @return list
 */
private ArrayList<Node> handleDowhile(ArrayList<Node> waitingNode, ArrayList<Node> finishedNodes) {
    ArrayList<Node> list = new ArrayList<Node>();
    for (Node node : waitingNode) {
        Component component = node.getComponent();
        if (component instanceof WSComponent) {
            ControlPort control = node.getControlInPort();
            boolean controlDone = true;
            if (control != null) {
                for (EdgeImpl edge : control.getEdges()) {
                    controlDone = controlDone && (finishedNodes.contains(edge.getFromPort().getNode()) || ((ControlPort) edge.getFromPort()).isConditionMet());
                }
            }
            /*
				 * Check for input ports
				 */
            List<DataPort> inputPorts = node.getInputPorts();
            boolean inputsDone = true;
            for (DataPort dataPort : inputPorts) {
                inputsDone = inputsDone && finishedNodes.contains(dataPort.getFromNode());
            }
            if (inputsDone && controlDone) {
                list.add(node);
            }
        }
    }
    return list;
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) EndDoWhileNode(org.apache.airavata.workflow.model.graph.system.EndDoWhileNode) Node(org.apache.airavata.workflow.model.graph.Node) DoWhileNode(org.apache.airavata.workflow.model.graph.system.DoWhileNode) ArrayList(java.util.ArrayList) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) EdgeImpl(org.apache.airavata.workflow.model.graph.impl.EdgeImpl) WSComponent(org.apache.airavata.workflow.model.component.ws.WSComponent) Component(org.apache.airavata.workflow.model.component.Component)

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