Search in sources :

Example 1 with SamzaApplication

use of org.apache.samza.application.SamzaApplication in project samza by apache.

the class LocalApplicationRunnerMain method main.

public static void main(String[] args) {
    ApplicationRunnerMain.ApplicationRunnerCommandLine cmdLine = new ApplicationRunnerMain.ApplicationRunnerCommandLine();
    OptionSet options = cmdLine.parser().parse(args);
    Config orgConfig = cmdLine.loadConfig(options);
    Config config = ConfigUtil.rewriteConfig(orgConfig);
    SamzaApplication app = ApplicationUtil.fromConfig(config);
    ApplicationRunner runner = ApplicationRunners.getApplicationRunner(app, config);
    try {
        LOGGER.info("Launching stream application: {} to run.", app);
        runner.run(buildExternalContext(config).orElse(null));
        runner.waitForFinish();
    } catch (Exception e) {
        LOGGER.error("Exception occurred when running application: {}.", app, e);
    }
}
Also used : SamzaApplication(org.apache.samza.application.SamzaApplication) ApplicationRunnerMain(org.apache.samza.runtime.ApplicationRunnerMain) ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) Config(org.apache.samza.config.Config) OptionSet(joptsimple.OptionSet)

Example 2 with SamzaApplication

use of org.apache.samza.application.SamzaApplication in project samza by apache.

the class TransactionalStateMultiStoreIntegrationTest method initialRun.

private void initialRun(List<String> inputMessages, List<String> expectedChangelogMessages) {
    // create input topic and produce the first batch of input messages
    createTopic(INPUT_TOPIC, 1);
    inputMessages.forEach(m -> produceMessage(INPUT_TOPIC, 0, m, m));
    // verify that the input messages were produced successfully
    if (inputMessages.size() > 0) {
        List<ConsumerRecord<String, String>> inputRecords = consumeMessages(INPUT_TOPIC, inputMessages.size());
        List<String> readInputMessages = inputRecords.stream().map(ConsumerRecord::value).collect(Collectors.toList());
        Assert.assertEquals(inputMessages, readInputMessages);
    }
    SamzaApplication app = new MyStatefulApplication(INPUT_SYSTEM, INPUT_TOPIC, ImmutableMap.of(STORE_1_NAME, STORE_1_CHANGELOG, STORE_2_NAME, STORE_2_CHANGELOG));
    // run the application
    RunApplicationContext context = runApplication(app, APP_NAME, CONFIGS);
    // consume and verify the changelog messages
    if (expectedChangelogMessages.size() > 0) {
        List<ConsumerRecord<String, String>> changelogRecords = consumeMessages(STORE_1_CHANGELOG, expectedChangelogMessages.size());
        List<String> changelogMessages = changelogRecords.stream().map(ConsumerRecord::value).collect(Collectors.toList());
        Assert.assertEquals(expectedChangelogMessages, changelogMessages);
    }
    // wait for the application to finish
    context.getRunner().waitForFinish();
    LOG.info("Finished initial run");
}
Also used : SamzaApplication(org.apache.samza.application.SamzaApplication) MyStatefulApplication(org.apache.samza.storage.MyStatefulApplication) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord)

Example 3 with SamzaApplication

use of org.apache.samza.application.SamzaApplication in project samza by apache.

the class TransactionalStateMultiStoreIntegrationTest method secondRun.

private void secondRun(String changelogTopic, List<String> expectedChangelogMessages, List<String> expectedInitialStoreContents) {
    // clear the local store directory
    if (!hostAffinity) {
        new FileUtil().rm(new File(LOGGED_STORE_BASE_DIR));
    }
    // produce the second batch of input messages
    List<String> inputMessages = Arrays.asList("4", "5", "5", ":shutdown");
    inputMessages.forEach(m -> produceMessage(INPUT_TOPIC, 0, m, m));
    SamzaApplication app = new MyStatefulApplication(INPUT_SYSTEM, INPUT_TOPIC, ImmutableMap.of(STORE_1_NAME, changelogTopic, STORE_2_NAME, STORE_2_CHANGELOG));
    // run the application
    RunApplicationContext context = runApplication(app, APP_NAME, CONFIGS);
    // wait for the application to finish
    context.getRunner().waitForFinish();
    // consume and verify any additional changelog messages
    List<ConsumerRecord<String, String>> changelogRecords = consumeMessages(changelogTopic, expectedChangelogMessages.size());
    List<String> changelogMessages = changelogRecords.stream().map(ConsumerRecord::value).collect(Collectors.toList());
    Assert.assertEquals(expectedChangelogMessages, changelogMessages);
    // verify the store contents during startup (this is after changelog verification to ensure init has completed)
    Assert.assertEquals(expectedInitialStoreContents, MyStatefulApplication.getInitialStoreContents().get(STORE_1_NAME));
}
Also used : SamzaApplication(org.apache.samza.application.SamzaApplication) MyStatefulApplication(org.apache.samza.storage.MyStatefulApplication) FileUtil(org.apache.samza.util.FileUtil) File(java.io.File) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord)

Aggregations

SamzaApplication (org.apache.samza.application.SamzaApplication)3 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2 MyStatefulApplication (org.apache.samza.storage.MyStatefulApplication)2 File (java.io.File)1 OptionSet (joptsimple.OptionSet)1 Config (org.apache.samza.config.Config)1 ApplicationRunner (org.apache.samza.runtime.ApplicationRunner)1 ApplicationRunnerMain (org.apache.samza.runtime.ApplicationRunnerMain)1 FileUtil (org.apache.samza.util.FileUtil)1