Search in sources :

Example 11 with APIQueryControlResult

use of edu.snu.mist.client.APIQueryControlResult in project mist by snuspl.

the class WordCount method main.

/**
 * Set the environment(Hostname and port of driver, source, and sink) and submit a query.
 * @param args command line parameters
 * @throws Exception
 */
public static void main(final String[] args) throws Exception {
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    final CommandLine commandLine = MISTExampleUtils.getDefaultCommandLine(jcb).registerShortNameOfClass(// Additional parameter
    NettySourceAddress.class).processCommandLine(args);
    if (commandLine == null) {
        // Option '?' was entered and processCommandLine printed the help.
        return;
    }
    Thread sinkServer = new Thread(MISTExampleUtils.getSinkServer());
    sinkServer.start();
    final APIQueryControlResult result = submitQuery(jcb.build());
    System.out.println("Query submission result: " + result.getQueryId());
}
Also used : APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) CommandLine(org.apache.reef.tang.formats.CommandLine) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress)

Example 12 with APIQueryControlResult

use of edu.snu.mist.client.APIQueryControlResult in project mist by snuspl.

the class CepHRMonitoring method main.

/**
 * Set the environment(Hostname and port of driver, source, and sink) and submit a query.
 * @param args command line parameters
 * @throws Exception
 */
public static void main(final String[] args) throws Exception {
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    final CommandLine commandLine = MISTExampleUtils.getDefaultCommandLine(jcb).registerShortNameOfClass(// Additional parameter
    NettySourceAddress.class).processCommandLine(args);
    if (commandLine == null) {
        // Option '?' was entered and processCommandLine printed the help.
        return;
    }
    Thread sinkServer = new Thread(MISTExampleUtils.getSinkServer());
    sinkServer.start();
    final APIQueryControlResult result = submitQuery(jcb.build());
    System.out.println("Query submission result: " + result.getQueryId());
}
Also used : APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) CommandLine(org.apache.reef.tang.formats.CommandLine) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress)

Example 13 with APIQueryControlResult

use of edu.snu.mist.client.APIQueryControlResult in project mist by snuspl.

the class CepHRMonitoring method submitQuery.

public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
    final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
    final String[] source = sourceSocket.split(":");
    final String sourceHostname = source[0];
    final int sourcePort = Integer.parseInt(source[1]);
    final CepInput<CepHRClass> input = new CepInput.TextSocketBuilder<CepHRClass>().setSocketAddress(sourceHostname).setSocketPort(sourcePort).setClassGenFunc(new CepHRClassGenFunc()).build();
    final CepSink sink = new CepSink.TextSocketBuilder().setSocketAddress(MISTExampleUtils.SINK_HOSTNAME).setSocketPort(MISTExampleUtils.SINK_PORT).build();
    final MISTPredicate<CepHRClass> conditionD = s -> s.getName().equals("D");
    final MISTPredicate<CepHRClass> conditionP = s -> s.getName().equals("P");
    final CepEventPattern<CepHRClass> eventD = new CepEventPattern.Builder<CepHRClass>().setName("doctor").setCondition(conditionD).setContiguity(CepEventContiguity.NON_DETERMINISTIC_RELAXED).setClass(CepHRClass.class).build();
    final CepEventPattern<CepHRClass> eventP = new CepEventPattern.Builder<CepHRClass>().setName("patient").setCondition(conditionP).setContiguity(CepEventContiguity.NON_DETERMINISTIC_RELAXED).setNOrMore(2).setInnerContiguity(CepEventContiguity.STRICT).setClass(CepHRClass.class).build();
    final MISTCepQuery<CepHRClass> cepQuery = new MISTCepQuery.Builder<CepHRClass>("demo-group", "user1").input(input).setEventPatternSequence(eventD, eventP).setQualifier(new CepHRQualifier()).within(3600000).setAction(new CepAction.Builder().setActionType(CepActionType.TEXT_WRITE).setCepSink(sink).setParams("Alert!").build()).build();
    final MISTQueryBuilder queryBuilder = CepUtils.translate(cepQuery);
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : Tang(org.apache.reef.tang.Tang) MISTFunction(edu.snu.mist.common.functions.MISTFunction) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress) edu.snu.mist.client.cep(edu.snu.mist.client.cep) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CommandLine(org.apache.reef.tang.formats.CommandLine) APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) CepEventPattern(edu.snu.mist.common.cep.CepEventPattern) CepEventContiguity(edu.snu.mist.common.cep.CepEventContiguity) List(java.util.List) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) Configuration(org.apache.reef.tang.Configuration) Map(java.util.Map) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) InjectionException(org.apache.reef.tang.exceptions.InjectionException) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) CepEventPattern(edu.snu.mist.common.cep.CepEventPattern) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder)

Example 14 with APIQueryControlResult

use of edu.snu.mist.client.APIQueryControlResult in project mist by snuspl.

the class KMeansClustering method main.

/**
 * Set the environment(Hostname and port of driver, source, and sink) and submit a query.
 * @param args command line parameters
 * @throws Exception
 */
public static void main(final String[] args) throws Exception {
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    final CommandLine commandLine = MISTExampleUtils.getDefaultCommandLine(jcb).registerShortNameOfClass(// Additional parameter
    NettySourceAddress.class).processCommandLine(args);
    if (commandLine == null) {
        // Option '?' was entered and processCommandLine printed the help.
        return;
    }
    Thread sinkServer = new Thread(MISTExampleUtils.getSinkServer());
    sinkServer.start();
    final APIQueryControlResult result = submitQuery(jcb.build());
    System.out.println("Query submission result: " + result.getQueryId());
}
Also used : APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) CommandLine(org.apache.reef.tang.formats.CommandLine) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress)

Example 15 with APIQueryControlResult

use of edu.snu.mist.client.APIQueryControlResult 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)

Aggregations

APIQueryControlResult (edu.snu.mist.client.APIQueryControlResult)28 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)28 CommandLine (org.apache.reef.tang.formats.CommandLine)28 NettySourceAddress (edu.snu.mist.examples.parameters.NettySourceAddress)20 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)11 IOException (java.io.IOException)11 URISyntaxException (java.net.URISyntaxException)11 Configuration (org.apache.reef.tang.Configuration)11 Tang (org.apache.reef.tang.Tang)11 InjectionException (org.apache.reef.tang.exceptions.InjectionException)11 SourceConfiguration (edu.snu.mist.client.datastreams.configurations.SourceConfiguration)10 MISTFunction (edu.snu.mist.common.functions.MISTFunction)4 Tuple2 (edu.snu.mist.common.types.Tuple2)4 UnionRightSourceAddress (edu.snu.mist.examples.parameters.UnionRightSourceAddress)4 ContinuousStream (edu.snu.mist.client.datastreams.ContinuousStream)3 MISTBiFunction (edu.snu.mist.common.functions.MISTBiFunction)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