Search in sources :

Example 86 with DataPort

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();
}
Also used : TException(org.apache.thrift.TException) NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) DataPort(org.apache.airavata.workflow.model.graph.DataPort) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) Iterator(java.util.Iterator) DataType(org.apache.airavata.model.appcatalog.appinterface.DataType) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) XBayaTextField(org.apache.airavata.xbaya.ui.widgets.XBayaTextField) AiravataClientException(org.apache.airavata.model.error.AiravataClientException) HashMap(java.util.HashMap) Map(java.util.Map) XBayaLabel(org.apache.airavata.xbaya.ui.widgets.XBayaLabel)

Example 87 with DataPort

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]);
}
Also used : InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) InputComponent(org.apache.airavata.workflow.model.component.system.InputComponent) NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) DataPort(org.apache.airavata.workflow.model.graph.DataPort) Port(org.apache.airavata.workflow.model.graph.Port) InputNode(org.apache.airavata.workflow.model.graph.system.InputNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) Node(org.apache.airavata.workflow.model.graph.Node) Workflow(org.apache.airavata.workflow.model.wf.Workflow) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) Point(java.awt.Point) LinkedList(java.util.LinkedList) DataPort(org.apache.airavata.workflow.model.graph.DataPort) GraphException(org.apache.airavata.workflow.model.graph.GraphException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) Pair(org.apache.airavata.common.utils.Pair)

Example 88 with DataPort

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;
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) LinkedList(java.util.LinkedList)

Example 89 with DataPort

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);
    }
}
Also used : DataPort(org.apache.airavata.workflow.model.graph.DataPort) XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) ControlPort(org.apache.airavata.workflow.model.graph.ControlPort) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 90 with DataPort

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);
        }
    }
}
Also used : NodeImpl(org.apache.airavata.workflow.model.graph.impl.NodeImpl) DynamicNode(org.apache.airavata.workflow.model.graph.dynamic.DynamicNode) Node(org.apache.airavata.workflow.model.graph.Node) SubWorkflowNode(org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode) WSNode(org.apache.airavata.workflow.model.graph.ws.WSNode) RegistryException(org.apache.airavata.registry.cpi.RegistryException) DataPort(org.apache.airavata.workflow.model.graph.DataPort) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType)

Aggregations

DataPort (org.apache.airavata.workflow.model.graph.DataPort)100 ComponentDataPort (org.apache.airavata.workflow.model.component.ComponentDataPort)39 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)26 Node (org.apache.airavata.workflow.model.graph.Node)26 DataEdge (org.apache.airavata.workflow.model.graph.DataEdge)20 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)16 GraphException (org.apache.airavata.workflow.model.graph.GraphException)15 InputNode (org.apache.airavata.workflow.model.graph.system.InputNode)13 DataType (org.apache.airavata.model.application.io.DataType)12 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)12 Port (org.apache.airavata.workflow.model.graph.Port)11 WSPort (org.apache.airavata.workflow.model.graph.ws.WSPort)10 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)9 DataType (org.apache.airavata.model.appcatalog.appinterface.DataType)8 NodeImpl (org.apache.airavata.workflow.model.graph.impl.NodeImpl)8 LinkedList (java.util.LinkedList)7 ControlPort (org.apache.airavata.workflow.model.graph.ControlPort)7 EPRPort (org.apache.airavata.workflow.model.graph.EPRPort)7 EndForEachNode (org.apache.airavata.workflow.model.graph.system.EndForEachNode)6 ForEachNode (org.apache.airavata.workflow.model.graph.system.ForEachNode)6