Search in sources :

Example 16 with InjectionException

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

the class MISTExampleUtils method submit.

/**
 * Submit query to MIST driver.
 */
public static APIQueryControlResult submit(final MISTQueryBuilder queryBuilder, final Configuration configuration) throws IOException, URISyntaxException, InjectionException {
    final String[] masterSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(MasterAddress.class).split(":");
    final String masterHostname = masterSocket[0];
    final int masterPort = Integer.parseInt(masterSocket[1]);
    try (final MISTExecutionEnvironment executionEnvironment = new MISTDefaultExecutionEnvironmentImpl(masterHostname, masterPort)) {
        // Upload jar
        final String jarFilePath = getJarFilePath();
        final List<String> jarFilePaths = Arrays.asList(jarFilePath);
        final JarUploadResult result = executionEnvironment.submitJar(jarFilePaths);
        queryBuilder.setApplicationId(result.getIdentifier());
        return executionEnvironment.submitQuery(queryBuilder.build());
    } catch (final Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : MasterAddress(edu.snu.mist.examples.parameters.MasterAddress) MISTDefaultExecutionEnvironmentImpl(edu.snu.mist.client.MISTDefaultExecutionEnvironmentImpl) MISTExecutionEnvironment(edu.snu.mist.client.MISTExecutionEnvironment) JarUploadResult(edu.snu.mist.formats.avro.JarUploadResult) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InjectionException(org.apache.reef.tang.exceptions.InjectionException)

Example 17 with InjectionException

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

the class MQTTNoiseSensing method submitQuery.

/**
 * Submit a query fetching data from a MQTT source.
 * The query reads strings from a MQTT topic and send them to a sink.
 * @return result of the submission
 * @throws IOException
 * @throws InjectionException
 */
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
    final String brokerURI = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(TestMQTTBrokerURI.class);
    final SourceConfiguration localMQTTSourceConf = MISTExampleUtils.getMQTTSourceConf("MISTExampleSub", brokerURI);
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    final ContinuousStream<Integer> sensedData = queryBuilder.mqttStream(localMQTTSourceConf).map((mqttMessage) -> Integer.parseInt(new String(mqttMessage.getPayload())));
    final ContinuousStream<Integer> noisy = sensedData.filter((value) -> value < 200);
    final ContinuousStream<Integer> calm = sensedData.filter((value) -> value >= 200);
    // Text socket output
    noisy.map((loudValue) -> new StringBuilder().append("It's noisy! The value was ").append(loudValue).toString()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
    // MQTT output
    noisy.map((value) -> new MqttMessage("ON".getBytes())).mqttOutput(brokerURI, "MISTExamplePub");
    calm.map((value) -> new MqttMessage("OFF".getBytes())).mqttOutput(brokerURI, "MISTExamplePub");
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) Tang(org.apache.reef.tang.Tang) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CommandLine(org.apache.reef.tang.formats.CommandLine) ContinuousStream(edu.snu.mist.client.datastreams.ContinuousStream) APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) TestMQTTBrokerURI(edu.snu.mist.examples.parameters.TestMQTTBrokerURI) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) Configuration(org.apache.reef.tang.Configuration) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) InjectionException(org.apache.reef.tang.exceptions.InjectionException) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration)

Example 18 with InjectionException

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

the class QueryDeletion 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 : MISTQueryControl(edu.snu.mist.client.MISTQueryControl) 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 19 with InjectionException

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

the class UnionMist method submitQuery.

/**
 * Submit a query unifying two sources.
 * The query reads strings from two source servers, unifies them, 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 Injector injector = Tang.Factory.getTang().newInjector(configuration);
    final String source1Socket = injector.getNamedInstance(UnionLeftSourceAddress.class);
    final String source2Socket = injector.getNamedInstance(UnionRightSourceAddress.class);
    final SourceConfiguration localTextSocketSource1Conf = MISTExampleUtils.getLocalTextSocketSourceConf(source1Socket);
    final SourceConfiguration localTextSocketSource2Conf = MISTExampleUtils.getLocalTextSocketSourceConf(source2Socket);
    // Simple reduce function.
    final MISTBiFunction<Integer, Integer, Integer> reduceFunction = (v1, v2) -> {
        return v1 + v2;
    };
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    final ContinuousStream sourceStream1 = queryBuilder.socketTextStream(localTextSocketSource1Conf).map(s -> new Tuple2(s, 1));
    final ContinuousStream sourceStream2 = queryBuilder.socketTextStream(localTextSocketSource2Conf).map(s -> new Tuple2(s, 1));
    sourceStream1.union(sourceStream2).reduceByKey(0, String.class, reduceFunction).map(s -> s.toString()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : Injector(org.apache.reef.tang.Injector) Tang(org.apache.reef.tang.Tang) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) Tuple2(edu.snu.mist.common.types.Tuple2) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CommandLine(org.apache.reef.tang.formats.CommandLine) ContinuousStream(edu.snu.mist.client.datastreams.ContinuousStream) APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) UnionLeftSourceAddress(edu.snu.mist.examples.parameters.UnionLeftSourceAddress) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) 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) UnionRightSourceAddress(edu.snu.mist.examples.parameters.UnionRightSourceAddress) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) ContinuousStream(edu.snu.mist.client.datastreams.ContinuousStream) Injector(org.apache.reef.tang.Injector) Tuple2(edu.snu.mist.common.types.Tuple2) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration)

Example 20 with InjectionException

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

the class WindowAndAggregate method submitQuery.

/**
 * Submit a windowing and aggregating query.
 * The query reads strings from a source server, puts them into window,
 * concatenates all inputs in the window into a single string using toString function, and
 * print out the start and end time of the window.
 * @return result of the submission
 * @throws IOException
 * @throws InjectionException
 */
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
    // configurations for source and sink
    final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
    final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
    // configurations for windowing and aggregation
    final int windowSize = 5000;
    final int windowEmissionInterval = 2500;
    final MISTFunction<WindowData<String>, String> aggregateFunc = (windowData) -> {
        return windowData.getDataCollection().toString() + ", window is started at " + windowData.getStart() + ", window is ended at " + windowData.getEnd() + ".";
    };
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.socketTextStream(localTextSocketSourceConf).window(new TimeWindowInformation(windowSize, windowEmissionInterval)).aggregateWindow(aggregateFunc).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : TimeWindowInformation(edu.snu.mist.common.windows.TimeWindowInformation) Tang(org.apache.reef.tang.Tang) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) MISTFunction(edu.snu.mist.common.functions.MISTFunction) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress) 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) Configuration(org.apache.reef.tang.Configuration) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) WindowData(edu.snu.mist.common.windows.WindowData) InjectionException(org.apache.reef.tang.exceptions.InjectionException) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) WindowData(edu.snu.mist.common.windows.WindowData) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) TimeWindowInformation(edu.snu.mist.common.windows.TimeWindowInformation)

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