Search in sources :

Example 1 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class RefControlTest method add.

private InMemoryRepository add(ProjectConfig pc) {
    PrologEnvironment.Factory envFactory = null;
    ProjectControl.AssistedFactory projectControlFactory = null;
    RulesCache rulesCache = null;
    SitePaths sitePaths = null;
    List<CommentLinkInfo> commentLinks = null;
    InMemoryRepository repo;
    try {
        repo = repoManager.createRepository(pc.getName());
        if (pc.getProject() == null) {
            pc.load(repo);
        }
    } catch (IOException | ConfigInvalidException e) {
        throw new RuntimeException(e);
    }
    all.put(pc.getName(), new ProjectState(sitePaths, projectCache, allProjectsName, allUsersName, projectControlFactory, envFactory, repoManager, rulesCache, commentLinks, capabilityCollectionFactory, pc));
    return repo;
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SitePaths(com.google.gerrit.server.config.SitePaths) IOException(java.io.IOException) PrologEnvironment(com.google.gerrit.rules.PrologEnvironment) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) RulesCache(com.google.gerrit.rules.RulesCache)

Example 2 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class MigrateAccountPatchReviewDb method run.

@Override
public int run() throws Exception {
    SitePaths sitePaths = new SitePaths(getSitePath());
    Config fakeCfg = new Config();
    if (!Strings.isNullOrEmpty(sourceUrl)) {
        fakeCfg.setString("accountPatchReviewDb", null, "url", sourceUrl);
    }
    JdbcAccountPatchReviewStore sourceJdbcAccountPatchReviewStore = JdbcAccountPatchReviewStore.createAccountPatchReviewStore(fakeCfg, sitePaths);
    Injector dbInjector = createDbInjector(DataSourceProvider.Context.SINGLE_USER);
    Config cfg = dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
    String targetUrl = cfg.getString("accountPatchReviewDb", null, "url");
    if (targetUrl == null) {
        System.err.println("accountPatchReviewDb.url is null in gerrit.config");
        return 1;
    }
    System.out.println("target Url: " + targetUrl);
    JdbcAccountPatchReviewStore targetJdbcAccountPatchReviewStore = JdbcAccountPatchReviewStore.createAccountPatchReviewStore(cfg, sitePaths);
    targetJdbcAccountPatchReviewStore.createTableIfNotExists();
    if (!isTargetTableEmpty(targetJdbcAccountPatchReviewStore)) {
        System.err.println("target table is not empty, cannot proceed");
        return 1;
    }
    try (Connection sourceCon = sourceJdbcAccountPatchReviewStore.getConnection();
        Connection targetCon = targetJdbcAccountPatchReviewStore.getConnection();
        PreparedStatement sourceStmt = sourceCon.prepareStatement("SELECT account_id, change_id, patch_set_id, file_name " + "FROM account_patch_reviews " + "LIMIT ? " + "OFFSET ?");
        PreparedStatement targetStmt = targetCon.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
        targetCon.setAutoCommit(false);
        long offset = 0;
        List<Row> rows = selectRows(sourceStmt, offset);
        while (!rows.isEmpty()) {
            insertRows(targetCon, targetStmt, rows);
            offset += rows.size();
            rows = selectRows(sourceStmt, offset);
        }
    }
    return 0;
}
Also used : GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) JdbcAccountPatchReviewStore(com.google.gerrit.server.schema.JdbcAccountPatchReviewStore) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Config(org.eclipse.jgit.lib.Config) Injector(com.google.inject.Injector) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SitePaths(com.google.gerrit.server.config.SitePaths)

Example 3 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class SwitchSecureStore method run.

@Override
public int run() throws Exception {
    SitePaths sitePaths = new SitePaths(getSitePath());
    Path newSecureStorePath = Paths.get(newSecureStoreLib);
    if (!Files.exists(newSecureStorePath)) {
        log.error(String.format("File %s doesn't exist", newSecureStorePath.toAbsolutePath()));
        return -1;
    }
    String newSecureStore = getNewSecureStoreClassName(newSecureStorePath);
    String currentSecureStoreName = getCurrentSecureStoreClassName(sitePaths);
    if (currentSecureStoreName.equals(newSecureStore)) {
        log.error("Old and new SecureStore implementation names " + "are the same. Migration will not work");
        return -1;
    }
    IoUtil.loadJARs(newSecureStorePath);
    SiteLibraryLoaderUtil.loadSiteLib(sitePaths.lib_dir);
    log.info("Current secureStoreClass property ({}) will be replaced with {}", currentSecureStoreName, newSecureStore);
    Injector dbInjector = createDbInjector(SINGLE_USER);
    SecureStore currentStore = getSecureStore(currentSecureStoreName, dbInjector);
    SecureStore newStore = getSecureStore(newSecureStore, dbInjector);
    migrateProperties(currentStore, newStore);
    removeOldLib(sitePaths, currentSecureStoreName);
    copyNewLib(sitePaths, newSecureStorePath);
    updateGerritConfig(sitePaths, newSecureStore);
    return 0;
}
Also used : Path(java.nio.file.Path) Injector(com.google.inject.Injector) SitePaths(com.google.gerrit.server.config.SitePaths) SecureStore(com.google.gerrit.server.securestore.SecureStore) DefaultSecureStore(com.google.gerrit.server.securestore.DefaultSecureStore)

Example 4 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class SchemaUpdaterTest method update.

@Test
public void update() throws OrmException, FileNotFoundException, IOException {
    db.create();
    final Path site = Paths.get(UUID.randomUUID().toString());
    final SitePaths paths = new SitePaths(site);
    SchemaUpdater u = Guice.createInjector(new FactoryModule() {

        @Override
        protected void configure() {
            TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
            };
            bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
            bind(Key.get(schemaFactory, ReviewDbFactory.class)).toInstance(db);
            bind(SitePaths.class).toInstance(paths);
            Config cfg = new Config();
            cfg.setString("user", null, "name", "Gerrit Code Review");
            cfg.setString("user", null, "email", "gerrit@localhost");
            //
            bind(Config.class).annotatedWith(//
            GerritServerConfig.class).toInstance(cfg);
            //
            bind(PersonIdent.class).annotatedWith(//
            GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
            bind(AllProjectsName.class).toInstance(new AllProjectsName("All-Projects"));
            bind(AllUsersName.class).toInstance(new AllUsersName("All-Users"));
            bind(GitRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
            //
            bind(String.class).annotatedWith(//
            AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
            bind(DataSourceType.class).to(InMemoryH2Type.class);
            bind(SystemGroupBackend.class);
            install(new ConfigNotesMigration.Module());
        }
    }).getInstance(SchemaUpdater.class);
    for (SchemaVersion s = u.getLatestSchemaVersion(); s.getVersionNbr() > 1; s = s.getPrior()) {
        try {
            assertThat(s.getPrior().getVersionNbr()).named("schema %s has prior version %s. Not true that", s.getVersionNbr(), s.getPrior().getVersionNbr()).isEqualTo(s.getVersionNbr() - 1);
        } catch (ProvisionException e) {
            // version.
            break;
        }
    }
    u.update(new UpdateUI() {

        @Override
        public void message(String msg) {
        }

        @Override
        public boolean yesno(boolean def, String msg) {
            return def;
        }

        @Override
        public boolean isBatch() {
            return true;
        }

        @Override
        public void pruneSchema(StatementExecutor e, List<String> pruneList) throws OrmException {
            for (String sql : pruneList) {
                e.execute(sql);
            }
        }
    });
    db.assertSchemaVersion();
    final SystemConfig sc = db.getSystemConfig();
    assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
}
Also used : SystemConfig(com.google.gerrit.reviewdb.client.SystemConfig) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) SystemConfig(com.google.gerrit.reviewdb.client.SystemConfig) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SitePaths(com.google.gerrit.server.config.SitePaths) StatementExecutor(com.google.gwtorm.server.StatementExecutor) ProvisionException(com.google.inject.ProvisionException) TypeLiteral(com.google.inject.TypeLiteral) OrmException(com.google.gwtorm.server.OrmException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) Path(java.nio.file.Path) SchemaFactory(com.google.gwtorm.server.SchemaFactory) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ConfigNotesMigration(com.google.gerrit.server.notedb.ConfigNotesMigration) AllUsersName(com.google.gerrit.server.config.AllUsersName) Test(org.junit.Test)

Example 5 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class LocalDiskRepositoryManagerTest method setUp.

@Before
public void setUp() throws Exception {
    site = new SitePaths(TempFileUtil.createTempDirectory().toPath());
    site.resolve("git").toFile().mkdir();
    cfg = new Config();
    cfg.setString("gerrit", null, "basePath", "git");
    repoManager = new LocalDiskRepositoryManager(site, cfg);
}
Also used : Config(org.eclipse.jgit.lib.Config) SitePaths(com.google.gerrit.server.config.SitePaths) Before(org.junit.Before)

Aggregations

SitePaths (com.google.gerrit.server.config.SitePaths)8 Config (org.eclipse.jgit.lib.Config)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 ConsoleUI (com.google.gerrit.pgm.init.api.ConsoleUI)2 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)2 Injector (com.google.inject.Injector)2 Before (org.junit.Before)2 CommentLinkInfo (com.google.gerrit.extensions.api.projects.CommentLinkInfo)1 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)1 InitFlags (com.google.gerrit.pgm.init.api.InitFlags)1 Section (com.google.gerrit.pgm.init.api.Section)1 SystemConfig (com.google.gerrit.reviewdb.client.SystemConfig)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 PrologEnvironment (com.google.gerrit.rules.PrologEnvironment)1 RulesCache (com.google.gerrit.rules.RulesCache)1 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)1 AllProjectsName (com.google.gerrit.server.config.AllProjectsName)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)1