use of org.apache.airavata.workflow.model.graph.DataPort in project airavata by apache.
the class LaunchApplicationWindow method show.
/**
* Shows the dialog.
*/
public void show() {
this.workflow = this.engine.getGUI().getWorkflow();
// Create input fields
// Collection<InputNode> inputNodes = GraphUtil.getInputNodes(this.workflow.getGraph());
// for (InputNode node : inputNodes) {
// String id = node.getID();
// QName parameterType = node.getParameterType();
// JLabel nameLabel = new JLabel(id);
// JLabel typeField = new JLabel(parameterType.getLocalPart());
// XBayaTextField paramField = new XBayaTextField();
// Object value = node.getDefaultValue();
//
// String valueString;
// if (value == null) {
// valueString = "";
// } else {
// if (value instanceof XmlElement) {
// XmlElement valueElement = (XmlElement) value;
// valueString = XMLUtil.xmlElementToString(valueElement);
// } else {
// // Only string comes here for now.
// valueString = value.toString();
// }
// }
// paramField.setText(valueString);
List<NodeImpl> nodes = workflow.getGraph().getNodes();
NodeImpl node = null;
for (int i = 0; i < nodes.size(); i++) {
node = nodes.get(i);
String html = node.getComponent().toHTML();
String nodeType = html.substring(html.indexOf("<h1>") + 4, html.indexOf(":")).trim();
if (nodeType.equals("Application")) {
break;
}
}
List<DataPort> inputPorts = node.getInputPorts();
for (DataPort port : inputPorts) {
String id = port.getName();
DataType parameterType = port.getType();
JLabel nameLabel = new JLabel(id);
JLabel typeField = new JLabel(parameterType.toString());
XBayaTextField paramField = new XBayaTextField();
paramField.setText("");
this.parameterPanel.add(nameLabel);
this.parameterPanel.add(typeField);
this.parameterPanel.add(paramField);
this.parameterTextFields.add(paramField);
}
Map<String, String> hosts = null;
try {
hosts = airavataClient.getAllComputeResourceNames();
} catch (InvalidRequestException e) {
logger.error(e.getMessage(), e);
} catch (AiravataClientException e) {
logger.error(e.getMessage(), e);
} catch (AiravataSystemException e) {
logger.error(e.getMessage(), e);
} catch (TException e) {
logger.error(e.getMessage(), e);
}
hostNames = new HashMap<String, String>();
Iterator it = hosts.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String key = (String) pairs.getKey();
String value = (String) pairs.getValue();
if (!hostNames.containsKey(value)) {
hostNames.put(value, key);
}
}
host = new JComboBox();
it = hostNames.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String key = (String) pairs.getKey();
host.addItem(key);
}
host.setSelectedIndex(1);
XBayaLabel hostLabel = new XBayaLabel("Host", this.host);
this.parameterPanel.add(hostLabel);
this.parameterPanel.add(host);
// this.parameterPanel.layout(inputNodes.size()+1, 2, GridPanel.WEIGHT_NONE, 2);
this.dialog.show();
}
use of org.apache.airavata.workflow.model.graph.DataPort 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.DataPort in project airavata by apache.
the class WorkflowHarvester method getRemainderPorts.
/**
* @param pair
* @return
*/
private List<DataPort> getRemainderPorts(Pair<WSNode, DataPort> pair) {
LinkedList<DataPort> ret = new LinkedList<DataPort>();
List<DataPort> inputPorts = pair.getLeft().getInputPorts();
for (DataPort dataPort : inputPorts) {
if (pair.getRight() != dataPort) {
ret.add(dataPort);
}
}
return ret;
}
use of org.apache.airavata.workflow.model.graph.DataPort in project airavata by apache.
the class WorkflowInterpreter method handleIf.
private void handleIf(Node node) throws WorkflowException {
IfNode ifNode = (IfNode) node;
/*
* Get all input to check condition
*/
String booleanExpression = ifNode.getXPath();
if (booleanExpression == null) {
throw new WorkFlowInterpreterException("XPath for if cannot be null");
}
List<DataPort> inputPorts = node.getInputPorts();
int i = 0;
for (DataPort port : inputPorts) {
Object inputVal = InterpreterUtil.findInputFromPort(port, this.invokerMap);
if (null == inputVal) {
throw new WorkFlowInterpreterException("Unable to find inputs for the node:" + node.getID());
}
booleanExpression = booleanExpression.replaceAll("\\$" + i, "'" + inputVal + "'");
}
// Now the XPath expression
try {
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
Boolean result = (Boolean) xpath.evaluate(booleanExpression, booleanExpression, XPathConstants.BOOLEAN);
/*
* Set control port to make execution flow continue according to
* condition
*/
for (ControlPort controlPort : node.getControlOutPorts()) {
if (controlPort.getName().equals(IfComponent.TRUE_PORT_NAME)) {
controlPort.setConditionMet(result.booleanValue());
} else if (controlPort.getName().equals(IfComponent.FALSE_PORT_NAME)) {
controlPort.setConditionMet(!result.booleanValue());
}
}
node.setState(NodeExecutionState.FINISHED);
} catch (XPathExpressionException e) {
throw new WorkFlowInterpreterException("Cannot evaluate XPath in If Condition: " + booleanExpression);
}
}
use of org.apache.airavata.workflow.model.graph.DataPort 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);
}
}
}
Aggregations