use of org.apache.airavata.workflow.model.graph.impl.NodeImpl in project airavata by apache.
the class WorkflowInterpreter method finish.
private void finish() throws WorkflowException, RegistryException {
ArrayList<Node> outoutNodes = new ArrayList<Node>();
List<NodeImpl> nodes = this.getGraph().getNodes();
for (Node node : nodes) {
if (node instanceof OutputNode) {
if (node.getInputPort(0).getFromNode().getState() == NodeExecutionState.FINISHED) {
outoutNodes.add(node);
} else {
// workflowFinished
return;
}
}
}
LinkedList<Object> outputValues = new LinkedList<Object>();
LinkedList<String> outputKeywords = new LinkedList<String>();
for (Node outputNode : outoutNodes) {
OutputNode node = (OutputNode) outputNode;
List<DataPort> inputPorts = node.getInputPorts();
for (DataPort dataPort : inputPorts) {
Object val = InterpreterUtil.findInputFromPort(dataPort, this.invokerMap);
;
if (null == val) {
throw new WorkFlowInterpreterException("Unable to find output for the node:" + node.getID());
}
WorkflowNodeDetails workflowNodeDetails = nodeInstanceList.get(node);
OutputDataObjectType elem = new OutputDataObjectType();
elem.setName(node.getName());
elem.setValue(val.toString());
workflowNodeDetails.addToNodeOutputs(elem);
try {
getExperimentCatalog().update(ExperimentCatalogModelType.WORKFLOW_NODE_DETAIL, workflowNodeDetails, workflowNodeDetails.getNodeInstanceId());
} catch (RegistryException e) {
log.error(e.getMessage(), e);
}
updateWorkflowNodeStatus(workflowNodeDetails, WorkflowNodeState.COMPLETED);
}
}
}
use of org.apache.airavata.workflow.model.graph.impl.NodeImpl in project airavata by apache.
the class WorkflowInterpreter method getNodesWithState.
private ArrayList<Node> getNodesWithState(NodeExecutionState state) {
ArrayList<Node> list = new ArrayList<Node>();
List<NodeImpl> nodes = getGraph().getNodes();
for (Node node : nodes) {
if (state == node.getState()) {
list.add(node);
}
}
return list;
}
use of org.apache.airavata.workflow.model.graph.impl.NodeImpl 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.impl.NodeImpl 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