use of org.apache.airavata.workflow.model.graph.Node 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;
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowHarvester method removeUnnecessaryNodes.
/**
* @param pair
* @param clone
*/
private void removeUnnecessaryNodes(Node node, Port candidatePort, Workflow workflow) {
if (candidatePort.getFromPort().getEdges().size() == 1) {
Node fromNode = candidatePort.getFromNode();
try {
List<DataPort> inputPorts = fromNode.getInputPorts();
for (DataPort dataPort : inputPorts) {
removeUnnecessaryNodes(fromNode, dataPort, workflow);
}
workflow.removeNode(fromNode);
} catch (GraphException e) {
throw new WorkflowRuntimeException(e);
}
}
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowHarvester method harvest.
public Workflow[] harvest(Workflow workflow, QName dataType) {
LinkedList<Workflow> harvest = new LinkedList<Workflow>();
LinkedList<Pair<String, String>> candidates = getCandidates(workflow, dataType);
for (Pair<String, String> pair : candidates) {
Workflow clone = workflow.clone();
NodeImpl node = clone.getGraph().getNode(pair.getLeft());
if (null == node) {
throw new WorkflowRuntimeException("Specified node not found:" + pair.getLeft());
}
Port candidatePort = null;
List<DataPort> inPorts = node.getInputPorts();
for (DataPort dataPort : inPorts) {
if (pair.getRight().equals(dataPort.getID())) {
candidatePort = dataPort;
break;
}
}
if (null == candidatePort) {
throw new WorkflowRuntimeException("Specifies Port was not found:" + pair.getRight());
}
if (!(candidatePort.getFromNode() instanceof InputNode)) {
removeUnnecessaryNodes(node, candidatePort, clone);
Node input = clone.addNode(new InputComponent());
input.setPosition(new Point(Math.max(0, node.getPosition().x - 150), node.getPosition().y));
// original
if (clone.getGraph().getNodes().size() < workflow.getGraph().getNodes().size() && // its not the same as one already harvested
!isWorkflowAlreadyHarvested(harvest, clone)) {
try {
clone.getGraph().addEdge(input.getOutputPort(0), candidatePort);
cleanLeftOverInputNodes(clone);
} catch (GraphException e) {
throw new RuntimeException(e);
}
harvest.add(clone);
}
}
}
return harvest.toArray(new Workflow[0]);
}
use of org.apache.airavata.workflow.model.graph.Node in project airavata by apache.
the class WorkflowHarvester method cleanLeftOverInputNodes.
/**
* @param clone
*/
private void cleanLeftOverInputNodes(Workflow clone) {
List<NodeImpl> nodes = clone.getGraph().getNodes();
LinkedList<Node> removeList = new LinkedList<Node>();
for (Node nodeImpl : nodes) {
if (nodeImpl instanceof InputNode) {
if (nodeImpl.getOutputPort(0).getToNodes().size() == 0) {
removeList.add(nodeImpl);
}
}
}
for (Node node : removeList) {
try {
clone.removeNode(node);
} catch (GraphException e) {
throw new WorkflowRuntimeException(e);
}
}
}
Aggregations