Search in sources :

Example 1 with ConfigExperimentFeaturesModule

use of com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule 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 ConfigExperimentFeaturesModule

use of com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule in project gerrit by GerritCodeReview.

the class InMemoryModule method configure.

@Override
protected void configure() {
    // Do NOT bind @RemotePeer, as it is bound in a child injector of
    // ChangeMergeQueue (bound via GerritGlobalModule below), so there cannot be
    // a binding in the parent injector. If you need @RemotePeer, you must bind
    // it in a child injector of the one containing InMemoryModule. But unless
    // you really need to test something request-scoped, you likely don't
    // actually need it.
    // For simplicity, don't create child injectors, just use this one to get a
    // few required modules.
    Injector cfgInjector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
        }
    });
    bind(GerritRuntime.class).toInstance(GerritRuntime.DAEMON);
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    install(cfgInjector.getInstance(GerritGlobalModule.class));
    AuthConfig authConfig = cfgInjector.getInstance(AuthConfig.class);
    install(new AuthModule(authConfig));
    install(new GerritApiModule());
    factory(PluginUser.Factory.class);
    install(new PluginApiModule());
    install(new DefaultPermissionBackendModule());
    install(new SearchingChangeCacheImplModule());
    factory(GarbageCollection.Factory.class);
    install(new AuditModule());
    install(new SubscriptionGraphModule());
    install(new SuperprojectUpdateSubmissionListenerModule());
    bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
    // It would be nice to use Jimfs for the SitePath, but the biggest blocker is that JGit does not
    // support Path-based Configs, only FileBasedConfig.
    bind(Path.class).annotatedWith(SitePath.class).toInstance(Paths.get("."));
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    bind(GerritOptions.class).toInstance(new GerritOptions(false, false));
    bind(AllProjectsConfigProvider.class).to(FileBasedAllProjectsConfigProvider.class);
    bind(GlobalPluginConfigProvider.class).to(FileBasedGlobalPluginConfigProvider.class);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    bind(SecureStore.class).to(DefaultSecureStore.class);
    install(new InMemorySchemaModule());
    install(NoSshKeyCache.module());
    install(new GerritInstanceNameModule());
    install(new GerritInstanceIdModule());
    install(new CanonicalWebUrlModule() {

        @Override
        protected Class<? extends Provider<String>> provider() {
            return CanonicalWebUrlProvider.class;
        }
    });
    install(new DefaultUrlFormatterModule());
    // Replacement of DiffExecutorModule to not use thread pool in the tests
    install(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @Singleton
        @DiffExecutor
        public ExecutorService createDiffExecutor() {
            return newDirectExecutorService();
        }
    });
    install(new DefaultMemoryCacheModule());
    install(new H2CacheModule());
    install(new FakeEmailSenderModule());
    install(new SignedTokenEmailTokenVerifierModule());
    install(new GpgModule(cfg));
    install(new LocalMergeSuperSetComputationModule());
    bind(AllAccountsIndexer.class).toProvider(Providers.of(null));
    bind(AllChangesIndexer.class).toProvider(Providers.of(null));
    bind(AllGroupsIndexer.class).toProvider(Providers.of(null));
    String indexTypeCfg = cfg.getString("index", null, "type");
    IndexType indexType = new IndexType(indexTypeCfg != null ? indexTypeCfg : "fake");
    // For custom index types, callers must provide their own module.
    if (indexType.isLucene()) {
        install(luceneIndexModule());
    } else if (indexType.isFake()) {
        install(fakeIndexModule());
    }
    bind(ServerInformationImpl.class);
    bind(ServerInformation.class).to(ServerInformationImpl.class);
    install(new RestApiModule());
    install(new OAuthRestModule());
    install(new DefaultProjectNameLockManagerModule());
    install(new FileInfoJsonModule());
    install(new ConfigExperimentFeaturesModule());
    bind(ProjectOperations.class).to(ProjectOperationsImpl.class);
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) RestApiModule(com.google.gerrit.server.restapi.RestApiModule) AuthConfig(com.google.gerrit.server.config.AuthConfig) DefaultProjectNameLockManagerModule(com.google.gerrit.server.project.DefaultProjectNameLockManager.DefaultProjectNameLockManagerModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) SearchingChangeCacheImplModule(com.google.gerrit.server.git.SearchingChangeCacheImpl.SearchingChangeCacheImplModule) GerritRuntime(com.google.gerrit.server.config.GerritRuntime) FakeEmailSenderModule(com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule) Injector(com.google.inject.Injector) SuperprojectUpdateSubmissionListenerModule(com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener.SuperprojectUpdateSubmissionListenerModule) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) DefaultPermissionBackendModule(com.google.gerrit.server.permissions.DefaultPermissionBackendModule) FileInfoJsonModule(com.google.gerrit.server.change.FileInfoJsonModule) GerritOptions(com.google.gerrit.server.config.GerritOptions) DefaultSecureStore(com.google.gerrit.server.securestore.DefaultSecureStore) SecureStore(com.google.gerrit.server.securestore.SecureStore) SignedTokenEmailTokenVerifierModule(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier.SignedTokenEmailTokenVerifierModule) Singleton(com.google.inject.Singleton) AuditModule(com.google.gerrit.server.audit.AuditModule) SitePath(com.google.gerrit.server.config.SitePath) DiffExecutor(com.google.gerrit.server.patch.DiffExecutor) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AuthConfig(com.google.gerrit.server.config.AuthConfig) FileBasedGlobalPluginConfigProvider(com.google.gerrit.server.config.FileBasedGlobalPluginConfigProvider) GlobalPluginConfigProvider(com.google.gerrit.server.config.GlobalPluginConfigProvider) LocalMergeSuperSetComputationModule(com.google.gerrit.server.submit.LocalMergeSuperSetComputation.LocalMergeSuperSetComputationModule) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AllChangesIndexer(com.google.gerrit.server.index.change.AllChangesIndexer) GarbageCollection(com.google.gerrit.server.git.GarbageCollection) AllAccountsIndexer(com.google.gerrit.server.index.account.AllAccountsIndexer) PluginApiModule(com.google.gerrit.server.api.PluginApiModule) GerritInstanceNameModule(com.google.gerrit.server.config.GerritInstanceNameModule) ServerInformation(com.google.gerrit.extensions.systemstatus.ServerInformation) OAuthRestModule(com.google.gerrit.httpd.auth.restapi.OAuthRestModule) GpgModule(com.google.gerrit.gpg.GpgModule) GerritApiModule(com.google.gerrit.server.api.GerritApiModule) IndexType(com.google.gerrit.index.IndexType) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Provides(com.google.inject.Provides) DefaultUrlFormatterModule(com.google.gerrit.server.config.DefaultUrlFormatter.DefaultUrlFormatterModule) AbstractModule(com.google.inject.AbstractModule) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) FileBasedGlobalPluginConfigProvider(com.google.gerrit.server.config.FileBasedGlobalPluginConfigProvider) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) CanonicalWebUrlProvider(com.google.gerrit.server.config.CanonicalWebUrlProvider) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) GlobalPluginConfigProvider(com.google.gerrit.server.config.GlobalPluginConfigProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) GerritServerIdProvider(com.google.gerrit.server.config.GerritServerIdProvider) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Provider(com.google.inject.Provider) DefaultMemoryCacheModule(com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule) H2CacheModule(com.google.gerrit.server.cache.h2.H2CacheModule) AllGroupsIndexer(com.google.gerrit.server.index.group.AllGroupsIndexer) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AuthModule(com.google.gerrit.auth.AuthModule) GerritInstanceIdModule(com.google.gerrit.server.config.GerritInstanceIdModule) SubscriptionGraphModule(com.google.gerrit.server.submit.SubscriptionGraph.SubscriptionGraphModule) PluginUser(com.google.gerrit.server.PluginUser)

Example 3 with ConfigExperimentFeaturesModule

use of com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule in project gerrit by GerritCodeReview.

the class GerritServer method startInMemory.

private static GerritServer startInMemory(Description desc, Path site, Config baseConfig, Daemon daemon, @Nullable InMemoryRepositoryManager inMemoryRepoManager) throws Exception {
    Config cfg = desc.buildConfig(baseConfig);
    daemon.setReplica(ReplicaUtil.isReplica(baseConfig) || ReplicaUtil.isReplica(cfg));
    mergeTestConfig(cfg);
    // Set the log4j configuration to an invalid one to prevent system logs
    // from getting configured and creating log files.
    System.setProperty(SystemLog.LOG4J_CONFIGURATION, "invalidConfiguration");
    cfg.setBoolean("httpd", null, "requestLog", false);
    cfg.setBoolean("sshd", null, "requestLog", false);
    cfg.setBoolean("index", "lucene", "testInmemory", true);
    cfg.setBoolean("index", null, "onlineUpgrade", false);
    cfg.setString("gitweb", null, "cgi", "");
    cfg.setString("accountPatchReviewDb", null, "url", JdbcAccountPatchReviewStore.TEST_IN_MEMORY_URL);
    String configuredIndexBackend = cfg.getString("index", null, "type");
    IndexType indexType;
    if (configuredIndexBackend != null) {
        // Explicitly configured index backend from gerrit.config trumps any other ways to configure
        // index backends so that Reindex tests can be explicit about the backend they want to test
        // against.
        indexType = new IndexType(configuredIndexBackend);
    } else {
        // Allow configuring the index backend based on sys/env variables so that integration tests
        // can be run against different index backends.
        indexType = IndexType.fromEnvironment().orElse(new IndexType("fake"));
    }
    if (indexType.isLucene()) {
        daemon.setIndexModule(LuceneIndexModule.singleVersionAllLatest(0, ReplicaUtil.isReplica(baseConfig), AutoFlush.ENABLED));
    } else {
        daemon.setIndexModule(FakeIndexModule.latestVersion(false));
    }
    daemon.setEnableHttpd(desc.httpd());
    daemon.setInMemory(true);
    daemon.setDatabaseForTesting(ImmutableList.of(new InMemoryTestingDatabaseModule(cfg, site, inMemoryRepoManager), new AbstractModule() {

        @Override
        protected void configure() {
            bind(GerritRuntime.class).toInstance(GerritRuntime.DAEMON);
        }
    }, new ConfigExperimentFeaturesModule()));
    daemon.addAdditionalSysModuleForTesting(new ReindexProjectsAtStartupModule(), new ReindexGroupsAtStartupModule());
    daemon.start();
    return new GerritServer(desc, null, createTestInjector(daemon), daemon, null);
}
Also used : GerritRuntime(com.google.gerrit.server.config.GerritRuntime) ReindexProjectsAtStartupModule(com.google.gerrit.acceptance.ReindexProjectsAtStartup.ReindexProjectsAtStartupModule) Config(org.eclipse.jgit.lib.Config) GlobalPluginConfig(com.google.gerrit.acceptance.config.GlobalPluginConfig) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) ReindexGroupsAtStartupModule(com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule) IndexType(com.google.gerrit.index.IndexType) AbstractModule(com.google.inject.AbstractModule)

Aggregations

ConfigExperimentFeaturesModule (com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule)3 AbstractModule (com.google.inject.AbstractModule)3 IndexType (com.google.gerrit.index.IndexType)2 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)2 GerritRuntime (com.google.gerrit.server.config.GerritRuntime)2 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)2 SitePath (com.google.gerrit.server.config.SitePath)2 Injector (com.google.inject.Injector)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors.newDirectExecutorService (com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService)1 ReindexGroupsAtStartupModule (com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule)1 ReindexProjectsAtStartupModule (com.google.gerrit.acceptance.ReindexProjectsAtStartup.ReindexProjectsAtStartupModule)1 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 GlobalPluginConfig (com.google.gerrit.acceptance.config.GlobalPluginConfig)1 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)1 AuthModule (com.google.gerrit.auth.AuthModule)1 ServerInformation (com.google.gerrit.extensions.systemstatus.ServerInformation)1 GpgModule (com.google.gerrit.gpg.GpgModule)1 OAuthRestModule (com.google.gerrit.httpd.auth.restapi.OAuthRestModule)1 LifecycleModule (com.google.gerrit.lifecycle.LifecycleModule)1