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 + "");
}
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations