Search in sources :

Example 6 with OrmRuntimeException

use of com.google.gwtorm.server.OrmRuntimeException in project gerrit by GerritCodeReview.

the class PrimaryStorageMigrator method setReadOnlyInReviewDb.

private Change setReadOnlyInReviewDb(Change.Id id) throws OrmException {
    AtomicBoolean alreadyMigrated = new AtomicBoolean(false);
    Change result = db().changes().atomicUpdate(id, new AtomicUpdate<Change>() {

        @Override
        public Change update(Change change) {
            NoteDbChangeState state = NoteDbChangeState.parse(change);
            if (state == null) {
                // really shouldn't happen.
                throw new OrmRuntimeException("change " + id + " has no note_db_state; rebuild it first");
            }
            // If the change is already read-only, then the lease is held by another
            // (likely failed) migrator thread. Fail early, as we can't take over
            // the lease.
            NoteDbChangeState.checkNotReadOnly(change, skewMs);
            if (state.getPrimaryStorage() != PrimaryStorage.NOTE_DB) {
                Timestamp now = TimeUtil.nowTs();
                Timestamp until = new Timestamp(now.getTime() + timeoutMs);
                change.setNoteDbState(state.withReadOnlyUntil(until).toString());
            } else {
                alreadyMigrated.set(true);
            }
            return change;
        }
    });
    return alreadyMigrated.get() ? null : result;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OrmRuntimeException(com.google.gwtorm.server.OrmRuntimeException) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp)

Example 7 with OrmRuntimeException

use of com.google.gwtorm.server.OrmRuntimeException in project gerrit by GerritCodeReview.

the class GetRevisionActions method getETag.

@Override
public String getETag(RevisionResource rsrc) {
    Hasher h = Hashing.md5().newHasher();
    CurrentUser user = rsrc.getControl().getUser();
    try {
        rsrc.getChangeResource().prepareETag(h, user);
        h.putBoolean(Submit.wholeTopicEnabled(config));
        ReviewDb db = dbProvider.get();
        ChangeSet cs = mergeSuperSet.get().completeChangeSet(db, rsrc.getChange(), user);
        for (ChangeData cd : cs.changes()) {
            changeResourceFactory.create(cd.changeControl()).prepareETag(h, user);
        }
        h.putBoolean(cs.furtherHiddenChanges());
    } catch (IOException | OrmException e) {
        throw new OrmRuntimeException(e);
    }
    return h.hash().toString();
}
Also used : Hasher(com.google.common.hash.Hasher) OrmRuntimeException(com.google.gwtorm.server.OrmRuntimeException) CurrentUser(com.google.gerrit.server.CurrentUser) OrmException(com.google.gwtorm.server.OrmException) IOException(java.io.IOException) ChangeSet(com.google.gerrit.server.git.ChangeSet) ChangeData(com.google.gerrit.server.query.change.ChangeData) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Aggregations

OrmRuntimeException (com.google.gwtorm.server.OrmRuntimeException)7 Change (com.google.gerrit.reviewdb.client.Change)6 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)4 ChangeSet (com.google.gerrit.server.git.ChangeSet)3 ChangeData (com.google.gerrit.server.query.change.ChangeData)3 OrmException (com.google.gwtorm.server.OrmException)3 IOException (java.io.IOException)3 Timestamp (java.sql.Timestamp)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ParameterizedString (com.google.gerrit.common.data.ParameterizedString)2 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)2 UiAction (com.google.gerrit.extensions.webui.UiAction)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 RevId (com.google.gerrit.reviewdb.client.RevId)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects (com.google.common.base.MoreObjects)1 Strings (com.google.common.base.Strings)1