Search in sources :

Example 11 with MISTStream

use of edu.snu.mist.client.datastreams.MISTStream in project mist by snuspl.

the class OperatorChainDagGenerator method generateOperatorChainDAG.

/**
 * Generate OperatorChain DAG according to the logic described above.
 * @return the OperatorChain DAG
 * The chain is represented as a list and AvroVertexSerializable can be serialized by avro
 */
public DAG<List<MISTStream>, MISTEdge> generateOperatorChainDAG() {
    final DAG<OperatorChain, MISTEdge> chainDag = new AdjacentListDAG<>();
    final Map<MISTStream, OperatorChain> vertexChainMap = new HashMap<>();
    // from the root operators which are following sources.
    for (final MISTStream source : optimizedDag.getRootVertices()) {
        final Map<MISTStream, MISTEdge> rootEdges = optimizedDag.getEdges(source);
        // This chaining group is a wrapper for List, for equality check
        final OperatorChain srcChain = new OperatorChain();
        // Partition Source
        srcChain.chain.add(source);
        chainDag.addVertex(srcChain);
        vertexChainMap.put(source, srcChain);
        for (final Map.Entry<MISTStream, MISTEdge> entry : rootEdges.entrySet()) {
            final MISTStream nextVertex = entry.getKey();
            final MISTEdge edge = entry.getValue();
            final OperatorChain nextChain = getOperatorChain(nextVertex, vertexChainMap, chainDag);
            chainDag.addEdge(srcChain, nextChain, edge);
            chainingInDfsOrder(nextChain, nextVertex, chainDag, vertexChainMap);
        }
    }
    // Convert to List<AvroVertexSerializable> for AvroOperatorChainDag
    final DAG<List<MISTStream>, MISTEdge> result = new AdjacentListDAG<>();
    final Queue<OperatorChain> queue = new LinkedList<>();
    final Iterator<OperatorChain> iterator = GraphUtils.topologicalSort(chainDag);
    while (iterator.hasNext()) {
        final OperatorChain queryPartition = iterator.next();
        queue.add(queryPartition);
        result.addVertex(queryPartition.chain);
    }
    for (final OperatorChain operatorChain : queue) {
        final Map<OperatorChain, MISTEdge> edges = chainDag.getEdges(operatorChain);
        for (final Map.Entry<OperatorChain, MISTEdge> edge : edges.entrySet()) {
            result.addEdge(operatorChain.chain, edge.getKey().chain, edge.getValue());
        }
    }
    return result;
}
Also used : MISTStream(edu.snu.mist.client.datastreams.MISTStream) MISTEdge(edu.snu.mist.common.graph.MISTEdge) AdjacentListDAG(edu.snu.mist.common.graph.AdjacentListDAG)

Aggregations

MISTStream (edu.snu.mist.client.datastreams.MISTStream)11 MISTEdge (edu.snu.mist.common.graph.MISTEdge)11 HashMap (java.util.HashMap)6 List (java.util.List)5 Test (org.junit.Test)5 ContinuousStreamImpl (edu.snu.mist.client.datastreams.ContinuousStreamImpl)2 AdjacentListDAG (edu.snu.mist.common.graph.AdjacentListDAG)1 AvroVertex (edu.snu.mist.formats.avro.AvroVertex)1 Edge (edu.snu.mist.formats.avro.Edge)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Tuple (org.apache.reef.io.Tuple)1