Search in sources :

Example 1 with ConfigurationFactory

use of io.dropwizard.configuration.ConfigurationFactory in project pinot by linkedin.

the class GenerateAnomalyReport method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("please pass report config directory path\n");
        System.exit(1);
    }
    File configFile = new File(args[0]);
    AnomalyReportConfig config = OBJECT_MAPPER.readValue(configFile, AnomalyReportConfig.class);
    File persistenceFile = new File(config.getThirdEyeConfigDirectoryPath() + "/persistence.yml");
    if (!persistenceFile.exists()) {
        System.err.println("Missing file:" + persistenceFile);
        System.exit(1);
    }
    File detectorConfigFile = new File(config.getThirdEyeConfigDirectoryPath() + "/detector.yml");
    if (!detectorConfigFile.exists()) {
        System.err.println("Missing file:" + detectorConfigFile);
        System.exit(1);
    }
    ConfigurationFactory<ThirdEyeAnomalyConfiguration> factory = new ConfigurationFactory<>(ThirdEyeAnomalyConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "");
    ThirdEyeAnomalyConfiguration detectorConfig = factory.build(detectorConfigFile);
    GenerateAnomalyReport reportGenerator = new GenerateAnomalyReport(df.parse(config.getStartTimeIso()), df.parse(config.getEndTimeIso()), persistenceFile, Arrays.asList(config.getDatasets().split(",")), config.getTeBaseUrl(), detectorConfig.getSmtpConfiguration(), config.getEmailRecipients());
    reportGenerator.buildReport();
    //    reportGenerator.updateEmailConfig();
    return;
}
Also used : ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) File(java.io.File)

Example 2 with ConfigurationFactory

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

the class InheritedServerCommandTest method usesDefaultConfigPath.

@Test
void usesDefaultConfigPath() throws Exception {
    class SingletonConfigurationFactory implements ConfigurationFactory<Configuration> {

        @Override
        public Configuration build(final ConfigurationSourceProvider provider, final String path) {
            return configuration;
        }

        @Override
        public Configuration build() {
            throw new AssertionError("Didn't use the default config path variable");
        }
    }
    when(configuration.getLoggingFactory()).thenReturn(mock(LoggingFactory.class));
    final Bootstrap<Configuration> bootstrap = new Bootstrap<>(application);
    bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) -> new SingletonConfigurationFactory());
    bootstrap.addCommand(new ConfiguredCommand<Configuration>("test", "a test command") {

        @Override
        protected void run(final Bootstrap<Configuration> bootstrap, final Namespace namespace, final Configuration configuration) {
            assertThat(namespace.getString("file")).isNotEmpty().isEqualTo("yaml/server.yml");
        }

        @Override
        protected Argument addFileArgument(final Subparser subparser) {
            return super.addFileArgument(subparser).setDefault("yaml/server.yml");
        }
    });
    final JarLocation location = mock(JarLocation.class);
    when(location.toString()).thenReturn("dw-thing.jar");
    when(location.getVersion()).thenReturn(Optional.of("1.0.0"));
    Cli cli = new Cli(location, bootstrap, System.out, System.err);
    cli.run("test");
}
Also used : LoggingFactory(io.dropwizard.logging.LoggingFactory) JarLocation(io.dropwizard.util.JarLocation) Configuration(io.dropwizard.Configuration) Argument(net.sourceforge.argparse4j.inf.Argument) Namespace(net.sourceforge.argparse4j.inf.Namespace) ConfigurationSourceProvider(io.dropwizard.configuration.ConfigurationSourceProvider) ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) Subparser(net.sourceforge.argparse4j.inf.Subparser) Bootstrap(io.dropwizard.setup.Bootstrap) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationFactory

use of io.dropwizard.configuration.ConfigurationFactory in project pinot by linkedin.

the class AnomalyReportDriver method runReportGenerator.

static void runReportGenerator() throws Exception {
    File configFile = new File("/opt/Code/pinot2_0/thirdeye/thirdeye-pinot/src/test/resources/custom-anomaly-report-config.yml");
    AnomalyReportConfig config = OBJECT_MAPPER.readValue(configFile, AnomalyReportConfig.class);
    File persistenceFile = new File(config.getThirdEyeConfigDirectoryPath() + "/persistence.yml");
    if (!persistenceFile.exists()) {
        System.err.println("Missing file:" + persistenceFile);
        System.exit(1);
    }
    File detectorConfigFile = new File(config.getThirdEyeConfigDirectoryPath() + "/detector.yml");
    if (!detectorConfigFile.exists()) {
        System.err.println("Missing file:" + detectorConfigFile);
        System.exit(1);
    }
    ConfigurationFactory<ThirdEyeAnomalyConfiguration> factory = new ConfigurationFactory<>(ThirdEyeAnomalyConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "");
    ThirdEyeAnomalyConfiguration detectorConfig = factory.build(detectorConfigFile);
    long current = System.currentTimeMillis();
    Date endDate = new Date(current - (current % 36_00_000));
    Date startDate = new Date(endDate.getTime() - TimeUnit.HOURS.toMillis(24));
    GenerateAnomalyReport reportGenerator = new GenerateAnomalyReport(startDate, endDate, persistenceFile, Arrays.asList(config.getDatasets().split(",")), config.getTeBaseUrl(), detectorConfig.getSmtpConfiguration(), config.getEmailRecipients());
    reportGenerator.buildReport();
}
Also used : ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) File(java.io.File) Date(java.util.Date)

Example 4 with ConfigurationFactory

use of io.dropwizard.configuration.ConfigurationFactory in project keywhiz by square.

the class KeywhizTestRunner method createInjector.

static Injector createInjector() {
    KeywhizService service = new KeywhizService();
    Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service);
    service.initialize(bootstrap);
    File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
    KeywhizConfig config;
    try {
        config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw").build(yamlFile);
    } catch (IOException | ConfigurationException e) {
        throw Throwables.propagate(e);
    }
    Environment environment = new Environment(service.getName(), objectMapper, validator, bootstrap.getMetricRegistry(), bootstrap.getClassLoader());
    Injector injector = Guice.createInjector(new ServiceModule(config, environment));
    service.setInjector(injector);
    return injector;
}
Also used : IOException(java.io.IOException) ConfigurationException(io.dropwizard.configuration.ConfigurationException) Injector(com.google.inject.Injector) ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) Bootstrap(io.dropwizard.setup.Bootstrap) Environment(io.dropwizard.setup.Environment) File(java.io.File) Validator(javax.validation.Validator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ConfigurationFactory (io.dropwizard.configuration.ConfigurationFactory)4 File (java.io.File)3 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)2 Bootstrap (io.dropwizard.setup.Bootstrap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Injector (com.google.inject.Injector)1 Configuration (io.dropwizard.Configuration)1 ConfigurationException (io.dropwizard.configuration.ConfigurationException)1 ConfigurationSourceProvider (io.dropwizard.configuration.ConfigurationSourceProvider)1 LoggingFactory (io.dropwizard.logging.LoggingFactory)1 Environment (io.dropwizard.setup.Environment)1 JarLocation (io.dropwizard.util.JarLocation)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Validator (javax.validation.Validator)1 Argument (net.sourceforge.argparse4j.inf.Argument)1 Namespace (net.sourceforge.argparse4j.inf.Namespace)1 Subparser (net.sourceforge.argparse4j.inf.Subparser)1 Test (org.junit.jupiter.api.Test)1