Search in sources :

Example 1 with SchemaModule

use of com.google.gerrit.server.schema.SchemaModule 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));
    }
}
Also used : SchemaModule(com.google.gerrit.server.schema.SchemaModule) Message(com.google.inject.spi.Message) GerritServerConfigModule.getSecureStoreClassName(com.google.gerrit.server.config.GerritServerConfigModule.getSecureStoreClassName) SecureStoreClassName(com.google.gerrit.server.securestore.SecureStoreClassName) ArrayList(java.util.ArrayList) CreationException(com.google.inject.CreationException) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) AbstractModule(com.google.inject.AbstractModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) Injector(com.google.inject.Injector) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) DropWizardMetricMaker(com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker) SitePath(com.google.gerrit.server.config.SitePath) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) Module(com.google.inject.Module) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) AbstractModule(com.google.inject.AbstractModule) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) SystemReaderInstaller(com.google.gerrit.server.git.SystemReaderInstaller)

Example 2 with SchemaModule

use of com.google.gerrit.server.schema.SchemaModule in project gerrit by GerritCodeReview.

the class InMemoryTestingDatabaseModule method configure.

@Override
protected void configure() {
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    bind(GlobalPluginConfigProvider.class).to(FileBasedGlobalPluginConfigProvider.class);
    bind(AllProjectsConfigProvider.class).to(FileBasedAllProjectsConfigProvider.class);
    bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
    if (repoManager != null) {
        bind(GitRepositoryManager.class).toInstance(repoManager);
    } else {
        bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
        bind(InMemoryRepositoryManager.class).in(SINGLETON);
    }
    bind(MetricMaker.class).to(TestMetricMaker.class);
    listener().to(CreateSchema.class);
    bind(SitePaths.class);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    install(new SchemaModule());
    install(new SshdModule());
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SchemaModule(com.google.gerrit.server.schema.SchemaModule) InMemoryRepositoryManager(com.google.gerrit.testing.InMemoryRepositoryManager) FileBasedGlobalPluginConfigProvider(com.google.gerrit.server.config.FileBasedGlobalPluginConfigProvider) GlobalPluginConfigProvider(com.google.gerrit.server.config.GlobalPluginConfigProvider) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) SitePath(com.google.gerrit.server.config.SitePath)

Example 3 with SchemaModule

use of com.google.gerrit.server.schema.SchemaModule in project gerrit by GerritCodeReview.

the class WebAppInitializer method createCfgInjector.

private Injector createCfgInjector() {
    final List<Module> modules = new ArrayList<>();
    modules.add(new SchemaModule());
    modules.add(SchemaVersionCheck.module());
    modules.add(new AuthConfigModule());
    return dbInjector.createChildInjector(modules);
}
Also used : SchemaModule(com.google.gerrit.server.schema.SchemaModule) AuthConfigModule(com.google.gerrit.server.config.AuthConfigModule) ArrayList(java.util.ArrayList) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) AuthConfigModule(com.google.gerrit.server.config.AuthConfigModule) Module(com.google.inject.Module) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) DataSourceModule(com.google.gerrit.server.schema.DataSourceModule) DatabaseModule(com.google.gerrit.server.schema.DatabaseModule) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) OAuthModule(com.google.gerrit.httpd.auth.oauth.OAuthModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) MimeUtil2Module(com.google.gerrit.server.mime.MimeUtil2Module) GarbageCollectionModule(com.google.gerrit.server.git.GarbageCollectionModule) SshModule(com.google.gerrit.sshd.SshModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) SshAddressesModule(com.google.gerrit.server.ssh.SshAddressesModule) HttpPluginModule(com.google.gerrit.httpd.plugins.HttpPluginModule) DefaultCommandModule(com.google.gerrit.sshd.commands.DefaultCommandModule) PluginRestApiModule(com.google.gerrit.server.plugins.PluginRestApiModule) ReceiveCommitsExecutorModule(com.google.gerrit.server.git.ReceiveCommitsExecutorModule) ElasticIndexModule(com.google.gerrit.elasticsearch.ElasticIndexModule) IndexModule(com.google.gerrit.server.index.IndexModule) StaticModule(com.google.gerrit.httpd.raw.StaticModule) RestCacheAdminModule(com.google.gerrit.server.config.RestCacheAdminModule) IndexCommandsModule(com.google.gerrit.sshd.commands.IndexCommandsModule) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) GpgModule(com.google.gerrit.gpg.GpgModule) OpenIdModule(com.google.gerrit.httpd.auth.openid.OpenIdModule) SshHostKeyModule(com.google.gerrit.sshd.SshHostKeyModule) AbstractModule(com.google.inject.AbstractModule)

Example 4 with SchemaModule

use of com.google.gerrit.server.schema.SchemaModule 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));
    }
}
Also used : Message(com.google.inject.spi.Message) SQLException(java.sql.SQLException) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GerritServerConfigModule.getSecureStoreClassName(com.google.gerrit.server.config.GerritServerConfigModule.getSecureStoreClassName) SecureStoreClassName(com.google.gerrit.server.securestore.SecureStoreClassName) ArrayList(java.util.ArrayList) DatabaseModule(com.google.gerrit.server.schema.DatabaseModule) LifecycleListener(com.google.gerrit.extensions.events.LifecycleListener) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) ProvisionException(com.google.inject.ProvisionException) OrmException(com.google.gwtorm.server.OrmException) Injector(com.google.inject.Injector) DataSourceType(com.google.gerrit.server.schema.DataSourceType) DropWizardMetricMaker(com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) Path(java.nio.file.Path) SitePath(com.google.gerrit.server.config.SitePath) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SchemaModule(com.google.gerrit.server.schema.SchemaModule) DataSourceProvider(com.google.gerrit.server.schema.DataSourceProvider) CreationException(com.google.inject.CreationException) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) AbstractModule(com.google.inject.AbstractModule) ConfigNotesMigration(com.google.gerrit.server.notedb.ConfigNotesMigration) SitePath(com.google.gerrit.server.config.SitePath) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) Module(com.google.inject.Module) DataSourceModule(com.google.gerrit.server.schema.DataSourceModule) DatabaseModule(com.google.gerrit.server.schema.DatabaseModule) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) AbstractModule(com.google.inject.AbstractModule) DataSourceModule(com.google.gerrit.server.schema.DataSourceModule)

Example 5 with SchemaModule

use of com.google.gerrit.server.schema.SchemaModule in project gerrit by GerritCodeReview.

the class WebAppInitializer method createDbInjector.

private Injector createDbInjector() {
    final List<Module> modules = new ArrayList<>();
    modules.add(new SchemaModule());
    modules.add(NoteDbSchemaVersionCheck.module());
    modules.add(new AuthConfigModule());
    return cfgInjector.createChildInjector(ModuleOverloader.override(modules, LibModuleLoader.loadModules(cfgInjector, LibModuleType.DB_MODULE_TYPE)));
}
Also used : SchemaModule(com.google.gerrit.server.schema.SchemaModule) AuthConfigModule(com.google.gerrit.server.config.AuthConfigModule) ArrayList(java.util.ArrayList) SubscriptionGraphModule(com.google.gerrit.server.submit.SubscriptionGraph.SubscriptionGraphModule) H2CacheModule(com.google.gerrit.server.cache.h2.H2CacheModule) PluginApiModule(com.google.gerrit.server.api.PluginApiModule) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) OAuthModule(com.google.gerrit.httpd.auth.oauth.OAuthModule) InternalAccountDirectoryModule(com.google.gerrit.server.account.InternalAccountDirectory.InternalAccountDirectoryModule) WorkQueueModule(com.google.gerrit.server.git.WorkQueue.WorkQueueModule) SshModule(com.google.gerrit.sshd.SshModule) DefaultPermissionBackendModule(com.google.gerrit.server.permissions.DefaultPermissionBackendModule) ChangeCleanupRunnerModule(com.google.gerrit.server.change.ChangeCleanupRunner.ChangeCleanupRunnerModule) SshAddressesModule(com.google.gerrit.server.ssh.SshAddressesModule) DefaultMemoryCacheModule(com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule) HttpPluginModule(com.google.gerrit.httpd.plugins.HttpPluginModule) DefaultCommandModule(com.google.gerrit.sshd.commands.DefaultCommandModule) WebModule(com.google.gerrit.httpd.WebModule) SmtpEmailSenderModule(com.google.gerrit.server.mail.send.SmtpEmailSender.SmtpEmailSenderModule) StreamEventsApiListenerModule(com.google.gerrit.server.events.StreamEventsApiListener.StreamEventsApiListenerModule) PluginModule(com.google.gerrit.server.plugins.PluginModule) IndexModule(com.google.gerrit.server.index.IndexModule) StaticModule(com.google.gerrit.httpd.raw.StaticModule) AccountDeactivatorModule(com.google.gerrit.server.account.AccountDeactivator.AccountDeactivatorModule) HttpdModule(com.google.gerrit.httpd.HttpdModule) LocalMergeSuperSetComputationModule(com.google.gerrit.server.submit.LocalMergeSuperSetComputation.LocalMergeSuperSetComputationModule) JdbcAccountPatchReviewStoreModule(com.google.gerrit.server.schema.JdbcAccountPatchReviewStore.JdbcAccountPatchReviewStoreModule) SearchingChangeCacheImplModule(com.google.gerrit.server.git.SearchingChangeCacheImpl.SearchingChangeCacheImplModule) GpgModule(com.google.gerrit.gpg.GpgModule) OpenIdModule(com.google.gerrit.httpd.auth.openid.OpenIdModule) AuthModule(com.google.gerrit.auth.AuthModule) SshHostKeyModule(com.google.gerrit.sshd.SshHostKeyModule) DefaultProjectNameLockManagerModule(com.google.gerrit.server.project.DefaultProjectNameLockManager.DefaultProjectNameLockManagerModule) OAuthRestModule(com.google.gerrit.httpd.auth.restapi.OAuthRestModule) SignedTokenEmailTokenVerifierModule(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier.SignedTokenEmailTokenVerifierModule) AbstractModule(com.google.inject.AbstractModule) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) AuthConfigModule(com.google.gerrit.server.config.AuthConfigModule) SequenceCommandsModule(com.google.gerrit.sshd.commands.SequenceCommandsModule) Module(com.google.inject.Module) DefaultUrlFormatterModule(com.google.gerrit.server.config.DefaultUrlFormatter.DefaultUrlFormatterModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) LfsPluginAuthCommandModule(com.google.gerrit.sshd.plugin.LfsPluginAuthCommand.LfsPluginAuthCommandModule) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) MimeUtil2Module(com.google.gerrit.server.mime.MimeUtil2Module) SysExecutorModule(com.google.gerrit.server.config.SysExecutorModule) GarbageCollectionModule(com.google.gerrit.server.git.GarbageCollectionModule) GerritAuthModule(com.google.gerrit.httpd.GerritAuthModule) WebSshGlueModule(com.google.gerrit.httpd.WebSshGlueModule) MailReceiverModule(com.google.gerrit.server.mail.receive.MailReceiver.MailReceiverModule) ExternalIdCommandsModule(com.google.gerrit.sshd.commands.ExternalIdCommandsModule) RequireSslFilterModule(com.google.gerrit.httpd.RequireSslFilter.RequireSslFilterModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) OnlineUpgraderModule(com.google.gerrit.server.index.OnlineUpgrader.OnlineUpgraderModule) AuditModule(com.google.gerrit.server.audit.AuditModule) GitOverHttpModule(com.google.gerrit.httpd.GitOverHttpModule) RestApiModule(com.google.gerrit.server.restapi.RestApiModule) LogFileCompressorModule(com.google.gerrit.pgm.util.LogFileCompressor.LogFileCompressorModule) SuperprojectUpdateSubmissionListenerModule(com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener.SuperprojectUpdateSubmissionListenerModule) IndexCommandsModule(com.google.gerrit.sshd.commands.IndexCommandsModule) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) EventBrokerModule(com.google.gerrit.server.events.EventBroker.EventBrokerModule) StartupChecksModule(com.google.gerrit.server.StartupChecks.StartupChecksModule) GerritApiModule(com.google.gerrit.server.api.GerritApiModule) GerritInstanceNameModule(com.google.gerrit.server.config.GerritInstanceNameModule)

Aggregations

SchemaModule (com.google.gerrit.server.schema.SchemaModule)6 GerritServerConfigModule (com.google.gerrit.server.config.GerritServerConfigModule)5 AbstractModule (com.google.inject.AbstractModule)5 Module (com.google.inject.Module)5 ArrayList (java.util.ArrayList)5 LifecycleModule (com.google.gerrit.lifecycle.LifecycleModule)4 SitePath (com.google.gerrit.server.config.SitePath)4 GitRepositoryManagerModule (com.google.gerrit.server.git.GitRepositoryManagerModule)4 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)3 GpgModule (com.google.gerrit.gpg.GpgModule)2 OAuthModule (com.google.gerrit.httpd.auth.oauth.OAuthModule)2 OpenIdModule (com.google.gerrit.httpd.auth.openid.OpenIdModule)2 HttpPluginModule (com.google.gerrit.httpd.plugins.HttpPluginModule)2 StaticModule (com.google.gerrit.httpd.raw.StaticModule)2 LuceneIndexModule (com.google.gerrit.lucene.LuceneIndexModule)2 AuthConfigModule (com.google.gerrit.server.config.AuthConfigModule)2 CanonicalWebUrlModule (com.google.gerrit.server.config.CanonicalWebUrlModule)2 GerritGlobalModule (com.google.gerrit.server.config.GerritGlobalModule)2 GarbageCollectionModule (com.google.gerrit.server.git.GarbageCollectionModule)2 IndexModule (com.google.gerrit.server.index.IndexModule)2