Search in sources :

Example 1 with ConfiguredBundle

use of io.dropwizard.ConfiguredBundle in project Singularity by HubSpot.

the class SingularityService method initialize.

@Override
public void initialize(final Bootstrap<T> bootstrap) {
    if (!Strings.isNullOrEmpty(System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY))) {
        bootstrap.setConfigurationSourceProvider(new MergingSourceProvider(bootstrap.getConfigurationSourceProvider(), System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY), bootstrap.getObjectMapper(), new YAMLFactory()));
    }
    final Iterable<? extends Module> additionalModules = checkNotNull(getGuiceModules(bootstrap), "getGuiceModules() returned null");
    final Iterable<? extends Bundle> additionalBundles = checkNotNull(getDropwizardBundles(bootstrap), "getDropwizardBundles() returned null");
    final Iterable<? extends ConfiguredBundle<T>> additionalConfiguredBundles = checkNotNull(getDropwizardConfiguredBundles(bootstrap), "getDropwizardConfiguredBundles() returned null");
    guiceBundle = GuiceBundle.defaultBuilder(SingularityConfiguration.class).modules(new SingularityServiceModule()).modules(new SingularityAuthModule()).modules(additionalModules).build();
    bootstrap.addBundle(guiceBundle);
    bootstrap.addBundle(new CorsBundle());
    bootstrap.addBundle(new ViewBundle<>());
    bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/"));
    bootstrap.addBundle(new AssetsBundle("/assets/api-docs/", "/api-docs/", "index.html", "api-docs"));
    bootstrap.addBundle(new MigrationsBundle<SingularityConfiguration>() {

        @Override
        public DataSourceFactory getDataSourceFactory(final SingularityConfiguration configuration) {
            return configuration.getDatabaseConfiguration().get();
        }
    });
    for (Bundle bundle : additionalBundles) {
        bootstrap.addBundle(bundle);
    }
    for (ConfiguredBundle<T> configuredBundle : additionalConfiguredBundles) {
        bootstrap.addBundle(configuredBundle);
    }
    bootstrap.getObjectMapper().registerModule(new ProtobufModule());
    bootstrap.getObjectMapper().registerModule(new GuavaModule());
    bootstrap.getObjectMapper().setSerializationInclusion(Include.NON_NULL);
    bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) CorsBundle(com.hubspot.singularity.bundles.CorsBundle) GuiceBundle(com.hubspot.dropwizard.guicier.GuiceBundle) MigrationsBundle(io.dropwizard.migrations.MigrationsBundle) ViewBundle(io.dropwizard.views.ViewBundle) AssetsBundle(io.dropwizard.assets.AssetsBundle) ConfiguredBundle(io.dropwizard.ConfiguredBundle) Bundle(io.dropwizard.Bundle) AssetsBundle(io.dropwizard.assets.AssetsBundle) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) MergingSourceProvider(com.hubspot.singularity.config.MergingSourceProvider) CorsBundle(com.hubspot.singularity.bundles.CorsBundle) ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration)

Aggregations

YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 GuiceBundle (com.hubspot.dropwizard.guicier.GuiceBundle)1 ProtobufModule (com.hubspot.jackson.datatype.protobuf.ProtobufModule)1 CorsBundle (com.hubspot.singularity.bundles.CorsBundle)1 MergingSourceProvider (com.hubspot.singularity.config.MergingSourceProvider)1 SingularityConfiguration (com.hubspot.singularity.config.SingularityConfiguration)1 Bundle (io.dropwizard.Bundle)1 ConfiguredBundle (io.dropwizard.ConfiguredBundle)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 DataSourceFactory (io.dropwizard.db.DataSourceFactory)1 MigrationsBundle (io.dropwizard.migrations.MigrationsBundle)1 ViewBundle (io.dropwizard.views.ViewBundle)1