use of com.google.gerrit.lifecycle.LifecycleModule in project gerrit by GerritCodeReview.
the class SiteProgram method createDbInjector.
/**
* Provides database connectivity and site path.
*/
protected Injector createDbInjector(boolean enableMetrics) {
List<Module> modules = new ArrayList<>();
Module sitePathModule = new AbstractModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(getConfiguredSecureStoreClass()));
}
};
modules.add(sitePathModule);
if (enableMetrics) {
modules.add(new DropWizardMetricMaker.ApiModule());
} else {
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(MetricMaker.class).to(DisabledMetricMaker.class);
}
});
}
modules.add(new LifecycleModule() {
@Override
protected void configure() {
listener().to(SystemReaderInstaller.class);
}
});
Module configModule = new GerritServerConfigModule();
modules.add(configModule);
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(GerritRuntime.class).toInstance(getGerritRuntime());
}
});
Injector cfgInjector = Guice.createInjector(sitePathModule, configModule);
modules.add(new SchemaModule());
modules.add(cfgInjector.getInstance(GitRepositoryManagerModule.class));
// The only implementation of experiments is available in all programs that can use
// gerrit.config
modules.add(new ConfigExperimentFeaturesModule());
try {
return Guice.createInjector(PRODUCTION, ModuleOverloader.override(modules, LibModuleLoader.loadModules(cfgInjector, LibModuleType.DB_MODULE_TYPE)));
} catch (CreationException ce) {
Message first = ce.getErrorMessages().iterator().next();
Throwable why = first.getCause();
StringBuilder buf = new StringBuilder();
if (why != null) {
buf.append(why.getMessage());
why = why.getCause();
} else {
buf.append(first.getMessage());
}
while (why != null) {
buf.append("\n caused by ");
buf.append(why.toString());
why = why.getCause();
}
throw die(buf.toString(), new RuntimeException("DbInjector failed", ce));
}
}
use of com.google.gerrit.lifecycle.LifecycleModule in project gerrit by GerritCodeReview.
the class WebAppInitializer method createDbInjector.
private Injector createDbInjector() {
final List<Module> modules = new ArrayList<>();
AbstractModule secureStore = createSecureStoreModule();
modules.add(secureStore);
if (sitePath != null) {
Module sitePathModule = new AbstractModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
}
};
modules.add(sitePathModule);
Module configModule = new GerritServerConfigModule();
modules.add(configModule);
Injector cfgInjector = Guice.createInjector(sitePathModule, configModule, secureStore);
Config cfg = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
String dbType = cfg.getString("database", null, "type");
final DataSourceType dst = Guice.createInjector(new DataSourceModule(), configModule, sitePathModule, secureStore).getInstance(Key.get(DataSourceType.class, Names.named(dbType.toLowerCase())));
modules.add(new LifecycleModule() {
@Override
protected void configure() {
bind(DataSourceType.class).toInstance(dst);
bind(DataSourceProvider.Context.class).toInstance(DataSourceProvider.Context.MULTI_USER);
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(DataSourceProvider.class).in(SINGLETON);
listener().to(DataSourceProvider.class);
}
});
} else {
modules.add(new LifecycleModule() {
@Override
protected void configure() {
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(ReviewDbDataSourceProvider.class).in(SINGLETON);
listener().to(ReviewDbDataSourceProvider.class);
}
});
// If we didn't get the site path from the system property
// we need to get it from the database, as that's our old
// method of locating the site path on disk.
//
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toProvider(SitePathFromSystemConfigProvider.class).in(SINGLETON);
}
});
modules.add(new GerritServerConfigModule());
}
modules.add(new DatabaseModule());
modules.add(new ConfigNotesMigration.Module());
modules.add(new DropWizardMetricMaker.ApiModule());
return Guice.createInjector(PRODUCTION, modules);
}
use of com.google.gerrit.lifecycle.LifecycleModule in project gerrit by GerritCodeReview.
the class SiteProgram method createDbInjector.
/** @return provides database connectivity and site path. */
protected Injector createDbInjector(final boolean enableMetrics, final DataSourceProvider.Context context) {
final Path sitePath = getSitePath();
final List<Module> modules = new ArrayList<>();
Module sitePathModule = new AbstractModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(getConfiguredSecureStoreClass()));
}
};
modules.add(sitePathModule);
if (enableMetrics) {
modules.add(new DropWizardMetricMaker.ApiModule());
} else {
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(MetricMaker.class).to(DisabledMetricMaker.class);
}
});
}
modules.add(new LifecycleModule() {
@Override
protected void configure() {
bind(DataSourceProvider.Context.class).toInstance(context);
if (dsProvider != null) {
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(dsProvider).in(SINGLETON);
if (LifecycleListener.class.isAssignableFrom(dsProvider.getClass())) {
listener().toInstance((LifecycleListener) dsProvider);
}
} else {
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(SiteLibraryBasedDataSourceProvider.class).in(SINGLETON);
listener().to(SiteLibraryBasedDataSourceProvider.class);
}
}
});
Module configModule = new GerritServerConfigModule();
modules.add(configModule);
Injector cfgInjector = Guice.createInjector(sitePathModule, configModule);
Config cfg = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
String dbType;
if (dsProvider != null) {
dbType = getDbType(dsProvider);
} else {
dbType = cfg.getString("database", null, "type");
}
if (dbType == null) {
throw new ProvisionException("database.type must be defined");
}
final DataSourceType dst = Guice.createInjector(new DataSourceModule(), configModule, sitePathModule).getInstance(Key.get(DataSourceType.class, Names.named(dbType.toLowerCase())));
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(DataSourceType.class).toInstance(dst);
}
});
modules.add(new DatabaseModule());
modules.add(new SchemaModule());
modules.add(cfgInjector.getInstance(GitRepositoryManagerModule.class));
modules.add(new ConfigNotesMigration.Module());
modules.addAll(LibModuleLoader.loadModules(cfgInjector));
try {
return Guice.createInjector(PRODUCTION, modules);
} catch (CreationException ce) {
final Message first = ce.getErrorMessages().iterator().next();
Throwable why = first.getCause();
if (why instanceof SQLException) {
throw die("Cannot connect to SQL database", why);
}
if (why instanceof OrmException && why.getCause() != null && "Unable to determine driver URL".equals(why.getMessage())) {
why = why.getCause();
if (isCannotCreatePoolException(why)) {
throw die("Cannot connect to SQL database", why.getCause());
}
throw die("Cannot connect to SQL database", why);
}
final StringBuilder buf = new StringBuilder();
if (why != null) {
buf.append(why.getMessage());
why = why.getCause();
} else {
buf.append(first.getMessage());
}
while (why != null) {
buf.append("\n caused by ");
buf.append(why.toString());
why = why.getCause();
}
throw die(buf.toString(), new RuntimeException("DbInjector failed", ce));
}
}
use of com.google.gerrit.lifecycle.LifecycleModule in project gerrit by GerritCodeReview.
the class ProjectCacheImpl method module.
public static Module module() {
return new CacheModule() {
@Override
protected void configure() {
// We split the project cache into two parts for performance reasons:
// 1) An in-memory part that has only the project name as key.
// 2) A persisted part that has the name and revision as key.
//
// When loading dashboards or returning change query results we potentially
// need to access hundreds of projects because each change could originate in
// a different project and, through inheritance, require us to check even more
// projects when evaluating permissions. It's not feasible to read the revision
// of refs/meta/config from each of these repos as that would require opening
// them all and reading their ref list or table.
// At the same time, we want the persisted cache to be immutable and we want it
// to be impossible that a value for a given key is out of date. We therefore
// require a revision in the key. That is in line with the rest of the caches in
// Gerrit.
//
// Splitting the cache into two chunks internally in this class allows us to retain
// the existing performance guarantees of not requiring reads for the repo for values
// cached in-memory but also to persist the cache which leads to a much improved
// cold-start behavior and in-memory miss latency.
cache(CACHE_NAME, Project.NameKey.class, CachedProjectConfig.class).loader(InMemoryLoader.class).refreshAfterWrite(Duration.ofMinutes(15)).expireAfterWrite(Duration.ofHours(1));
persist(PERSISTED_CACHE_NAME, Cache.ProjectCacheKeyProto.class, CachedProjectConfig.class).loader(PersistedLoader.class).keySerializer(new ProtobufSerializer<>(Cache.ProjectCacheKeyProto.parser())).valueSerializer(PersistedProjectConfigSerializer.INSTANCE).diskLimit(// 1 GiB
1 << 30).version(4).maximumWeight(0);
cache(CACHE_LIST, ListKey.class, new TypeLiteral<ImmutableSortedSet<Project.NameKey>>() {
}).maximumWeight(1).loader(Lister.class);
bind(ProjectCacheImpl.class);
bind(ProjectCache.class).to(ProjectCacheImpl.class);
install(new LifecycleModule() {
@Override
protected void configure() {
listener().to(ProjectCacheWarmer.class);
}
});
}
};
}
use of com.google.gerrit.lifecycle.LifecycleModule in project gerrit by GerritCodeReview.
the class WebAppInitializer method createCfgInjector.
private Injector createCfgInjector() {
final List<Module> modules = new ArrayList<>();
AbstractModule secureStore = createSecureStoreModule();
modules.add(secureStore);
Module sitePathModule = new AbstractModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
}
};
modules.add(sitePathModule);
Module configModule = new GerritServerConfigModule();
modules.add(configModule);
modules.add(new LifecycleModule() {
@Override
protected void configure() {
listener().to(SystemReaderInstaller.class);
}
});
modules.add(new DropWizardMetricMaker.ApiModule());
return Guice.createInjector(PRODUCTION, modules);
}
Aggregations