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