Search in sources :

Example 1 with IndexType

use of com.google.gerrit.index.IndexType in project gerrit by GerritCodeReview.

the class Reindex method createSysInjector.

private Injector createSysInjector() {
    Map<String, Integer> versions = new HashMap<>();
    if (changesVersion != null) {
        versions.put(ChangeSchemaDefinitions.INSTANCE.getName(), changesVersion);
    }
    boolean replica = ReplicaUtil.isReplica(globalConfig);
    List<Module> modules = new ArrayList<>();
    Module indexModule;
    IndexType indexType = IndexModule.getIndexType(dbInjector);
    if (indexType.isLucene()) {
        indexModule = LuceneIndexModule.singleVersionWithExplicitVersions(versions, threads, replica, AutoFlush.DISABLED);
    } else if (indexType.isFake()) {
        // compile the component in.
        try {
            Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModule");
            Method m = clazz.getMethod("singleVersionWithExplicitVersions", Map.class, int.class, boolean.class);
            indexModule = (Module) m.invoke(null, versions, threads, replica);
        } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | InvocationTargetException e) {
            throw new IllegalStateException("can't create index", e);
        }
    } else {
        throw new IllegalStateException("unsupported index.type = " + indexType);
    }
    modules.add(indexModule);
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            super.configure();
            OptionalBinder.newOptionalBinder(binder(), IsFirstInsertForEntry.class).setBinding().toInstance(IsFirstInsertForEntry.YES);
        }
    });
    modules.add(new BatchProgramModule(dbInjector));
    modules.add(new FactoryModule() {

        @Override
        protected void configure() {
            factory(ChangeResource.Factory.class);
        }
    });
    return dbInjector.createChildInjector(ModuleOverloader.override(modules, LibModuleLoader.loadReindexModules(cfgInjector, versions, threads, replica)));
}
Also used : HashMap(java.util.HashMap) IsFirstInsertForEntry(com.google.gerrit.server.index.options.IsFirstInsertForEntry) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) BatchProgramModule(com.google.gerrit.pgm.util.BatchProgramModule) Module(com.google.inject.Module) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) IndexModule(com.google.gerrit.server.index.IndexModule) BatchProgramModule(com.google.gerrit.pgm.util.BatchProgramModule) AbstractModule(com.google.inject.AbstractModule) IndexType(com.google.gerrit.index.IndexType) Map(java.util.Map) HashMap(java.util.HashMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap)

Example 2 with IndexType

use of com.google.gerrit.index.IndexType in project gerrit by GerritCodeReview.

the class InitIndex method run.

@Override
public void run() throws IOException {
    ui.header("Index");
    IndexType type = new IndexType(index.select("Type", "type", IndexType.getDefault(), IndexType.getKnownTypes()));
    if ((site.isNew || isEmptySite()) && type.isLucene()) {
        for (SchemaDefinitions<?> def : IndexModule.ALL_SCHEMA_DEFS) {
            IndexUtils.setReady(site, def.getName(), def.getLatest().getVersion(), true);
        }
    } else {
        String message = String.format("\nThe index must be %sbuilt before starting Gerrit:\n" + "  java -jar gerrit.war reindex -d site_path\n", site.isNew ? "" : "re");
        ui.message(message);
        initFlags.autoStart = false;
    }
}
Also used : IndexType(com.google.gerrit.index.IndexType)

Example 3 with IndexType

use of com.google.gerrit.index.IndexType 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 4 with IndexType

use of com.google.gerrit.index.IndexType 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)

Example 5 with IndexType

use of com.google.gerrit.index.IndexType in project gerrit by GerritCodeReview.

the class GerritServer method init.

/**
 * Initializes on-disk site but does not start server.
 *
 * @param desc server description
 * @param baseConfig default config values; merged with config from {@code desc} and then written
 *     into {@code site/etc/gerrit.config}.
 * @param site temp directory where site will live.
 */
public static void init(Description desc, Config baseConfig, Path site) throws Exception {
    checkArgument(!desc.memory(), "can't initialize site path for in-memory test: %s", desc);
    Config cfg = desc.buildConfig(baseConfig);
    Map<String, Config> pluginConfigs = desc.buildPluginConfigs();
    MergeableFileBasedConfig gerritConfig = new MergeableFileBasedConfig(site.resolve("etc").resolve("gerrit.config").toFile(), FS.DETECTED);
    gerritConfig.load();
    gerritConfig.merge(cfg);
    mergeTestConfig(gerritConfig);
    String configuredIndexBackend = cfg.getString("index", null, "type");
    if (configuredIndexBackend == null) {
        // Propagate index type to pgms that run off of the gerrit.config file on local disk.
        IndexType indexType = IndexType.fromEnvironment().orElse(new IndexType("fake"));
        gerritConfig.setString("index", null, "type", indexType.isLucene() ? "lucene" : "fake");
    }
    gerritConfig.save();
    Init init = new Init();
    int rc = init.main(new String[] { "-d", site.toString(), "--batch", "--no-auto-start", "--skip-plugins" });
    if (rc != 0) {
        throw new RuntimeException("Couldn't initialize site");
    }
    for (String pluginName : pluginConfigs.keySet()) {
        MergeableFileBasedConfig pluginCfg = new MergeableFileBasedConfig(site.resolve("etc").resolve(pluginName + ".config").toFile(), FS.DETECTED);
        pluginCfg.load();
        pluginCfg.merge(pluginConfigs.get(pluginName));
        pluginCfg.save();
    }
}
Also used : Init(com.google.gerrit.pgm.Init) 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) IndexType(com.google.gerrit.index.IndexType)

Aggregations

IndexType (com.google.gerrit.index.IndexType)7 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)4 AbstractModule (com.google.inject.AbstractModule)4 Config (org.eclipse.jgit.lib.Config)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)2 GlobalPluginConfig (com.google.gerrit.acceptance.config.GlobalPluginConfig)2 GerritRuntime (com.google.gerrit.server.config.GerritRuntime)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 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)1 AuthModule (com.google.gerrit.auth.AuthModule)1 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)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 LuceneIndexModule (com.google.gerrit.lucene.LuceneIndexModule)1 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)1