Search in sources :

Example 31 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class MISTQueryImpl method getAvroOperatorDag.

@Override
public Tuple<List<AvroVertex>, List<Edge>> getAvroOperatorDag() {
    final LogicalDagOptimizer logicalDagOptimizer = new LogicalDagOptimizer(dag);
    final DAG<MISTStream, MISTEdge> optimizedDag = logicalDagOptimizer.getOptimizedDAG();
    final Queue<MISTStream> queue = new LinkedList<>();
    final List<MISTStream> vertices = new ArrayList<>();
    final List<Edge> edges = new ArrayList<>();
    // Put all vertices into a queue
    final Iterator<MISTStream> iterator = GraphUtils.topologicalSort(optimizedDag);
    while (iterator.hasNext()) {
        final MISTStream vertex = iterator.next();
        queue.add(vertex);
        vertices.add(vertex);
    }
    // Visit each vertex and serialize its edges
    while (!queue.isEmpty()) {
        final MISTStream vertex = queue.remove();
        final int fromIndex = vertices.indexOf(vertex);
        final Map<MISTStream, MISTEdge> neighbors = optimizedDag.getEdges(vertex);
        for (final Map.Entry<MISTStream, MISTEdge> neighbor : neighbors.entrySet()) {
            final int toIndex = vertices.indexOf(neighbor.getKey());
            final MISTEdge edgeInfo = neighbor.getValue();
            final Edge.Builder edgeBuilder = Edge.newBuilder().setFrom(fromIndex).setTo(toIndex).setDirection(edgeInfo.getDirection()).setBranchIndex(edgeInfo.getIndex());
            edges.add(edgeBuilder.build());
        }
    }
    final Set<MISTStream> rootVertices = optimizedDag.getRootVertices();
    // Serialize each vertex via avro.
    final List<AvroVertex> serializedVertices = new ArrayList<>();
    for (final MISTStream vertex : vertices) {
        final AvroVertex.Builder vertexBuilder = AvroVertex.newBuilder();
        vertexBuilder.setConfiguration(vertex.getConfiguration());
        vertexBuilder.setVertexId(String.valueOf(vertexIdIndex));
        // Set vertex type
        if (rootVertices.contains(vertex)) {
            // this is a source
            vertexBuilder.setAvroVertexType(AvroVertexTypeEnum.SOURCE);
        } else if (optimizedDag.getEdges(vertex).size() == 0) {
            // this is a sink
            vertexBuilder.setAvroVertexType(AvroVertexTypeEnum.SINK);
        } else {
            vertexBuilder.setAvroVertexType(AvroVertexTypeEnum.OPERATOR);
        }
        serializedVertices.add(vertexBuilder.build());
        vertexIdIndex++;
    }
    return new Tuple<>(serializedVertices, edges);
}
Also used : AvroVertex(edu.snu.mist.formats.avro.AvroVertex) MISTStream(edu.snu.mist.client.datastreams.MISTStream) Edge(edu.snu.mist.formats.avro.Edge) MISTEdge(edu.snu.mist.common.graph.MISTEdge) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Tuple(org.apache.reef.io.Tuple)

Example 32 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class DefaultDagGeneratorImpl method dfsCreation.

private void dfsCreation(final ExecutionVertex parent, final MISTEdge parentEdge, final ConfigVertex currVertex, final Map<ConfigVertex, ExecutionVertex> created, final DAG<ConfigVertex, MISTEdge> configDag, final ExecutionDag executionDag, final URL[] urls, final ClassLoader classLoader) throws IOException, ClassNotFoundException {
    final ExecutionVertex currExecutionVertex;
    final DAG<ExecutionVertex, MISTEdge> dag = executionDag.getDag();
    if (created.get(currVertex) == null) {
        currExecutionVertex = executionVertexGenerator.generate(currVertex, urls, classLoader);
        created.put(currVertex, currExecutionVertex);
        dag.addVertex(currExecutionVertex);
        // do dfs creation
        for (final Map.Entry<ConfigVertex, MISTEdge> edges : configDag.getEdges(currVertex).entrySet()) {
            final ConfigVertex childVertex = edges.getKey();
            final MISTEdge edge = edges.getValue();
            dfsCreation(currExecutionVertex, edge, childVertex, created, configDag, executionDag, urls, classLoader);
        }
    } else {
        currExecutionVertex = created.get(currVertex);
    }
    dag.addEdge(parent, currExecutionVertex, parentEdge);
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 33 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class DefaultDagGeneratorImpl method generate.

/**
 * This generates the logical and physical plan from the avro operator chain dag.
 * Note that the avro operator chain dag is already partitioned,
 * so we need to rewind the partition to generate the logical dag.
 * @param configDag the tuple of queryId and avro operator chain dag
 * @return the logical and execution dag
 */
@Override
public ExecutionDag generate(final DAG<ConfigVertex, MISTEdge> configDag, final List<String> jarFilePaths) throws IOException, ClassNotFoundException {
    // For execution dag
    final ExecutionDag executionDag = new ExecutionDag(new AdjacentListConcurrentMapDAG<>());
    // Get a class loader
    final URL[] urls = SerializeUtils.getJarFileURLs(jarFilePaths);
    final ClassLoader classLoader = classLoaderProvider.newInstance(urls);
    final Map<ConfigVertex, ExecutionVertex> created = new HashMap<>(configDag.numberOfVertices());
    for (final ConfigVertex source : configDag.getRootVertices()) {
        final ExecutionVertex currExecutionVertex = executionVertexGenerator.generate(source, urls, classLoader);
        executionDag.getDag().addVertex(currExecutionVertex);
        created.put(source, currExecutionVertex);
        // do dfs creation
        for (final Map.Entry<ConfigVertex, MISTEdge> edges : configDag.getEdges(source).entrySet()) {
            final ConfigVertex childVertex = edges.getKey();
            final MISTEdge edge = edges.getValue();
            dfsCreation(currExecutionVertex, edge, childVertex, created, configDag, executionDag, urls, classLoader);
        }
    }
    return executionDag;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) URL(java.net.URL) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 34 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class NonBlockingQueueSourceOutputEmitter method processAllEvent.

@Override
public int processAllEvent() {
    int numProcessedEvent = 0;
    MistEvent event = queue.poll();
    while (event != null) {
        numEvents.decrementAndGet();
        for (final Map.Entry<ExecutionVertex, MISTEdge> entry : nextOperators.entrySet()) {
            process(event, entry.getValue().getDirection(), (PhysicalOperator) entry.getKey());
        }
        numProcessedEvent += 1;
        event = queue.poll();
    }
    return numProcessedEvent;
}
Also used : Map(java.util.Map) MistEvent(edu.snu.mist.core.MistEvent) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Example 35 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class OperatorOutputEmitter method emitCheckpoint.

@Override
public void emitCheckpoint(final MistCheckpointEvent checkpoint) {
    // Checkpoint is not changed, so we just forward it to the next operator chains.
    for (final Map.Entry<ExecutionVertex, MISTEdge> nextQuery : nextOperators.entrySet()) {
        final Direction direction = nextQuery.getValue().getDirection();
        sendCheckpoint(checkpoint, direction, nextQuery.getKey());
    }
}
Also used : Map(java.util.Map) Direction(edu.snu.mist.formats.avro.Direction) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Aggregations

MISTEdge (edu.snu.mist.common.graph.MISTEdge)50 Test (org.junit.Test)23 Tuple2 (edu.snu.mist.common.types.Tuple2)12 MISTStream (edu.snu.mist.client.datastreams.MISTStream)11 Map (java.util.Map)11 DAG (edu.snu.mist.common.graph.DAG)9 Direction (edu.snu.mist.formats.avro.Direction)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 InjectionException (org.apache.reef.tang.exceptions.InjectionException)6 MISTQuery (edu.snu.mist.client.MISTQuery)5 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)5 UDFTestUtils (edu.snu.mist.client.utils.UDFTestUtils)5 AdjacentListDAG (edu.snu.mist.common.graph.AdjacentListDAG)5 TimeWindowInformation (edu.snu.mist.common.windows.TimeWindowInformation)5 List (java.util.List)5 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)5 TestParameters (edu.snu.mist.client.utils.TestParameters)4 SerializeUtils (edu.snu.mist.common.SerializeUtils)4 ConfKeys (edu.snu.mist.common.configurations.ConfKeys)4