Search in sources :

Example 6 with ManagedDataSource

use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.

the class ServiceDataSourceModuleTest method injectsDataSources.

@Test
public void injectsDataSources() {
    class Holder {

        @Inject
        ManagedDataSource readWrite;

        @Inject
        @Readonly
        ManagedDataSource readonly;
    }
    Holder holder = new Holder();
    ServiceContext context = ServiceContext.create();
    Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule()).injectMembers(holder);
    assertNotNull(holder.readWrite);
    assertNotNull(holder.readonly);
}
Also used : ServiceContext(keywhiz.test.ServiceContext) ContextModule(keywhiz.inject.ContextModule) ServiceDataSourceModule(keywhiz.ServiceDataSourceModule) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Test(org.junit.Test)

Example 7 with ManagedDataSource

use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.

the class AddUserCommand method getUserDAO.

@VisibleForTesting
static UserDAO getUserDAO(Bootstrap<KeywhizConfig> bootstrap, KeywhizConfig config) {
    ManagedDataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "add-user-datasource");
    Injector injector = InjectorFactory.createInjector(config, Environments.fromBootstrap(bootstrap), dataSource);
    return injector.getInstance(UserDAO.class);
}
Also used : Injector(com.google.inject.Injector) MetricRegistry(com.codahale.metrics.MetricRegistry) ManagedDataSource(io.dropwizard.db.ManagedDataSource) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with ManagedDataSource

use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.

the class BackfillOwnershipCommand method execute.

public int execute(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) {
    ManagedDataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "backfill-ownership-datasource");
    Injector injector = InjectorFactory.createInjector(config, Environments.fromBootstrap(bootstrap), dataSource);
    DSLContext jooq = injector.getInstance(Key.get(DSLContext.class, Readonly.class));
    int batchSize = getBatchSize(namespace);
    Duration delay = getDelay(namespace);
    return new Backfill(jooq, batchSize, delay).execute();
}
Also used : Readonly(keywhiz.service.config.Readonly) Injector(com.google.inject.Injector) MetricRegistry(com.codahale.metrics.MetricRegistry) DSLContext(org.jooq.DSLContext) Duration(java.time.Duration) ManagedDataSource(io.dropwizard.db.ManagedDataSource)

Example 9 with ManagedDataSource

use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.

the class DropDeletedSecretsCommand method getSecretDAO.

@VisibleForTesting
static SecretDAO getSecretDAO(Bootstrap<KeywhizConfig> bootstrap, KeywhizConfig config) {
    ManagedDataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "drop-deleted-secrets-datasource");
    Injector injector = InjectorFactory.createInjector(config, Environments.fromBootstrap(bootstrap), dataSource);
    SecretDAO.SecretDAOFactory factory = injector.getInstance(SecretDAO.SecretDAOFactory.class);
    return factory.readwrite();
}
Also used : Injector(com.google.inject.Injector) MetricRegistry(com.codahale.metrics.MetricRegistry) ManagedDataSource(io.dropwizard.db.ManagedDataSource) SecretDAO(keywhiz.service.daos.SecretDAO) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with ManagedDataSource

use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.

the class ServiceDataSourceModule method readonlyDataSource.

@Provides
@Singleton
@Readonly
ManagedDataSource readonlyDataSource(Environment environment, KeywhizConfig config) {
    DataSourceFactory dataSourceFactory = config.getReadonlyDataSourceFactory();
    ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-readonly");
    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register("db-readonly-health", new JooqHealthCheck(dataSource, RETURN_UNHEALTHY));
    return dataSource;
}
Also used : JooqHealthCheck(keywhiz.JooqHealthCheck) DataSourceFactory(io.dropwizard.db.DataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Readonly(keywhiz.service.config.Readonly) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

ManagedDataSource (io.dropwizard.db.ManagedDataSource)12 MetricRegistry (com.codahale.metrics.MetricRegistry)5 Injector (com.google.inject.Injector)4 Provides (com.google.inject.Provides)4 Singleton (com.google.inject.Singleton)4 DataSourceFactory (io.dropwizard.db.DataSourceFactory)4 Readonly (keywhiz.service.config.Readonly)3 Test (org.junit.Test)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JooqHealthCheck (keywhiz.JooqHealthCheck)2 ServiceDataSourceModule (keywhiz.ServiceDataSourceModule)2 ContextModule (keywhiz.inject.ContextModule)2 ServiceContext (keywhiz.test.ServiceContext)2 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 InstrumentedSqlLogger (com.codahale.metrics.jdbi3.InstrumentedSqlLogger)1 StatementNameStrategy (com.codahale.metrics.jdbi3.strategies.StatementNameStrategy)1 PooledDataSourceFactory (io.dropwizard.db.PooledDataSourceFactory)1 LifecycleEnvironment (io.dropwizard.lifecycle.setup.LifecycleEnvironment)1 Environment (io.dropwizard.setup.Environment)1 Duration (java.time.Duration)1