Search in sources :

Example 1 with InputNode

use of org.apache.airavata.workflow.core.dag.nodes.InputNode in project airavata by apache.

the class JsonWorkflowParser method buildWorkflowGraph.

private void buildWorkflowGraph() throws Exception {
    // TODO construct runtime model
    Queue<WorkflowNode> queue = new LinkedList<>();
    queue.addAll(inputs);
    Map<String, List<Link>> linkMap = getEdgesMap(links);
    Map<String, InPort> nodeInportMap = getNodeInPortsMap(getApplicationNodes());
    nodeInportMap.putAll(getNodeInPortMap(getOutputNodes()));
    Set<String> processedNodes = new HashSet<>();
    while (!queue.isEmpty()) {
        WorkflowNode node = queue.poll();
        if (processedNodes.contains(node.getId())) {
            continue;
        }
        if (node instanceof InputNode) {
            InputNode input = ((InputNode) node);
            OutPort outPort = ((OutPort) node);
            Map<String, Edge> edgeMap = addEdges(outPort, linkMap.get(outPort.getNodeId() + "," + outPort.getId()));
            for (Map.Entry<String, Edge> entry : edgeMap.entrySet()) {
                InPort inPort = nodeInportMap.get(entry.getKey());
                if (inPort != null) {
                    // inPort.addEdge(entry.getValue());
                    entry.getValue().setToPort(inPort);
                    queue.add(inPort.getNode());
                }
            }
        } else if (node instanceof ApplicationNode) {
            ApplicationNode appNode = ((ApplicationNode) node);
            for (OutPort outPort : appNode.getOutputPorts()) {
                outPort.setNode(appNode);
                Map<String, Edge> edgeMap = addEdges(outPort, linkMap.get(outPort.getNodeId() + "," + outPort.getId()));
                for (Map.Entry<String, Edge> entry : edgeMap.entrySet()) {
                    InPort inPort = nodeInportMap.get(entry.getKey());
                    if (inPort != null) {
                        // inPort.addEdge(entry.getValue());
                        entry.getValue().setToPort(inPort);
                        queue.add(inPort.getNode());
                    }
                }
            }
        } else if (node instanceof OutputNode) {
            OutputNode outputNode = ((OutputNode) node);
            InPort inPort = ((InPort) node);
            outputNode.setInputObject(inPort.getInputObject());
        }
        // marke node as precessed node, we don't need to process it again.
        processedNodes.add(node.getId());
    }
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) OutputNode(org.apache.airavata.workflow.core.dag.nodes.OutputNode) InPort(org.apache.airavata.workflow.core.dag.port.InPort) ApplicationNode(org.apache.airavata.workflow.core.dag.nodes.ApplicationNode) WorkflowNode(org.apache.airavata.workflow.core.dag.nodes.WorkflowNode) LinkedList(java.util.LinkedList) OutPort(org.apache.airavata.workflow.core.dag.port.OutPort) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) DirectedEdge(org.apache.airavata.workflow.core.dag.edge.DirectedEdge) Edge(org.apache.airavata.workflow.core.dag.edge.Edge) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with InputNode

use of org.apache.airavata.workflow.core.dag.nodes.InputNode in project airavata by apache.

the class WorkflowInterpreter method processWorkflowInputNodes.

private void processWorkflowInputNodes(List<InputNode> inputNodes) {
    Set<WorkflowNode> tempNodeSet = new HashSet<>();
    for (InputNode inputNode : inputNodes) {
        if (inputNode.isReady()) {
            log.debug("Workflow node : " + inputNode.getId() + " is ready to execute");
            for (Edge edge : inputNode.getOutPort().getEdges()) {
                edge.getToPort().getInputObject().setValue(inputNode.getInputObject().getValue());
                if (edge.getToPort().getNode().isReady()) {
                    addToReadyQueue(edge.getToPort().getNode());
                    log.debug("Added workflow node : " + edge.getToPort().getNode().getId() + " to the readyQueue");
                } else {
                    addToWaitingQueue(edge.getToPort().getNode());
                    log.debug("Added workflow node " + edge.getToPort().getNode().getId() + " to the waitingQueue");
                }
            }
        }
    }
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) WorkflowNode(org.apache.airavata.workflow.core.dag.nodes.WorkflowNode) Edge(org.apache.airavata.workflow.core.dag.edge.Edge) HashSet(java.util.HashSet)

Example 3 with InputNode

use of org.apache.airavata.workflow.core.dag.nodes.InputNode in project airavata by apache.

the class WorkflowInterpreter method launchWorkflow.

/**
 * Package-Private method.
 *
 * @throws Exception
 */
void launchWorkflow() throws Exception {
    // WorkflowBuilder workflowBuilder = WorkflowFactory.getWorkflowBuilder(experiment.getExperimentId(), credentialToken, null);
    workflowString = getWorkflow();
    WorkflowParser workflowParser = WorkflowFactory.getWorkflowParser(workflowString);
    log.debug("Initialized workflow parser");
    workflowParser.parse();
    setInputNodes(workflowParser.getInputNodes());
    log.debug("Parsed the workflow and got the workflow input nodes");
    // process workflow input nodes
    processWorkflowInputNodes(getInputNodes());
    if (readyList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (InputNode inputNode : inputNodes) {
            sb.append(", ");
            sb.append(inputNode.getInputObject().getName());
            sb.append("=");
            sb.append(inputNode.getInputObject().getValue());
        }
        throw new AiravataException("No workflow application node is in ready state to run with experiment inputs" + sb.toString());
    }
    processReadyList();
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) WorkflowParser(org.apache.airavata.workflow.core.parser.WorkflowParser) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 4 with InputNode

use of org.apache.airavata.workflow.core.dag.nodes.InputNode in project airavata by apache.

the class WorkflowInterpreter method processReadyList.

// try to remove synchronization tag
/**
 * Package-Private method.
 *
 * @throws RegistryException
 * @throws AiravataException
 */
void processReadyList() throws RegistryException, AiravataException {
    if (readyList.isEmpty() && processingQueue.isEmpty() && !waitingList.isEmpty()) {
        throw new AiravataException("No workflow application node is in ready state to run");
    }
    for (WorkflowNode readyNode : readyList.values()) {
        if (readyNode instanceof OutputNode) {
            OutputNode outputNode = (OutputNode) readyNode;
            outputNode.getOutputObject().setValue(outputNode.getInPort().getInputObject().getValue());
            addToCompleteOutputNodeList(outputNode);
        } else if (readyNode instanceof InputNode) {
        // FIXME: set input object of applications and add applications to ready List.
        } else if (readyNode instanceof ApplicationNode) {
        // FIXME:  call orchestrator to create process for the application
        } else {
            throw new RuntimeException("Unsupported workflow node type");
        }
    }
    if (processingQueue.isEmpty() && waitingList.isEmpty()) {
        try {
            saveWorkflowOutputs();
        } catch (AppCatalogException e) {
            throw new AiravataException("Error while updating completed workflow outputs to registry", e);
        }
    }
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) OutputNode(org.apache.airavata.workflow.core.dag.nodes.OutputNode) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationNode(org.apache.airavata.workflow.core.dag.nodes.ApplicationNode) WorkflowNode(org.apache.airavata.workflow.core.dag.nodes.WorkflowNode) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 5 with InputNode

use of org.apache.airavata.workflow.core.dag.nodes.InputNode in project airavata by apache.

the class JsonWorkflowParser method readWorkflowInputs.

private void readWorkflowInputs(JsonReader jsonReader) throws ParserException, IOException {
    JsonToken peek = jsonReader.peek();
    InputNode inputNode;
    NodeModel nodeModel;
    ComponentStatus status;
    String name;
    if (peek == JsonToken.NULL) {
        throw new ParserException("Error! workflow inputs can't be null");
    } else if (peek == JsonToken.BEGIN_ARRAY) {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            nodeModel = new NodeModel();
            status = new ComponentStatus();
            status.setState(ComponentState.CREATED);
            status.setReason("Created");
            nodeModel.setStatus(status);
            inputNode = new InputNodeImpl(nodeModel);
            while (jsonReader.hasNext()) {
                name = jsonReader.nextName();
                if (name.equals(NAME)) {
                    nodeModel.setName(jsonReader.nextString());
                } else if (name.equals(ID)) {
                    nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DATATYPE)) {
                    inputNode.setDataType(DataType.valueOf(jsonReader.nextString()));
                } else if (name.equals(DESCRIPTION)) {
                    nodeModel.setDescription(jsonReader.nextString());
                } else if (name.equals(POSITION)) {
                    readPosition(jsonReader);
                } else if (name.equals(NODE_ID)) {
                    jsonReader.skipValue();
                // nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DEFAULT_VALUE)) {
                    inputNode.setValue(jsonReader.nextString());
                } else {
                    jsonReader.skipValue();
                }
            }
            jsonReader.endObject();
            inputs.add(inputNode);
        }
        jsonReader.endArray();
    } else {
        throw new ParserException("Error! Unsupported value for Workflow Inputs, exptected " + getTokenString(JsonToken.BEGIN_OBJECT) + " but found" + getTokenString(peek));
    }
}
Also used : InputNode(org.apache.airavata.workflow.core.dag.nodes.InputNode) NodeModel(org.apache.airavata.model.NodeModel) InputNodeImpl(org.apache.airavata.workflow.core.dag.nodes.InputNodeImpl) ComponentStatus(org.apache.airavata.model.ComponentStatus) JsonToken(com.google.gson.stream.JsonToken)

Aggregations

InputNode (org.apache.airavata.workflow.core.dag.nodes.InputNode)5 WorkflowNode (org.apache.airavata.workflow.core.dag.nodes.WorkflowNode)3 HashSet (java.util.HashSet)2 AiravataException (org.apache.airavata.common.exception.AiravataException)2 Edge (org.apache.airavata.workflow.core.dag.edge.Edge)2 ApplicationNode (org.apache.airavata.workflow.core.dag.nodes.ApplicationNode)2 OutputNode (org.apache.airavata.workflow.core.dag.nodes.OutputNode)2 JsonToken (com.google.gson.stream.JsonToken)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ComponentStatus (org.apache.airavata.model.ComponentStatus)1 NodeModel (org.apache.airavata.model.NodeModel)1 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)1 DirectedEdge (org.apache.airavata.workflow.core.dag.edge.DirectedEdge)1 InputNodeImpl (org.apache.airavata.workflow.core.dag.nodes.InputNodeImpl)1 InPort (org.apache.airavata.workflow.core.dag.port.InPort)1 OutPort (org.apache.airavata.workflow.core.dag.port.OutPort)1