Search in sources :

Example 1 with OutPort

use of org.apache.airavata.workflow.core.dag.port.OutPort in project airavata by apache.

the class JsonWorkflowParser method readApplicationOutputs.

private List<OutPort> readApplicationOutputs(JsonReader jsonReader) throws IOException, ParserException {
    List<OutPort> outPorts = new ArrayList<>();
    PortModel portModel;
    OutPort outPort;
    String name;
    JsonToken peek = jsonReader.peek();
    if (peek == JsonToken.NULL) {
        jsonReader.nextNull();
    } else if (peek == JsonToken.BEGIN_ARRAY) {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            portModel = new PortModel();
            outPort = new OutPortImpl(portModel);
            jsonReader.beginObject();
            while (jsonReader.hasNext()) {
                name = jsonReader.nextName();
                if (name.equals(NAME)) {
                    portModel.setName(jsonReader.nextString());
                } else if (name.equals(ID)) {
                    portModel.setPortId(jsonReader.nextString());
                } else if (name.equals(DATATYPE)) {
                    jsonReader.skipValue();
                } else if (name.equals(DEFAULT_VALUE)) {
                    // can output has default values?
                    jsonReader.skipValue();
                } else if (name.equals(DESCRIPTION)) {
                    portModel.setDescription(jsonReader.nextString());
                } else {
                    jsonReader.skipValue();
                }
            }
            jsonReader.endObject();
            outPorts.add(outPort);
        }
        jsonReader.endArray();
    } else {
        throw new ParserException("Error! reading application outputs, expected " + getTokenString(JsonToken.NULL) + " or " + getTokenString(JsonToken.BEGIN_ARRAY) + " but found " + getTokenString(peek));
    }
    return outPorts;
}
Also used : OutPort(org.apache.airavata.workflow.core.dag.port.OutPort) PortModel(org.apache.airavata.model.PortModel) ArrayList(java.util.ArrayList) JsonToken(com.google.gson.stream.JsonToken) OutPortImpl(org.apache.airavata.workflow.core.dag.port.OutPortImpl)

Example 2 with OutPort

use of org.apache.airavata.workflow.core.dag.port.OutPort 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)

Aggregations

ArrayList (java.util.ArrayList)2 OutPort (org.apache.airavata.workflow.core.dag.port.OutPort)2 JsonToken (com.google.gson.stream.JsonToken)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 PortModel (org.apache.airavata.model.PortModel)1 DirectedEdge (org.apache.airavata.workflow.core.dag.edge.DirectedEdge)1 Edge (org.apache.airavata.workflow.core.dag.edge.Edge)1 ApplicationNode (org.apache.airavata.workflow.core.dag.nodes.ApplicationNode)1 InputNode (org.apache.airavata.workflow.core.dag.nodes.InputNode)1 OutputNode (org.apache.airavata.workflow.core.dag.nodes.OutputNode)1 WorkflowNode (org.apache.airavata.workflow.core.dag.nodes.WorkflowNode)1 InPort (org.apache.airavata.workflow.core.dag.port.InPort)1 OutPortImpl (org.apache.airavata.workflow.core.dag.port.OutPortImpl)1