Search in sources :

Example 11 with InjectionException

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);
}
Also used : 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) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) WindowData(edu.snu.mist.common.windows.WindowData) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation)

Example 12 with InjectionException

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);
}
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 13 with InjectionException

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;
}
Also used : InjectionException(org.apache.reef.tang.exceptions.InjectionException) REEF(org.apache.reef.client.REEF) YarnClientConfiguration(org.apache.reef.runtime.yarn.client.YarnClientConfiguration) Configuration(org.apache.reef.tang.Configuration) ClientConfiguration(org.apache.reef.client.ClientConfiguration) DriverConfiguration(org.apache.reef.client.DriverConfiguration) YarnDriverConfiguration(org.apache.reef.runtime.yarn.client.YarnDriverConfiguration) Injector(org.apache.reef.tang.Injector)

Example 14 with InjectionException

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;
}
Also used : InjectionException(org.apache.reef.tang.exceptions.InjectionException) REEF(org.apache.reef.client.REEF) YarnClientConfiguration(org.apache.reef.runtime.yarn.client.YarnClientConfiguration) Configuration(org.apache.reef.tang.Configuration) ClientConfiguration(org.apache.reef.client.ClientConfiguration) DriverConfiguration(org.apache.reef.client.DriverConfiguration) YarnDriverConfiguration(org.apache.reef.runtime.yarn.client.YarnDriverConfiguration) Injector(org.apache.reef.tang.Injector)

Example 15 with InjectionException

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);
}
Also used : Arrays(java.util.Arrays) MISTFunction(edu.snu.mist.common.functions.MISTFunction) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) MistEvent(edu.snu.mist.core.MistEvent) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) Logger(java.util.logging.Logger) MistDataEvent(edu.snu.mist.core.MistDataEvent) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) LinkedList(java.util.LinkedList) MistDataEvent(edu.snu.mist.core.MistDataEvent) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test)

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