Search in sources :

Example 31 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class SchemaVersionCheck method start.

@Override
public void start() {
    try (ReviewDb db = schema.open()) {
        final CurrentSchemaVersion currentVer = getSchemaVersion(db);
        final int expectedVer = SchemaVersion.getBinaryVersion();
        if (currentVer == null) {
            throw new ProvisionException("Schema not yet initialized." + "  Run init to initialize the schema:\n" + "$ java -jar gerrit.war init -d " + site.site_path.toAbsolutePath());
        }
        if (currentVer.versionNbr < expectedVer) {
            throw new ProvisionException("Unsupported schema version " + currentVer.versionNbr + "; expected schema version " + expectedVer + ".  Run init to upgrade:\n" + "$ java -jar " + site.gerrit_war.toAbsolutePath() + " init -d " + site.site_path.toAbsolutePath());
        } else if (currentVer.versionNbr > expectedVer) {
            throw new ProvisionException("Unsupported schema version " + currentVer.versionNbr + "; expected schema version " + expectedVer + ". Downgrade is not supported.");
        }
    } catch (OrmException e) {
        throw new ProvisionException("Cannot read schema_version", e);
    }
}
Also used : CurrentSchemaVersion(com.google.gerrit.reviewdb.client.CurrentSchemaVersion) ProvisionException(com.google.inject.ProvisionException) OrmException(com.google.gwtorm.server.OrmException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 32 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class InMemoryTestingDatabaseModule method configure.

@Override
protected void configure() {
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    // TODO(dborowitz): Use jimfs.
    Path p = Paths.get(cfg.getString("gerrit", null, "tempSiteDir"));
    bind(Path.class).annotatedWith(SitePath.class).toInstance(p);
    makeSiteDirs(p);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    bind(DataSourceType.class).to(InMemoryH2Type.class);
    bind(NotesMigration.class).to(TestNotesMigration.class);
    TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
    };
    bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
    bind(Key.get(schemaFactory, ReviewDbFactory.class)).to(InMemoryDatabase.class);
    bind(InMemoryDatabase.class).in(SINGLETON);
    bind(ChangeBundleReader.class).to(GwtormChangeBundleReader.class);
    listener().to(CreateDatabase.class);
    bind(SitePaths.class);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    install(new SchemaModule());
    bind(SchemaVersion.class).to(SchemaVersion.C);
}
Also used : Path(java.nio.file.Path) SitePath(com.google.gerrit.server.config.SitePath) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) MetricMaker(com.google.gerrit.metrics.MetricMaker) NotesMigrationSchemaFactory(com.google.gerrit.server.schema.NotesMigrationSchemaFactory) SchemaFactory(com.google.gwtorm.server.SchemaFactory) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SchemaModule(com.google.gerrit.server.schema.SchemaModule) SchemaVersion(com.google.gerrit.server.schema.SchemaVersion) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) InMemoryDatabase(com.google.gerrit.testutil.InMemoryDatabase) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) TestNotesMigration(com.google.gerrit.testutil.TestNotesMigration) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) GwtormChangeBundleReader(com.google.gerrit.server.notedb.GwtormChangeBundleReader) ChangeBundleReader(com.google.gerrit.server.notedb.ChangeBundleReader) TypeLiteral(com.google.inject.TypeLiteral) DataSourceType(com.google.gerrit.server.schema.DataSourceType) SitePath(com.google.gerrit.server.config.SitePath) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 33 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class AcceptanceTestRequestScope method disableDb.

public Context disableDb() {
    Context old = current.get();
    SchemaFactory<ReviewDb> sf = new SchemaFactory<ReviewDb>() {

        @Override
        public ReviewDb open() {
            return new DisabledReviewDb();
        }
    };
    Context ctx = new Context(sf, old.session, old.user, old.created);
    current.set(ctx);
    local.setContext(ctx);
    return old;
}
Also used : RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) SchemaFactory(com.google.gwtorm.server.SchemaFactory) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb)

Example 34 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class AccountCreator method create.

public synchronized TestAccount create(@Nullable String username, @Nullable String email, @Nullable String fullName, String... groups) throws Exception {
    TestAccount account = accounts.get(username);
    if (account != null) {
        return account;
    }
    try (ReviewDb db = reviewDbProvider.open()) {
        Account.Id id = new Account.Id(db.nextAccountId());
        List<ExternalId> extIds = new ArrayList<>(2);
        String httpPass = null;
        if (username != null) {
            httpPass = "http-pass";
            extIds.add(ExternalId.createUsername(username, id, httpPass));
        }
        if (email != null) {
            extIds.add(ExternalId.createEmail(id, email));
        }
        externalIdsUpdate.create().insert(extIds);
        Account a = new Account(id, TimeUtil.nowTs());
        a.setFullName(fullName);
        a.setPreferredEmail(email);
        accountsUpdate.create().insert(db, a);
        if (groups != null) {
            for (String n : groups) {
                AccountGroup.NameKey k = new AccountGroup.NameKey(n);
                AccountGroup g = groupCache.get(k);
                checkArgument(g != null, "group not found: %s", n);
                AccountGroupMember m = new AccountGroupMember(new AccountGroupMember.Key(id, g.getId()));
                db.accountGroupMembers().insert(Collections.singleton(m));
            }
        }
        KeyPair sshKey = null;
        if (SshMode.useSsh() && username != null) {
            sshKey = genSshKey();
            authorizedKeys.addKey(id, publicKey(sshKey, email));
            sshKeyCache.evict(username);
        }
        if (username != null) {
            accountCache.evictByUsername(username);
        }
        byEmailCache.evict(email);
        indexer.index(id);
        account = new TestAccount(id, username, email, fullName, sshKey, httpPass);
        if (username != null) {
            accounts.put(username, account);
        }
        return account;
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) KeyPair(com.jcraft.jsch.KeyPair) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ArrayList(java.util.ArrayList) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 35 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method setInvalidNoteDbState.

private void setInvalidNoteDbState(Change.Id id) throws Exception {
    ReviewDb db = getUnwrappedDb();
    Change c = db.changes().get(id);
    // In reality we would have NoteDb writes enabled, which would write a real
    // state into this field. For tests however, we turn NoteDb writes off, so
    // just use a dummy state to force ChangeNotes to view the notes as
    // out-of-date.
    c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
    db.changes().update(Collections.singleton(c));
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Aggregations

ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)63 OrmException (com.google.gwtorm.server.OrmException)25 Change (com.google.gerrit.reviewdb.client.Change)21 Account (com.google.gerrit.reviewdb.client.Account)17 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)12 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)10 Repository (org.eclipse.jgit.lib.Repository)9 Project (com.google.gerrit.reviewdb.client.Project)8 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)8 Provider (com.google.inject.Provider)8 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 Inject (com.google.inject.Inject)7 AllUsersName (com.google.gerrit.server.config.AllUsersName)6 ChangeControl (com.google.gerrit.server.project.ChangeControl)6 PersonIdent (org.eclipse.jgit.lib.PersonIdent)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)5 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)5 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)5