use of org.apache.reef.tang.exceptions.InjectionException 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 org.apache.reef.tang.exceptions.InjectionException 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 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;
}
use of org.apache.reef.tang.exceptions.InjectionException in project incubator-heron by apache.
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;
}
use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.
the class StatelessOperatorTest method testFilterOperator.
/**
* Test filter operator.
* It filters string values which start with "a".
*/
@Test
public void testFilterOperator() throws InjectionException {
// input stream
final List<MistDataEvent> inputStream = ImmutableList.of(new MistDataEvent("alpha", 1L), new MistDataEvent("gamma", 2L), new MistDataEvent("bravo", 3L), new MistDataEvent("area", 4L), new MistDataEvent("charlie", 5L), new MistDataEvent("delta", 6L), new MistDataEvent("application", 7L), new MistDataEvent("echo", 8L), new MistDataEvent("ally", 9L), new MistDataEvent("foxtrot", 10L));
// expected output
final List<MistEvent> expectedStream = ImmutableList.of(new MistDataEvent("alpha", 1L), new MistDataEvent("area", 4L), new MistDataEvent("application", 7L), new MistDataEvent("ally", 9L));
// create a filter function
final MISTPredicate<String> filterFunc = (input) -> input.startsWith("a");
final FilterOperator<String> filterOperator = new FilterOperator<>(filterFunc);
testStatelessOperator(inputStream, expectedStream, filterOperator);
}
Aggregations