use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class InputNode method edgeWasAdded.
/**
* Called whan an Edge was added to the parameter port. Change the name of this node.
*
* @throws GraphException
*
* @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
*/
@Override
protected void edgeWasAdded(Edge edge) throws GraphException {
super.edgeWasAdded(edge);
// TODO organize this.
if (edge instanceof DataEdge) {
DataEdge dataEdge = (DataEdge) edge;
DataPort toPort = dataEdge.getToPort();
DataType toType = toPort.getType();
List<DataEdge> edges = getEdges();
if (edges.size() == 1) {
// The first edge.
setParameterType(toType);
if (!isConfigured() && toPort instanceof WSPort) {
// Copy
copyDefaultConfiguration((WSPort) toPort);
}
} else if (edges.size() > 1) {
// Not the first edge.
DataType parameterType = getParameterType();
if (!toType.equals(WSConstants.XSD_ANY_TYPE) && !parameterType.equals(toType)) {
throw new GraphException("Cannot connect ports with different types.");
}
} else {
// Should not happen.
throw new WorkflowRuntimeException("edges.size(): " + edges.size());
}
}
}
use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class OutputNode method edgeWasAdded.
/**
* Called whan an Edge was added to the parameter port. Change the name of this node.
*
* @throws GraphException
*
* @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
*/
@Override
protected void edgeWasAdded(Edge edge) throws GraphException {
super.edgeWasAdded(edge);
// TODO organize
Port fromPort = edge.getFromPort();
if (edge instanceof DataEdge) {
DataPort fromDataPort = (DataPort) fromPort;
DataType fromType = fromDataPort.getType();
List<DataEdge> edges = getEdges();
if (edges.size() == 1) {
setParameterType(fromType);
if (!isConfigured() && fromDataPort instanceof WSPort) {
setName(fromDataPort.getName());
WSComponentPort componentPort = ((WSPort) fromDataPort).getComponentPort();
setDescription(componentPort.getDescription());
setMetadata(componentPort.getAppinfo());
}
} else {
throw new GraphException("Cannot connect more than one output ports to the output parameter.");
}
}
}
use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class EndifNode method portTypeChanged.
/**
* @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
*/
@Override
protected void portTypeChanged(SystemDataPort port) throws GraphException {
super.portTypeChanged(port);
List<DataPort> inputPorts = getInputPorts();
List<DataPort> outputPorts = getOutputPorts();
int size = outputPorts.size();
Kind kind = port.getKind();
int index;
if (kind == Kind.DATA_IN) {
index = inputPorts.indexOf(port) % size;
} else if (kind == Kind.DATA_OUT) {
index = outputPorts.indexOf(port);
} else {
throw new WorkflowRuntimeException();
}
DataPort inputPort1 = inputPorts.get(index);
DataPort inputPort2 = inputPorts.get(size + index);
DataPort outputPort = outputPorts.get(index);
DataType inputType1 = inputPort1.getType();
DataType inputType2 = inputPort2.getType();
DataType outputType = outputPort.getType();
DataType portType = port.getType();
if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
// Do nothing
return;
}
if (port == inputPort1) {
// input1 -> input2
if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort2.copyType(port);
} else if (inputType2.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
throw new GraphException(message);
}
// input1 -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else if (port == inputPort2) {
// input2 -> input1
if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort1.copyType(port);
} else if (inputType1.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
throw new GraphException(message);
}
// input2 -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else if (port == outputPort) {
// output -> input1
if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort1.copyType(port);
} else if (inputType1.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
// output -> input2
if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort2.copyType(port);
} else if (inputType2.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of input " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else {
throw new WorkflowRuntimeException();
}
}
use of org.apache.airavata.workflow.model.graph.GraphException in project airavata by apache.
the class JythonScript method writeOutput.
private void writeOutput(OutputNode node, PrintWriter pw) throws GraphException {
String id = node.getID();
Port port = node.getPort();
Node fromNode = port.getFromNode();
if (fromNode == null) {
throw new GraphException("Output parameter has to be connected to some node.");
}
Port fromPort = port.getFromPort();
if (fromNode instanceof InputNode) {
// The OutputNode is directly connected to an InputNode.
pw.println(TAB + id + VALUE_SUFFIX + " = " + PROPERTIES_VARIABLE + "." + GET_PROPERTY_METHOD + "('" + fromNode.getID() + "')");
} else {
pw.println(TAB + "# Wait output " + id);
pw.println(TAB + id + VALUE_SUFFIX + " = " + fromNode.getID() + INVOKER_SUFFIX + "." + GET_OUTPUT_METHOD + "('" + fromPort.getName() + "')");
}
pw.println(TAB + "print '" + id + " = ', " + id + VALUE_SUFFIX);
// This might try to remove a node that has been removed
// already, but it's OK.
this.executingNodes.remove(fromNode);
pw.println();
}
use of org.apache.airavata.workflow.model.graph.GraphException 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);
}
}
}
Aggregations