Search in sources :

Example 1 with AvroDag

use of edu.snu.mist.formats.avro.AvroDag in project mist by snuspl.

the class QueryIdGeneratorTest method testQueryIdGenerate.

/**
 * Test whether QueryIdGenerator generates query ids correctly.
 * It creates 10,000 query ids and checks the ids.
 * @throws org.apache.reef.tang.exceptions.InjectionException
 */
@Test
public void testQueryIdGenerate() throws InjectionException {
    final Injector injector = Tang.Factory.getTang().newInjector();
    final QueryIdGenerator queryIdGenerator = injector.getInstance(QueryIdGenerator.class);
    final String prefix = injector.getNamedInstance(QueryIdPrefix.class);
    final AvroDag avroDag = new AvroDag();
    long submittedQueryNum = 0;
    while (submittedQueryNum < 10000) {
        final String queryId = queryIdGenerator.generate();
        Assert.assertEquals(prefix + submittedQueryNum, queryId);
        submittedQueryNum++;
    }
}
Also used : AvroDag(edu.snu.mist.formats.avro.AvroDag) Injector(org.apache.reef.tang.Injector) Test(org.junit.Test)

Example 2 with AvroDag

use of edu.snu.mist.formats.avro.AvroDag in project mist by snuspl.

the class DefaultGroupCheckpointStore method loadSavedQueries.

@Override
public List<AvroDag> loadSavedQueries(final List<String> queryIdList) throws IOException {
    final List<AvroDag> savedQueries = new ArrayList<>();
    for (final String queryId : queryIdList) {
        final File storedFile = getQueryStoreFile(queryId);
        final DataFileReader<AvroDag> dataFileReader = new DataFileReader<>(storedFile, avroDagDatumReader);
        AvroDag avroDag = null;
        avroDag = dataFileReader.next(avroDag);
        savedQueries.add(avroDag);
    }
    return savedQueries;
}
Also used : AvroDag(edu.snu.mist.formats.avro.AvroDag) DataFileReader(org.apache.avro.file.DataFileReader) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with AvroDag

use of edu.snu.mist.formats.avro.AvroDag in project mist by snuspl.

the class DefaultDagGeneratorImplTest method testPlanGenerator.

/**
 * Round-trip test of de-serializing AvroOperatorChainDag.
 * @throws org.apache.reef.tang.exceptions.InjectionException
 */
@Test
public void testPlanGenerator() throws InjectionException, IOException, URISyntaxException, ClassNotFoundException {
    // Generate a query
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.setApplicationId(TestParameters.SUPER_GROUP_ID);
    queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).flatMap(s -> Arrays.asList(s.split(" "))).filter(s -> s.startsWith("A")).map(s -> new Tuple2<>(s, 1)).reduceByKey(0, String.class, (Integer x, Integer y) -> x + y).textSocketOutput(TestParameters.HOST, TestParameters.SINK_PORT);
    final MISTQuery query = queryBuilder.build();
    // Generate avro operator chain dag
    final Tuple<List<AvroVertex>, List<Edge>> serializedDag = query.getAvroOperatorDag();
    final AvroDag.Builder avroDagBuilder = AvroDag.newBuilder();
    final AvroDag avroChainedDag = avroDagBuilder.setAppId(TestParameters.SUPER_GROUP_ID).setQueryId(TestParameters.QUERY_ID).setJarPaths(new ArrayList<>()).setAvroVertices(serializedDag.getKey()).setEdges(serializedDag.getValue()).build();
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(TaskHostname.class, "127.0.0.1");
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    final ConfigDagGenerator configDagGenerator = injector.getInstance(ConfigDagGenerator.class);
    final DagGenerator dagGenerator = injector.getInstance(DagGenerator.class);
    final Tuple<String, AvroDag> tuple = new Tuple<>("query-test", avroChainedDag);
    final DAG<ConfigVertex, MISTEdge> configDag = configDagGenerator.generate(tuple.getValue());
    final ExecutionDag executionDag = dagGenerator.generate(configDag, new LinkedList<>());
    // Test execution dag
    final DAG<ExecutionVertex, MISTEdge> dag = executionDag.getDag();
    final Set<ExecutionVertex> sources = dag.getRootVertices();
    Assert.assertEquals(1, sources.size());
    Assert.assertTrue(sources.iterator().next() instanceof PhysicalSource);
    final PhysicalSource source = (PhysicalSource) sources.iterator().next();
    final Map<ExecutionVertex, MISTEdge> nextOps = dag.getEdges(source);
    Assert.assertEquals(1, nextOps.size());
    final PhysicalOperator flatMapOp = (PhysicalOperator) nextOps.entrySet().iterator().next().getKey();
    final PhysicalOperator filterOp = (PhysicalOperator) dag.getEdges(flatMapOp).entrySet().iterator().next().getKey();
    final PhysicalOperator mapOp = (PhysicalOperator) dag.getEdges(filterOp).entrySet().iterator().next().getKey();
    final PhysicalOperator reduceByKeyOp = (PhysicalOperator) dag.getEdges(mapOp).entrySet().iterator().next().getKey();
    final PhysicalSink sink = (PhysicalSink) dag.getEdges(reduceByKeyOp).entrySet().iterator().next().getKey();
    Assert.assertTrue(flatMapOp.getOperator() instanceof FlatMapOperator);
    Assert.assertTrue(filterOp.getOperator() instanceof FilterOperator);
    Assert.assertTrue(mapOp.getOperator() instanceof MapOperator);
    Assert.assertTrue(reduceByKeyOp.getOperator() instanceof ReduceByKeyOperator);
    Assert.assertTrue(sink.getSink() instanceof NettyTextSink);
}
Also used : Injector(org.apache.reef.tang.Injector) java.util(java.util) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Tuple2(edu.snu.mist.common.types.Tuple2) URISyntaxException(java.net.URISyntaxException) MISTEdge(edu.snu.mist.common.graph.MISTEdge) AvroDag(edu.snu.mist.formats.avro.AvroDag) MISTQuery(edu.snu.mist.client.MISTQuery) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) ServerSocket(java.net.ServerSocket) DAG(edu.snu.mist.common.graph.DAG) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) After(org.junit.After) MapOperator(edu.snu.mist.core.operators.MapOperator) Before(org.junit.Before) Tang(org.apache.reef.tang.Tang) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) IOException(java.io.IOException) TestParameters(edu.snu.mist.core.utils.TestParameters) TaskHostname(edu.snu.mist.core.parameters.TaskHostname) FilterOperator(edu.snu.mist.core.operators.FilterOperator) Edge(edu.snu.mist.formats.avro.Edge) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) AvroVertex(edu.snu.mist.formats.avro.AvroVertex) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) AvroDag(edu.snu.mist.formats.avro.AvroDag) MapOperator(edu.snu.mist.core.operators.MapOperator) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) Injector(org.apache.reef.tang.Injector) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) MISTEdge(edu.snu.mist.common.graph.MISTEdge) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) FilterOperator(edu.snu.mist.core.operators.FilterOperator) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) MISTQuery(edu.snu.mist.client.MISTQuery) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test)

Example 4 with AvroDag

use of edu.snu.mist.formats.avro.AvroDag in project mist by snuspl.

the class DefaultCheckpointManagerImpl method recoverGroup.

@Override
public void recoverGroup(final String groupId) throws IOException {
    final Map<String, QueryCheckpoint> queryCheckpointMap;
    final List<AvroDag> dagList;
    final QueryManager queryManager = queryManagerFuture.get();
    try {
        // Load the checkpointed states and the query lists.
        queryCheckpointMap = checkpointStore.loadSavedGroupState(groupId).getQueryCheckpointMap();
        final List<String> queryIdListInGroup = new ArrayList<>();
        for (final String queryId : queryCheckpointMap.keySet()) {
            queryIdListInGroup.add(queryId);
        }
        // Load the queries.
        dagList = checkpointStore.loadSavedQueries(queryIdListInGroup);
    } catch (final FileNotFoundException ie) {
        LOG.log(Level.WARNING, "Failed in loading group {0}, this group may not exist in the checkpoint store.", new Object[] { groupId });
        return;
    }
    for (final AvroDag avroDag : dagList) {
        final QueryCheckpoint queryCheckpoint = queryCheckpointMap.get(avroDag.getQueryId());
        // Recover each query in the group.
        queryManager.createQueryWithCheckpoint(avroDag, queryCheckpoint);
    }
}
Also used : AvroDag(edu.snu.mist.formats.avro.AvroDag) QueryManager(edu.snu.mist.core.task.QueryManager) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) QueryCheckpoint(edu.snu.mist.formats.avro.QueryCheckpoint)

Example 5 with AvroDag

use of edu.snu.mist.formats.avro.AvroDag in project mist by snuspl.

the class QueryManagerTest method testSubmitComplexQueryHelper.

@SuppressWarnings("unchecked")
private void testSubmitComplexQueryHelper(final Configuration conf) throws Exception {
    final String queryId = "testQuery";
    final List<String> inputs = Arrays.asList("mist is a cloud of tiny water droplets suspended in the atmosphere", "a mist rose out of the river", "the peaks were shrouded in mist");
    // Expected results
    final List<Map<String, Integer>> intermediateResult = getIntermediateResult(inputs);
    final List<String> expectedSink1Output = intermediateResult.stream().map(input -> input.toString()).collect(Collectors.toList());
    final List<Integer> expectedSink2Output = intermediateResult.stream().map(totalCountMapFunc).collect(Collectors.toList());
    // Number of expected outputs
    final CountDownLatch countDownAllOutputs = new CountDownLatch(intermediateResult.size() * 2);
    // Create the execution DAG of the query
    final ExecutionDag executionDag = new ExecutionDag(new AdjacentListDAG<>());
    // Create source
    final TestDataGenerator dataGenerator = new TestDataGenerator(inputs);
    final EventGenerator eventGenerator = new PunctuatedEventGenerator(null, input -> false, null, 0, null, null);
    final PhysicalSource src = new PhysicalSourceImpl("testSource", new HashMap<>(), dataGenerator, eventGenerator);
    final Injector injector = Tang.Factory.getTang().newInjector(conf);
    // Create sinks
    final List<String> sink1Result = new LinkedList<>();
    final List<Integer> sink2Result = new LinkedList<>();
    final PhysicalSink sink1 = new PhysicalSinkImpl<>("sink1", null, new TestWithCountDownSink<String>(sink1Result, countDownAllOutputs));
    final PhysicalSink sink2 = new PhysicalSinkImpl<>("sink2", null, new TestWithCountDownSink<Integer>(sink2Result, countDownAllOutputs));
    // Fake operator chain dag of QueryManager
    final AvroDag fakeAvroDag = new AvroDag();
    fakeAvroDag.setQueryId(queryId);
    // fakeAvroDag.setSuperGroupId("testGroup");
    // Construct execution dag
    constructExecutionDag(executionDag, src, sink1, sink2);
    // Create mock DagGenerator. It returns the above  execution dag
    final ConfigDagGenerator configDagGenerator = mock(ConfigDagGenerator.class);
    final DAG<ConfigVertex, MISTEdge> configDag = mock(DAG.class);
    when(configDagGenerator.generate(fakeAvroDag)).thenReturn(configDag);
    final DagGenerator dagGenerator = mock(DagGenerator.class);
    // when(dagGenerator.generate(configDag, tuple.getValue().getJarFilePaths())).thenReturn(executionDag);
    // Build QueryManager
    final QueryManager queryManager = queryManagerBuild(fakeAvroDag, configDagGenerator, dagGenerator, injector);
    queryManager.create(fakeAvroDag);
    // Wait until all of the outputs are generated
    countDownAllOutputs.await();
    // Check the outputs
    Assert.assertEquals(expectedSink1Output, sink1Result);
    Assert.assertEquals(expectedSink2Output, sink2Result);
    src.close();
    queryManager.close();
    // Delete plan directory and plans
    deletePlans(injector);
}
Also used : DefaultNumEventProcessors(edu.snu.mist.core.task.groupaware.eventprocessor.parameters.DefaultNumEventProcessors) Injector(org.apache.reef.tang.Injector) java.util(java.util) EventGenerator(edu.snu.mist.core.sources.EventGenerator) Tuple2(edu.snu.mist.common.types.Tuple2) MISTEdge(edu.snu.mist.common.graph.MISTEdge) AvroDag(edu.snu.mist.formats.avro.AvroDag) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) PunctuatedEventGenerator(edu.snu.mist.core.sources.PunctuatedEventGenerator) DAG(edu.snu.mist.common.graph.DAG) Configuration(org.apache.reef.tang.Configuration) MISTBiFunction(edu.snu.mist.common.functions.MISTBiFunction) MapOperator(edu.snu.mist.core.operators.MapOperator) TestWithCountDownSink(edu.snu.mist.core.task.utils.TestWithCountDownSink) Tang(org.apache.reef.tang.Tang) MISTFunction(edu.snu.mist.common.functions.MISTFunction) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) PlanStorePath(edu.snu.mist.core.parameters.PlanStorePath) Mockito.when(org.mockito.Mockito.when) Logger(java.util.logging.Logger) QueryInfoStore(edu.snu.mist.core.task.stores.QueryInfoStore) Collectors(java.util.stream.Collectors) File(java.io.File) FilterOperator(edu.snu.mist.core.operators.FilterOperator) CountDownLatch(java.util.concurrent.CountDownLatch) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) Assert(junit.framework.Assert) MistTaskConfigs(edu.snu.mist.core.driver.MistTaskConfigs) Direction(edu.snu.mist.formats.avro.Direction) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) TestDataGenerator(edu.snu.mist.core.task.utils.TestDataGenerator) ClientToTaskPort(edu.snu.mist.core.parameters.ClientToTaskPort) AdjacentListDAG(edu.snu.mist.common.graph.AdjacentListDAG) Mockito.mock(org.mockito.Mockito.mock) TestDataGenerator(edu.snu.mist.core.task.utils.TestDataGenerator) AvroDag(edu.snu.mist.formats.avro.AvroDag) Injector(org.apache.reef.tang.Injector) MISTEdge(edu.snu.mist.common.graph.MISTEdge) EventGenerator(edu.snu.mist.core.sources.EventGenerator) PunctuatedEventGenerator(edu.snu.mist.core.sources.PunctuatedEventGenerator) CountDownLatch(java.util.concurrent.CountDownLatch) PunctuatedEventGenerator(edu.snu.mist.core.sources.PunctuatedEventGenerator)

Aggregations

AvroDag (edu.snu.mist.formats.avro.AvroDag)10 File (java.io.File)5 Injector (org.apache.reef.tang.Injector)5 Test (org.junit.Test)4 MISTQuery (edu.snu.mist.client.MISTQuery)3 Tuple2 (edu.snu.mist.common.types.Tuple2)3 IOException (java.io.IOException)3 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)3 Tang (org.apache.reef.tang.Tang)3 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)2 DAG (edu.snu.mist.common.graph.DAG)2 MISTEdge (edu.snu.mist.common.graph.MISTEdge)2 FilterOperator (edu.snu.mist.core.operators.FilterOperator)2 FlatMapOperator (edu.snu.mist.core.operators.FlatMapOperator)2 MapOperator (edu.snu.mist.core.operators.MapOperator)2 ReduceByKeyOperator (edu.snu.mist.core.operators.ReduceByKeyOperator)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2 MISTBiFunction (edu.snu.mist.common.functions.MISTBiFunction)1