use of org.apache.airavata.workflow.model.graph.GraphException 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);
}
}
}
use of org.apache.airavata.workflow.model.graph.GraphException 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.GraphException in project airavata by apache.
the class Workflow method parse.
private void parse(JsonObject workflowObject) throws GraphException, ComponentException {
// Graph
if (workflowObject.getAsJsonObject(WORKFLOW_TAG) == null) {
throw new GraphException("Failed to parse the json object, workflow object doesn't exist");
}
JsonObject workflowObj = workflowObject.getAsJsonObject(WORKFLOW_TAG);
JsonObject graphObject = workflowObj.getAsJsonObject(GraphSchema.GRAPH_TAG);
this.graph = WSGraphFactory.createGraph(graphObject);
bindComponents();
// Image
JsonPrimitive imagePrimitive = workflowObj.getAsJsonPrimitive(IMAGE_TAG);
if (imagePrimitive != null) {
String base64 = imagePrimitive.getAsString();
byte[] bytes = Base64.decodeBase64(base64.getBytes());
try {
this.image = ImageIO.read(new ByteArrayInputStream(bytes));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class Workflow method parse.
/**
* @param workflowElement
* @throws GraphException
* @throws ComponentException
*/
private void parse(XmlElement workflowElement) throws GraphException, ComponentException {
// Graph
XmlElement graphElement = workflowElement.element(GraphSchema.GRAPH_TAG);
this.graph = WSGraphFactory.createGraph(graphElement);
// WsdlDefinitions wsdl = null;
// XmlElement wsdlsElement = workflowElement.element(WSDLS_TAG);
// for (XmlElement wsdlElement : wsdlsElement.elements(null, WSDL_TAG)) {
// String wsdlText = wsdlElement.requiredText();
// try {
// wsdl = WSDLUtil.stringToWSDL(wsdlText);
// } catch (UtilsException e) {
// logger.error(e.getMessage(), e);
// }
// String id = wsdlElement.attributeValue(NS_XWF, ID_ATTRIBUTE);
// if (id == null || id.length() == 0) {
// // xwf up to 2.2.6_2 doesn't have ID.
// id = WSDLUtil.getWSDLQName(wsdl).toString();
// }
// addWSDL(id, wsdl);
// }
bindComponents();
// Image
XmlElement imageElement = workflowElement.element(IMAGE_TAG);
if (imageElement != null) {
String base64 = imageElement.requiredText();
byte[] bytes = Base64.decodeBase64(base64.getBytes());
try {
this.image = ImageIO.read(new ByteArrayInputStream(bytes));
} catch (IOException e) {
// This should not happen and it's OK that image is broken. We
// can reproduce it anytime.
logger.error(e.getMessage(), e);
}
}
XmlElement bpelElement = workflowElement.element(BPEL_TAG);
if (bpelElement != null) {
try {
String bpelString = bpelElement.requiredText();
XmlNamespace gpelNS = XmlInfosetBuilder.newInstance().newNamespace(BPELScript.GPEL, BPELScript.GPELNS);
// GpelConstants.GPEL_NS = gpelNS;
// this.gpelProcess = new GpelProcess(XMLUtil.stringToXmlElement(bpelString));
} catch (RuntimeException e) {
String error = "Failed to parse the BPEL document.";
throw new GraphException(error, e);
}
}
XmlElement workflowWSDLElement = workflowElement.element(WORKFLOW_WSDL_TAG);
if (workflowWSDLElement != null) {
try {
String wsdlText = workflowWSDLElement.requiredText();
// this.workflowWSDL = new WsdlDefinitions(XMLUtil.stringToXmlElement(wsdlText));
} catch (RuntimeException e) {
String error = "Failed to parse the workflow WSDL.";
throw new GraphException(error, e);
}
}
}
use of org.apache.airavata.workflow.model.graph.GraphException 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);
}
}
}
Aggregations