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);
}
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);
}
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();
}
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();
}
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;
}
Aggregations