Search in sources :

Example 21 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class WordCount method submitQuery.

/**
 * Submit a query containing reduce-by-key operator.
 * The query reads strings from a source server, filters alphabetical words,
 * counts words using reduce-by-key operator, and sends them to a sink server.
 * @return result of the submission
 * @throws IOException
 * @throws InjectionException
 */
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
    final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
    final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
    // Simple reduce function.
    final MISTBiFunction<Integer, Integer, Integer> reduceFunction = (v1, v2) -> {
        return v1 + v2;
    };
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.socketTextStream(localTextSocketSourceConf).filter(s -> isAlpha(s)).map(s -> new Tuple2(s, 1)).reduceByKey(0, String.class, reduceFunction).map(s -> s.toString()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : Tang(org.apache.reef.tang.Tang) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress) Tuple2(edu.snu.mist.common.types.Tuple2) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CommandLine(org.apache.reef.tang.formats.CommandLine) APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) StringUtils.isAlpha(org.apache.commons.lang3.StringUtils.isAlpha) Configuration(org.apache.reef.tang.Configuration) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) MISTBiFunction(edu.snu.mist.common.functions.MISTBiFunction) InjectionException(org.apache.reef.tang.exceptions.InjectionException) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) Tuple2(edu.snu.mist.common.types.Tuple2) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration)

Example 22 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class QueryInfoStoreTest method diskStoreTest.

/**
 * Tests whether the PlanStore correctly saves, deletes and loads the operator chain dag.
 * @throws InjectionException
 * @throws IOException
 */
@Test(timeout = 1000)
public void diskStoreTest() throws InjectionException, IOException {
    // 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();
    // Jar files
    final List<ByteBuffer> jarFiles = new LinkedList<>();
    final ByteBuffer byteBuffer1 = ByteBuffer.wrap(new byte[] { 0, 1, 0, 1, 1, 1 });
    jarFiles.add(byteBuffer1);
    final Injector injector = Tang.Factory.getTang().newInjector();
    final QueryInfoStore store = injector.getInstance(QueryInfoStore.class);
    final ApplicationCodeManager applicationCodeManager = injector.getInstance(ApplicationCodeManager.class);
    final ApplicationMap applicationMap = injector.getInstance(ApplicationMap.class);
    final String queryId1 = "testQuery1";
    final String queryId2 = "testQuery2";
    final String tmpFolderPath = injector.getNamedInstance(SharedStorePath.class);
    final File folder = new File(tmpFolderPath);
    // Store jar files
    final List<String> paths = applicationCodeManager.registerNewAppCode(jarFiles).getJarPaths();
    for (int i = 0; i < jarFiles.size(); i++) {
        final ByteBuffer buf = ByteBuffer.allocateDirect(jarFiles.get(i).capacity());
        final String path = paths.get(i);
        final FileInputStream fis = new FileInputStream(path);
        final FileChannel channel = fis.getChannel();
        channel.read(buf);
        Assert.assertEquals(jarFiles.get(i), buf);
    }
    final ApplicationInfo applicationInfo = mock(ApplicationInfo.class);
    when(applicationInfo.getApplicationId()).thenReturn(TestParameters.SUPER_GROUP_ID);
    when(applicationInfo.getJarFilePath()).thenReturn(paths);
    applicationMap.putIfAbsent(TestParameters.SUPER_GROUP_ID, applicationInfo);
    // Generate logical plan
    final Tuple<List<AvroVertex>, List<Edge>> serializedDag = query.getAvroOperatorDag();
    final AvroDag.Builder avroDagBuilder = AvroDag.newBuilder();
    final AvroDag avroDag1 = avroDagBuilder.setAppId(TestParameters.SUPER_GROUP_ID).setQueryId(TestParameters.QUERY_ID).setJarPaths(paths).setAvroVertices(serializedDag.getKey()).setEdges(serializedDag.getValue()).build();
    final AvroDag avroDag2 = avroDagBuilder.setAppId(TestParameters.SUPER_GROUP_ID).setQueryId(TestParameters.QUERY_ID).setJarPaths(paths).setAvroVertices(serializedDag.getKey()).setEdges(serializedDag.getValue()).build();
    // Store the chained dag
    store.saveAvroDag(new Tuple<>(queryId1, avroDag1));
    store.saveAvroDag(new Tuple<>(queryId2, avroDag2));
    while (!(store.isStored(queryId1) && store.isStored(queryId2))) {
    // Wait until the plan is stored
    }
    Assert.assertTrue(new File(tmpFolderPath, queryId1 + ".plan").exists());
    Assert.assertTrue(new File(tmpFolderPath, queryId2 + ".plan").exists());
    // Test stored file
    final AvroDag loadedDag1 = store.load(queryId1);
    Assert.assertEquals(avroDag1.getEdges(), loadedDag1.getEdges());
    Assert.assertEquals(avroDag1.getSchema(), loadedDag1.getSchema());
    testVerticesEqual(avroDag1.getAvroVertices(), loadedDag1.getAvroVertices());
    final AvroDag loadedDag2 = store.load(queryId2);
    Assert.assertEquals(avroDag2.getEdges(), loadedDag2.getEdges());
    Assert.assertEquals(avroDag2.getSchema(), loadedDag2.getSchema());
    testVerticesEqual(avroDag2.getAvroVertices(), loadedDag2.getAvroVertices());
    // Test deletion
    store.delete(queryId1);
    store.delete(queryId2);
    Assert.assertFalse(store.isStored(queryId1));
    Assert.assertFalse(new File(tmpFolderPath, queryId1 + ".plan").exists());
    Assert.assertFalse(store.isStored(queryId2));
    Assert.assertFalse(new File(tmpFolderPath, queryId2 + ".plan").exists());
    for (final String path : paths) {
        Assert.assertFalse(new File(path).exists());
    }
    folder.delete();
}
Also used : MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) ApplicationInfo(edu.snu.mist.core.task.groupaware.ApplicationInfo) Injector(org.apache.reef.tang.Injector) Arrays(java.util.Arrays) Tuple2(edu.snu.mist.common.types.Tuple2) SharedStorePath(edu.snu.mist.core.parameters.SharedStorePath) AvroDag(edu.snu.mist.formats.avro.AvroDag) MISTQuery(edu.snu.mist.client.MISTQuery) ByteBuffer(java.nio.ByteBuffer) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) LinkedList(java.util.LinkedList) ApplicationCodeManager(edu.snu.mist.core.master.ApplicationCodeManager) Tang(org.apache.reef.tang.Tang) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) IOException(java.io.IOException) ApplicationMap(edu.snu.mist.core.task.groupaware.ApplicationMap) FileInputStream(java.io.FileInputStream) Mockito.when(org.mockito.Mockito.when) TestParameters(edu.snu.mist.core.utils.TestParameters) File(java.io.File) List(java.util.List) Edge(edu.snu.mist.formats.avro.Edge) AvroVertex(edu.snu.mist.formats.avro.AvroVertex) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) FileChannel(java.nio.channels.FileChannel) Mockito.mock(org.mockito.Mockito.mock) ApplicationMap(edu.snu.mist.core.task.groupaware.ApplicationMap) FileChannel(java.nio.channels.FileChannel) ApplicationInfo(edu.snu.mist.core.task.groupaware.ApplicationInfo) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) AvroDag(edu.snu.mist.formats.avro.AvroDag) Injector(org.apache.reef.tang.Injector) MISTQuery(edu.snu.mist.client.MISTQuery) ApplicationCodeManager(edu.snu.mist.core.master.ApplicationCodeManager) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 23 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class HelloMist method submitQuery.

/**
 * Submit a stateless query.
 * The query reads strings from a source server, filter strings which start with "HelloMist:",
 * trim "HelloMist:" part of the filtered strings, and send them to a sink server.
 * @return result of the submission
 * @throws IOException
 * @throws InjectionException
 */
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
    final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
    final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.socketTextStream(localTextSocketSourceConf).filter(s -> s.startsWith("HelloMIST:")).map(s -> s.substring("HelloMIST:".length()).trim()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) Tang(org.apache.reef.tang.Tang) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress) Configuration(org.apache.reef.tang.Configuration) URISyntaxException(java.net.URISyntaxException) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) IOException(java.io.IOException) InjectionException(org.apache.reef.tang.exceptions.InjectionException) CommandLine(org.apache.reef.tang.formats.CommandLine) APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration)

Example 24 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project heron by twitter.

the class YarnLauncher method launch.

@Override
public boolean launch(PackingPlan packing) {
    Configuration reefRuntimeConf = getRuntimeConf();
    Configuration reefDriverConf = getHMDriverConf();
    Configuration reefClientConf = getClientConf();
    boolean ret;
    try {
        final Injector injector = Tang.Factory.getTang().newInjector(reefRuntimeConf, reefClientConf);
        final REEF reef = injector.getInstance(REEF.class);
        final ReefClientSideHandlers client = injector.getInstance(ReefClientSideHandlers.class);
        reef.submit(reefDriverConf);
        ret = client.waitForSchedulerJobResponse();
    } catch (InjectionException | InterruptedException e) {
        LOG.log(Level.WARNING, "Failed to launch REEF app", e);
        return false;
    }
    return ret;
}
Also used : InjectionException(org.apache.reef.tang.exceptions.InjectionException) REEF(org.apache.reef.client.REEF) YarnClientConfiguration(org.apache.reef.runtime.yarn.client.YarnClientConfiguration) Configuration(org.apache.reef.tang.Configuration) ClientConfiguration(org.apache.reef.client.ClientConfiguration) DriverConfiguration(org.apache.reef.client.DriverConfiguration) YarnDriverConfiguration(org.apache.reef.runtime.yarn.client.YarnDriverConfiguration) Injector(org.apache.reef.tang.Injector)

Aggregations

InjectionException (org.apache.reef.tang.exceptions.InjectionException)24 IOException (java.io.IOException)17 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)16 URISyntaxException (java.net.URISyntaxException)14 Configuration (org.apache.reef.tang.Configuration)14 Tang (org.apache.reef.tang.Tang)13 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)12 APIQueryControlResult (edu.snu.mist.client.APIQueryControlResult)11 SourceConfiguration (edu.snu.mist.client.datastreams.configurations.SourceConfiguration)11 CommandLine (org.apache.reef.tang.formats.CommandLine)11 Tuple2 (edu.snu.mist.common.types.Tuple2)9 MISTFunction (edu.snu.mist.common.functions.MISTFunction)8 NettySourceAddress (edu.snu.mist.examples.parameters.NettySourceAddress)8 Injector (org.apache.reef.tang.Injector)8 Assert (org.junit.Assert)8 Test (org.junit.Test)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 MISTBiFunction (edu.snu.mist.common.functions.MISTBiFunction)5 Tuple (org.apache.reef.io.Tuple)5