use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class WorkflowInterpreter method handleForEach.
private void handleForEach(Node node) throws WorkflowException {
final ForEachNode forEachNode = (ForEachNode) node;
EndForEachNode endForEachNode = null;
Collection<Node> repeatNodes = node.getOutputPort(0).getToNodes();
// we will support only one for now
if (repeatNodes.size() != 1) {
throw new WorkFlowInterpreterException("Only one node allowed inside foreach");
}
Iterator<Node> iterator = repeatNodes.iterator();
if (iterator.hasNext()) {
Node middleNode = iterator.next();
// output
if ((!(middleNode instanceof WSNode)) && (!(middleNode instanceof SubWorkflowNode))) {
throw new WorkFlowInterpreterException("Encountered Node inside foreach that is not a WSNode" + middleNode);
} else if (middleNode instanceof SubWorkflowNode) {
/* Get the EndforEach Node of the Subworkflow */
Iterator<Node> subWorkflowOut = middleNode.getOutputPort(0).getToNodes().iterator();
while (subWorkflowOut.hasNext()) {
Node node2 = subWorkflowOut.next();
if (node2 instanceof EndForEachNode) {
endForEachNode = (EndForEachNode) node2;
}
}
final LinkedList<String> listOfValues = new LinkedList<String>();
InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
Workflow workflow1 = ((SubWorkflowNode) middleNode).getWorkflow();
List<NodeImpl> nodes = workflow1.getGraph().getNodes();
List<Node> wsNodes = new ArrayList<Node>();
/* Take the List of WSNodes in the subworkflow */
for (NodeImpl subWorkflowNode : nodes) {
if (subWorkflowNode instanceof WSNode) {
wsNodes.add(subWorkflowNode);
}
}
for (int i = 0; i < wsNodes.size(); i++) {
final WSNode node1 = (WSNode) wsNodes.get(i);
SystemComponentInvoker systemInvoker = null;
List<DataPort> outputPorts1 = node1.getOutputPorts();
List<Node> endForEachNodes = new ArrayList<Node>();
for (DataPort port : outputPorts1) {
Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
while (endForEachNodeItr1.hasNext()) {
Node node2 = endForEachNodeItr1.next();
if (node2 instanceof EndForEachNode) {
endForEachNodes.add(node2);
} else if (node2 instanceof OutputNode) {
// intentionally left noop
} else {
throw new WorkFlowInterpreterException("Found More than one node inside foreach");
}
}
}
final List<Node> finalEndForEachNodes = endForEachNodes;
Iterator<Node> endForEachNodeItr1 = node1.getOutputPort(0).getToNodes().iterator();
while (endForEachNodeItr1.hasNext()) {
Node node2 = endForEachNodeItr1.next();
// Start reading input came for foreach node
int parallelRuns = listOfValues.size() * node1.getOutputPorts().size();
if (listOfValues.size() > 0) {
forEachNode.setState(NodeExecutionState.EXECUTING);
node1.setState(NodeExecutionState.EXECUTING);
List<DataPort> outputPorts = node1.getOutputPorts();
final AtomicInteger counter = new AtomicInteger();
for (Node endFor : endForEachNodes) {
systemInvoker = new SystemComponentInvoker();
this.invokerMap.put(endFor, systemInvoker);
}
final Map<Node, Invoker> finalMap = this.invokerMap;
new Thread() {
@Override
public void run() {
try {
runInThread(listOfValues, forEachNode, node1, finalEndForEachNodes, finalMap, counter, inputNumbers);
} catch (WorkflowException e) {
log.error(e.getLocalizedMessage(), e);
} catch (RegistryException e) {
log.error(e.getMessage(), e);
} catch (TException e) {
log.error(e.getMessage(), e);
}
}
}.start();
while (counter.intValue() < parallelRuns) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// if (!(node2 instanceof OutputNode)) {
// listOfValues.removeAll(listOfValues);
// String output = (String) systemInvoker.getOutput(node1.getOutputPort(0).getName());
// XmlElement xmlElement = XMLUtil.stringToXmlElement("<result>" + output + "</result>");
// Iterator iterator1 = xmlElement.children().iterator();
// while (iterator1.hasNext()) {
// Object next1 = iterator1.next();
// if (next1 instanceof XmlElement) {
// listOfValues.add((String) ((XmlElement) next1).children().iterator().next());
// }
// }
// }
}
}
}
// we have finished execution so end foreach is finished
// todo this has to be done in a separate thread
endForEachNode.setState(NodeExecutionState.FINISHED);
middleNode.setState(NodeExecutionState.FINISHED);
node.setState(NodeExecutionState.FINISHED);
} else {
// First node after foreach should end with EndForEachNode
List<DataPort> outputPorts1 = middleNode.getOutputPorts();
List<Node> endForEachNodes = new ArrayList<Node>();
for (DataPort port : outputPorts1) {
Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
while (endForEachNodeItr1.hasNext()) {
Node node2 = endForEachNodeItr1.next();
if (node2 instanceof EndForEachNode) {
endForEachNodes.add(node2);
} else if (node2 instanceof OutputNode) {
// intentionally left noop
} else {
throw new WorkFlowInterpreterException("Found More than one node inside foreach");
}
}
}
final List<Node> finalEndForEachNodes = endForEachNodes;
final Node foreachWSNode = middleNode;
final LinkedList<String> listOfValues = new LinkedList<String>();
// Start reading input came for foreach node
InterpreterUtil.getInputsForForEachNode(forEachNode, listOfValues, this.invokerMap);
final Integer[] inputNumbers = InterpreterUtil.getNumberOfInputsForForEachNode(forEachNode, this.invokerMap);
int parallelRuns = createInputValues(listOfValues, inputNumbers).size() * outputPorts1.size();
if (listOfValues.size() > 0) {
forEachNode.setState(NodeExecutionState.EXECUTING);
foreachWSNode.setState(NodeExecutionState.EXECUTING);
List<DataPort> outputPorts = middleNode.getOutputPorts();
final AtomicInteger counter = new AtomicInteger();
for (Node endFor : endForEachNodes) {
final SystemComponentInvoker systemInvoker = new SystemComponentInvoker();
this.invokerMap.put(endFor, systemInvoker);
}
final Map<Node, Invoker> finalInvokerMap = this.invokerMap;
new Thread() {
@Override
public void run() {
try {
runInThread(listOfValues, forEachNode, foreachWSNode, finalEndForEachNodes, finalInvokerMap, counter, inputNumbers);
} catch (WorkflowException e) {
log.error(e.getLocalizedMessage(), e);
} catch (RegistryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
while (counter.intValue() < parallelRuns) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// we have finished execution so end foreach is finished
// todo this has to be done in a separate thread
middleNode.setState(NodeExecutionState.FINISHED);
for (Node endForEach : endForEachNodes) {
endForEach.setState(NodeExecutionState.FINISHED);
}
} else {
throw new WorkFlowInterpreterException("No array values found for foreach");
}
}
}
}
use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class WorkflowEngineImpl method launchExperiment.
@Override
public void launchExperiment(String experimentId, String token) throws WorkflowEngineException {
try {
ExperimentCatalog experimentCatalog = RegistryFactory.getDefaultExpCatalog();
Experiment experiment = (Experiment) experimentCatalog.get(ExperimentCatalogModelType.EXPERIMENT, experimentId);
WorkflowCatalog workflowCatalog = WorkflowCatalogFactory.getWorkflowCatalog();
WorkflowInterpreterConfiguration config = new WorkflowInterpreterConfiguration(new Workflow(workflowCatalog.getWorkflow(experiment.getApplicationId()).getGraph()));
final WorkflowInterpreter workflowInterpreter = new WorkflowInterpreter(experiment, token, config, getOrchestratorClient(), rabbitMQPublisher);
new Thread() {
public void run() {
try {
workflowInterpreter.scheduleDynamically();
} catch (WorkflowException e) {
logger.error(e.getMessage(), e);
} catch (RegistryException e) {
logger.error(e.getMessage(), e);
} catch (AiravataException e) {
logger.error(e.getMessage(), e);
}
}
}.start();
} catch (Exception e) {
logger.error("Error while retrieving the experiment", e);
WorkflowEngineException exception = new WorkflowEngineException("Error while launching the workflow experiment. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class ODEScriptFiler method save.
/**
*/
public void save() {
Workflow wf = this.engine.getGUI().getWorkflow();
if (0 == wf.getGraph().getNodes().size()) {
this.engine.getGUI().getErrorWindow().warning("Workflow is Empty");
return;
}
GpelProcess process;
try {
int returnVal = this.bpelFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = this.bpelFileChooser.getSelectedFile();
String path = file.getPath();
// Remove ".bpel" at the end if any
if (path.endsWith(XBayaConstants.BPEL_SUFFIX)) {
path = path.substring(0, path.length() - XBayaConstants.BPEL_SUFFIX.length());
}
// Add ".bpel" at the end of the file name
File bpelFile = new File(path + XBayaConstants.BPEL_SUFFIX);
// Add ".wsdl" at the end of the file name
File wsdlFile = new File(path + XBayaConstants.WSDL_SUFFIX);
// todo this has to fix, for compilation purpose passing dummy value instead of xregistry url
URI temp = null;
try {
temp = new URI("temp");
} catch (URISyntaxException e) {
log.error(e.getMessage(), e);
}
// process = wf.getOdeProcess(WSDLUtil.appendWSDLQuary(temp), this.engine.getConfiguration().getODEURL());
// String processString = process.xmlStringPretty();
// FileWriter writer = new FileWriter(bpelFile);
// writer.write(processString);
// writer.close();
//
// WsdlDefinitions workflowWSDL = wf.getOdeWorkflowWSDL(this.engine.getConfiguration().getDSCURL(),
// this.engine.getConfiguration().getODEURL());
// String workflowWsdlStr = XmlConstants.BUILDER.serializeToStringPretty(workflowWSDL.xml());
// writer = new FileWriter(wsdlFile);
// writer.write(workflowWsdlStr);
//
// Map<String, WsdlDefinitions> wsdlMap = wf.getOdeServiceWSDLs(
// this.engine.getConfiguration().getDSCURL(), this.engine.getConfiguration().getODEURL());
// Set<String> keySet = wsdlMap.keySet();
// for (String string : keySet) {
// writer = new FileWriter(new File(wsdlFile.getParent(), QName.valueOf(string).getLocalPart()));
// writer.write(XmlConstants.BUILDER.serializeToStringPretty(wsdlMap.get(string).xml()));
// writer.close();
// }
//
// XmlElement deployDescriptor = wf.getODEDeploymentDescriptor(this.engine.getConfiguration().getDSCURL(),
// this.engine.getConfiguration().getODEURL());
// writer = new FileWriter(new File(wsdlFile.getParent(), "deploy.xml"));
// writer.write(XmlConstants.BUILDER.serializeToString(deployDescriptor));
// writer.close();
//
}
//
// } catch (IOException e) {
// this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
// } catch (GraphException e) {
// this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
} catch (RuntimeException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (Error e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
// } catch (ComponentException e) {
// this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
}
}
use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class WorkflowFiler method getWorkflow.
/**
* @param workflow
* @return
*/
public Workflow getWorkflow() {
Workflow workflow = null;
int returnVal = this.graphFileChooser.showOpenDialog(this.engine.getGUI().getFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = this.graphFileChooser.getSelectedFile();
logger.debug(file.getPath());
try {
String path = file.getPath();
if (path.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
WSGraph graph = WSGraphFactory.createGraph(file);
workflow = Workflow.graphToWorkflow(graph);
} else {
XmlElement workflowElement = XMLUtil.loadXML(file);
workflow = new Workflow(workflowElement);
}
} catch (IOException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.OPEN_FILE_ERROR, e);
} catch (GraphException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
} catch (ComponentException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
} catch (RuntimeException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (Error e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
}
}
return workflow;
}
use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class WorkflowFiler method importWorkflow.
/**
* Imports a workflow from the local file to the current workflow.
*/
public void importWorkflow() {
int returnVal = this.graphFileChooser.showOpenDialog(this.engine.getGUI().getFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = this.graphFileChooser.getSelectedFile();
try {
String path = file.getPath();
Workflow importedWorkflow;
if (path.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
WSGraph importedGraph = WSGraphFactory.createGraph(file);
importedWorkflow = Workflow.graphToWorkflow(importedGraph);
} else {
XmlElement importedWorkflowElement = XMLUtil.loadXML(file);
importedWorkflow = new Workflow(importedWorkflowElement);
}
GraphCanvas newGraphCanvas = engine.getGUI().newGraphCanvas(true);
newGraphCanvas.setWorkflow(importedWorkflow);
this.engine.getGUI().setWorkflow(importedWorkflow);
engine.getGUI().getGraphCanvas().setWorkflowFile(file);
} catch (IOException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.OPEN_FILE_ERROR, e);
} catch (GraphException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
} catch (ComponentException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
} catch (RuntimeException e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
} catch (Error e) {
this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
}
}
}
Aggregations