use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class RuleBasedWeatherInfo method submitQuery.
/**
* Submit a stateless query.
* The query reads strings that represents location name and temperature from a source server,
* filter the only location "Seoul" and "Paris". And send a message if the temperature is too hot or cold
* 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 String[] source = sourceSocket.split(":");
final String sourceHostname = source[0];
final int sourcePort = Integer.parseInt(source[1]);
final String firstField = "Location";
final String secondField = "Temperature";
final RuleBasedValueType firstFieldType = RuleBasedValueType.STRING;
final RuleBasedValueType secondFieldType = RuleBasedValueType.DOUBLE;
final String sourceSeparator = ",";
/**
* Make RuleBasedInput with sourceConfiguration.
*/
final RuleBasedInput input = new RuleBasedInput.TextSocketBuilder().setSocketAddress(sourceHostname).setSocketPort(sourcePort).addField(firstField, firstFieldType).addField(secondField, secondFieldType).setSeparator(sourceSeparator).build();
/**
* Make RuleBasedSink with sinkConfiguration.
*/
final RuleBasedSink sink = new RuleBasedSink.TextSocketBuilder().setSocketAddress(MISTExampleUtils.SINK_HOSTNAME).setSocketPort(MISTExampleUtils.SINK_PORT).build();
/**
* Make a RuleBasedQuery.
*/
final MISTStatelessQuery ruleBasedQuery = new MISTStatelessQuery.Builder("example-group", "user1").input(input).addStatelessRule(new StatelessRule.Builder().setCondition(UnionCondition.and(UnionCondition.or(ComparisonCondition.eq("Location", "Seoul"), ComparisonCondition.eq("Location", "Paris")), ComparisonCondition.gt("Temperature", 30.0))).setAction(new RuleBasedAction.Builder().setActionType(RuleBasedActionType.TEXT_WRITE).setSink(sink).setParams("$Location is too hot!(Temperature : $Temperature)").build()).build()).addStatelessRule(new StatelessRule.Builder().setCondition(UnionCondition.and(UnionCondition.or(ComparisonCondition.eq("Location", "Seoul"), ComparisonCondition.eq("Location", "Paris")), ComparisonCondition.lt("Temperature", 0.0))).setAction(new RuleBasedAction.Builder().setActionType(RuleBasedActionType.TEXT_WRITE).setSink(sink).setParams("$Location is too cold!(Temperature : $Temperature)").build()).build()).build();
/**
* Translate cepStatelessQuery into MISTQuery
*/
final MISTQueryBuilder queryBuilder = RuleBasedTranslator.statelessTranslator(ruleBasedQuery);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class SessionWindow method submitQuery.
/**
* Submit a query.
* The query reads strings from a source server, puts them into a window,
* and if there is no incoming data during the interval of the session window,
* the session will be closed.
* The query will print out the data in the session, and a new session is created
* @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 by session dependent on time
final int sessionInterval = 5000;
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 SessionWindowInformation(sessionInterval)).aggregateWindow(aggregateFunc).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
System.out.println("End of submitQuery");
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.MISTQueryBuilder 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);
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class ContinuousStreamTest method setUp.
@Before
public void setUp() {
queryBuilder = new MISTQueryBuilder();
queryBuilder.setApplicationId(TestParameters.SUPER_GROUP_ID);
sourceStream = queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF);
filteredStream = sourceStream.filter(defaultFilter);
filteredMappedStream = filteredStream.map(defaultMap);
}
use of edu.snu.mist.client.MISTQueryBuilder in project mist by snuspl.
the class RuleBasedTranslator method statefulTranslator.
/**
* Translate stateful query into MIST query.
* @param query RuleBasedStatefulQuery
* @return translated MIST query
*/
public static MISTQueryBuilder statefulTranslator(final MISTStatefulQuery query) {
final RuleBasedInput input = query.getInput();
final String initialState = query.getInitialState();
final List<StatefulRule> statefulRules = query.getStatefulRules();
final Map<String, RuleBasedAction> finalStates = query.getFinalState();
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
final ContinuousStream<Map<String, Object>> inputMapStream = inputTranslator(queryBuilder, input);
statefulRulesTranslator(inputMapStream, initialState, statefulRules, finalStates);
return queryBuilder;
}
Aggregations