Search in sources :

Example 11 with SourceConfiguration

use of edu.snu.mist.client.datastreams.configurations.SourceConfiguration 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 12 with SourceConfiguration

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

the class GroupRecoveryTest method buildQuery.

/**
 * Builds the query for this test.
 * @return the built MISTQuery
 */
private MISTQuery buildQuery() {
    /**
     * Build the query which consists of:
     * SRC1 -> toTuple -> reduceByKey -> sort -> toString -> sink1
     */
    final SourceConfiguration localTextSocketSource1Conf = TextSocketSourceConfiguration.newBuilder().setHostAddress("localhost").setHostPort(16118).build();
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.setApplicationId("test-group");
    final int defaultWatermarkPeriod = 100;
    final WatermarkConfiguration testConf = PeriodicWatermarkConfiguration.newBuilder().setWatermarkPeriod(defaultWatermarkPeriod).build();
    queryBuilder.socketTextStream(localTextSocketSource1Conf, testConf).map(toTupleMapFunc).reduceByKey(0, String.class, countFunc).map(m -> new TreeMap<>(m)).map(toStringMapFunc).textSocketOutput("localhost", SINK_PORT);
    return queryBuilder.build();
}
Also used : MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) TextSocketSourceConfiguration(edu.snu.mist.client.datastreams.configurations.TextSocketSourceConfiguration) PeriodicWatermarkConfiguration(edu.snu.mist.client.datastreams.configurations.PeriodicWatermarkConfiguration) WatermarkConfiguration(edu.snu.mist.client.datastreams.configurations.WatermarkConfiguration)

Aggregations

MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)12 SourceConfiguration (edu.snu.mist.client.datastreams.configurations.SourceConfiguration)12 IOException (java.io.IOException)11 URISyntaxException (java.net.URISyntaxException)11 InjectionException (org.apache.reef.tang.exceptions.InjectionException)11 APIQueryControlResult (edu.snu.mist.client.APIQueryControlResult)10 Configuration (org.apache.reef.tang.Configuration)10 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)10 Tang (org.apache.reef.tang.Tang)10 CommandLine (org.apache.reef.tang.formats.CommandLine)10 NettySourceAddress (edu.snu.mist.examples.parameters.NettySourceAddress)7 Tuple2 (edu.snu.mist.common.types.Tuple2)4 ContinuousStream (edu.snu.mist.client.datastreams.ContinuousStream)3 MISTBiFunction (edu.snu.mist.common.functions.MISTBiFunction)3 MISTFunction (edu.snu.mist.common.functions.MISTFunction)3 Injector (org.apache.reef.tang.Injector)3 ApplyStatefulFunction (edu.snu.mist.common.functions.ApplyStatefulFunction)2 TimeWindowInformation (edu.snu.mist.common.windows.TimeWindowInformation)2 WindowData (edu.snu.mist.common.windows.WindowData)2 UnionLeftSourceAddress (edu.snu.mist.examples.parameters.UnionLeftSourceAddress)2