use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class WorkflowFiler method openWorkflow.
/**
* Opens a current workflow from the local file.
*/
public void openWorkflow() {
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 {
JsonObject workflowObject = JSONUtil.loadJSON(file);
// XmlElement workflowElement = XMLUtil.loadXML(file);
// workflow = new Workflow(workflowElement);
workflow = new Workflow(workflowObject);
}
GraphCanvas newGraphCanvas = engine.getGUI().newGraphCanvas(true);
newGraphCanvas.setWorkflow(workflow);
// this.engine.setWorkflow(workflow);
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);
}
}
}
use of org.apache.airavata.workflow.model.wf.Workflow 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.wf.Workflow in project airavata by apache.
the class BPELFiler method exportBPEL.
/**
* Exports a BPEL process to the local file
*/
public void exportBPEL() {
Workflow workflow = this.engine.getGUI().getWorkflow();
BPELScript bpel = new BPELScript(workflow);
// Check if there is any errors in the workflow first.
ArrayList<String> warnings = new ArrayList<String>();
if (!bpel.validate(warnings)) {
StringBuilder buf = new StringBuilder();
for (String warning : warnings) {
buf.append("- ");
buf.append(warning);
buf.append("\n");
}
this.engine.getGUI().getErrorWindow().warning(buf.toString());
return;
}
int returnVal = this.bpelFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = this.bpelFileChooser.getSelectedFile();
logger.debug(file.getPath());
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);
// try {
// // Create the script.
// bpel.create(BPELScriptType.BPEL2);
//
// GpelProcess gpelProcess = bpel.getGpelProcess();
// XMLUtil.saveXML(gpelProcess.xml(), bpelFile);
//
// WorkflowWSDL workflowWSDL = bpel.getWorkflowWSDL();
// XMLUtil.saveXML(workflowWSDL.getWsdlDefinitions().xml(), wsdlFile);
//
// } catch (IOException e) {
// this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
// } catch (GraphException e) {
// this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_NOT_READY_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);
// }
}
}
use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class JythonFiler method exportJythonScript.
/**
* Exports a Jython script to the local file
*/
public void exportJythonScript() {
Workflow workflow = this.engine.getGUI().getWorkflow();
JythonScript script = new JythonScript(workflow, this.engine.getConfiguration());
// Check if there is any errors in the workflow first.
ArrayList<String> warnings = new ArrayList<String>();
if (!script.validate(warnings)) {
StringBuilder buf = new StringBuilder();
for (String warning : warnings) {
buf.append("- ");
buf.append(warning);
buf.append("\n");
}
this.engine.getGUI().getErrorWindow().warning(buf.toString());
return;
}
int returnVal = this.jythonFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = this.jythonFileChooser.getSelectedFile();
logger.debug(file.getPath());
// Put ".py" at the end of the file name
String path = file.getPath();
if (!path.endsWith(XBayaConstants.JYTHON_SCRIPT_SUFFIX)) {
file = new File(path + XBayaConstants.JYTHON_SCRIPT_SUFFIX);
}
try {
// Create the script.
script.create();
// Write to a file
IOUtil.writeToFile(script.getJythonString(), file);
} 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);
}
}
}
use of org.apache.airavata.workflow.model.wf.Workflow in project airavata by apache.
the class WorkflowInterpreter method handleSubWorkComponent.
private void handleSubWorkComponent(Node node) throws WorkflowException {
// TODO we will not support this in 0.13
notifyViaInteractor(WorkflowExecutionMessage.OPEN_SUBWORKFLOW, node);
// setting the inputs
Workflow subWorkflow = ((SubWorkflowNode) node).getWorkflow();
ArrayList<Node> subWorkflowInputNodes = getInputNodes(subWorkflow);
List<DataPort> inputPorts = node.getInputPorts();
for (DataPort port : inputPorts) {
Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);
if (null == inputVal) {
throw new WorkFlowInterpreterException("Unable to find inputs for the subworkflow node node:" + node.getID());
}
for (Iterator<Node> iterator = subWorkflowInputNodes.iterator(); iterator.hasNext(); ) {
InputNode inputNode = (InputNode) iterator.next();
if (inputNode.getName().equals(port.getName())) {
inputNode.setDefaultValue(inputVal);
}
}
}
for (Iterator<Node> iterator = subWorkflowInputNodes.iterator(); iterator.hasNext(); ) {
InputNode inputNode = (InputNode) iterator.next();
if (inputNode.getDefaultValue() == null) {
throw new WorkFlowInterpreterException("Input not set for :" + inputNode.getID());
}
}
try {
WorkflowInterpreter subworkflowInterpreter = (WorkflowInterpreter) getInputViaInteractor(WorkflowExecutionMessage.INPUT_WORKFLOWINTERPRETER_FOR_WORKFLOW, subWorkflow);
subworkflowInterpreter.scheduleDynamically();
} catch (Exception e) {
throw new WorkflowException(e);
}
}
Aggregations