Search in sources :

Example 1 with AllUsersName

use of com.google.gerrit.server.config.AllUsersName 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 2 with AllUsersName

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

the class Schema_147 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    try (Repository repo = repoManager.openRepository(allUsersName)) {
        Set<Account.Id> accountIdsFromReviewDb = db.accounts().all().toList().stream().map(a -> a.getId()).collect(toSet());
        Set<Account.Id> accountIdsFromUserBranches = repo.getRefDatabase().getRefs(RefNames.REFS_USERS).values().stream().map(r -> Account.Id.fromRef(r.getName())).filter(Objects::nonNull).collect(toSet());
        accountIdsFromUserBranches.removeAll(accountIdsFromReviewDb);
        for (Account.Id accountId : accountIdsFromUserBranches) {
            AccountsUpdate.deleteUserBranch(repo, serverIdent, accountId);
        }
    } catch (IOException e) {
        throw new OrmException("Failed to delete user branches for non-existing accounts.", e);
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) OrmException(com.google.gwtorm.server.OrmException) Inject(com.google.inject.Inject) Set(java.util.Set) IOException(java.io.IOException) Objects(java.util.Objects) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Provider(com.google.inject.Provider) SQLException(java.sql.SQLException) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) RefNames(com.google.gerrit.reviewdb.client.RefNames) Account(com.google.gerrit.reviewdb.client.Account) Collectors.toSet(java.util.stream.Collectors.toSet) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) Repository(org.eclipse.jgit.lib.Repository) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) Account(com.google.gerrit.reviewdb.client.Account) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) IOException(java.io.IOException)

Aggregations

ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)2 OrmException (com.google.gwtorm.server.OrmException)2 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)1 Account (com.google.gerrit.reviewdb.client.Account)1 RefNames (com.google.gerrit.reviewdb.client.RefNames)1 SystemConfig (com.google.gerrit.reviewdb.client.SystemConfig)1 AccountsUpdate (com.google.gerrit.server.account.AccountsUpdate)1 AllProjectsName (com.google.gerrit.server.config.AllProjectsName)1 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)1 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1 SitePaths (com.google.gerrit.server.config.SitePaths)1 ConfigNotesMigration (com.google.gerrit.server.notedb.ConfigNotesMigration)1 InMemoryRepositoryManager (com.google.gerrit.testutil.InMemoryRepositoryManager)1 SchemaFactory (com.google.gwtorm.server.SchemaFactory)1 StatementExecutor (com.google.gwtorm.server.StatementExecutor)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1