Search in sources :

Example 1 with FileConfigurationSourceProvider

use of io.dropwizard.configuration.FileConfigurationSourceProvider in project api-core by ca-cwds.

the class ElasticSearchLiveTestRunner method main.

/**
 * Let 'er rip!
 *
 * @param args command line
 * @throws Exception Exception rises to the top
 */
public static void main(String... args) throws Exception {
    if (args.length < 2) {
        throw new ApiException("Usage: java " + ElasticSearchLiveTestRunner.class.getName() + " <ES config file> <search terms>");
    }
    final String path = args[0];
    final String searchFor = args[1];
    final ConfigurationSourceProvider provider = new SubstitutingSourceProvider(new FileConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false));
    ElasticsearchConfiguration config;
    try (InputStream iss = provider.open(path)) {
        config = YAML_MAPPER.readValue(iss, ElasticsearchConfiguration.class);
    }
    try (AutoCloseElasticsearchDao autoCloseDao = new AutoCloseElasticsearchDao(elasticsearchClient(config))) {
        ElasticSearchLiveTestRunner job = new ElasticSearchLiveTestRunner(autoCloseDao, searchFor);
        job.run();
    }
}
Also used : SubstitutingSourceProvider(io.dropwizard.configuration.SubstitutingSourceProvider) ConfigurationSourceProvider(io.dropwizard.configuration.ConfigurationSourceProvider) FileConfigurationSourceProvider(io.dropwizard.configuration.FileConfigurationSourceProvider) InputStream(java.io.InputStream) EnvironmentVariableSubstitutor(io.dropwizard.configuration.EnvironmentVariableSubstitutor) ElasticsearchConfiguration(gov.ca.cwds.rest.ElasticsearchConfiguration) ApiException(gov.ca.cwds.rest.api.ApiException) FileConfigurationSourceProvider(io.dropwizard.configuration.FileConfigurationSourceProvider)

Example 2 with FileConfigurationSourceProvider

use of io.dropwizard.configuration.FileConfigurationSourceProvider in project dropwizard by dropwizard.

the class DefaultLoggingFactoryTest method testConfigure.

@Test
public void testConfigure() throws Exception {
    final File newAppLog = folder.newFile("example-new-app.log");
    final File newAppNotAdditiveLog = folder.newFile("example-new-app-not-additive.log");
    final File defaultLog = folder.newFile("example.log");
    final StrSubstitutor substitutor = new StrSubstitutor(ImmutableMap.of("new_app", StringUtils.removeEnd(newAppLog.getAbsolutePath(), ".log"), "new_app_not_additive", StringUtils.removeEnd(newAppNotAdditiveLog.getAbsolutePath(), ".log"), "default", StringUtils.removeEnd(defaultLog.getAbsolutePath(), ".log")));
    final String configPath = Resources.getResource("yaml/logging_advanced.yml").getFile();
    final DefaultLoggingFactory config = factory.build(new SubstitutingSourceProvider(new FileConfigurationSourceProvider(), substitutor), configPath);
    config.configure(new MetricRegistry(), "test-logger");
    LoggerFactory.getLogger("com.example.app").debug("Application debug log");
    LoggerFactory.getLogger("com.example.app").info("Application log");
    LoggerFactory.getLogger("com.example.newApp").debug("New application debug log");
    LoggerFactory.getLogger("com.example.newApp").info("New application info log");
    LoggerFactory.getLogger("com.example.legacyApp").debug("Legacy application debug log");
    LoggerFactory.getLogger("com.example.legacyApp").info("Legacy application info log");
    LoggerFactory.getLogger("com.example.notAdditive").debug("Not additive application debug log");
    LoggerFactory.getLogger("com.example.notAdditive").info("Not additive application info log");
    config.stop();
    assertThat(Files.readLines(defaultLog, StandardCharsets.UTF_8)).containsOnly("INFO  com.example.app: Application log", "DEBUG com.example.newApp: New application debug log", "INFO  com.example.newApp: New application info log", "DEBUG com.example.legacyApp: Legacy application debug log", "INFO  com.example.legacyApp: Legacy application info log");
    assertThat(Files.readLines(newAppLog, StandardCharsets.UTF_8)).containsOnly("DEBUG com.example.newApp: New application debug log", "INFO  com.example.newApp: New application info log");
    assertThat(Files.readLines(newAppNotAdditiveLog, StandardCharsets.UTF_8)).containsOnly("DEBUG com.example.notAdditive: Not additive application debug log", "INFO  com.example.notAdditive: Not additive application info log");
}
Also used : SubstitutingSourceProvider(io.dropwizard.configuration.SubstitutingSourceProvider) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) MetricRegistry(com.codahale.metrics.MetricRegistry) File(java.io.File) FileConfigurationSourceProvider(io.dropwizard.configuration.FileConfigurationSourceProvider) Test(org.junit.Test)

Aggregations

FileConfigurationSourceProvider (io.dropwizard.configuration.FileConfigurationSourceProvider)2 SubstitutingSourceProvider (io.dropwizard.configuration.SubstitutingSourceProvider)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ElasticsearchConfiguration (gov.ca.cwds.rest.ElasticsearchConfiguration)1 ApiException (gov.ca.cwds.rest.api.ApiException)1 ConfigurationSourceProvider (io.dropwizard.configuration.ConfigurationSourceProvider)1 EnvironmentVariableSubstitutor (io.dropwizard.configuration.EnvironmentVariableSubstitutor)1 File (java.io.File)1 InputStream (java.io.InputStream)1 StrSubstitutor (org.apache.commons.lang3.text.StrSubstitutor)1 Test (org.junit.Test)1