use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class ExternalIdIT method retryOnLockFailure.
@Test
public void retryOnLockFailure() throws Exception {
Retryer<RefsMetaExternalIdsUpdate> retryer = ExternalIdsUpdate.retryerBuilder().withBlockStrategy(new BlockStrategy() {
@Override
public void block(long sleepTime) {
// Don't sleep in tests.
}
}).build();
ExternalId.Key fooId = ExternalId.Key.create("foo", "foo");
ExternalId.Key barId = ExternalId.Key.create("bar", "bar");
final AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
ExternalIdsUpdate update = new ExternalIdsUpdate(repoManager, allUsers, metricMaker, externalIds, new DisabledExternalIdCache(), serverIdent.get(), serverIdent.get(), () -> {
if (!doneBgUpdate.getAndSet(true)) {
try {
extIdsUpdate.create().insert(ExternalId.create(barId, admin.id));
} catch (IOException | ConfigInvalidException | OrmException e) {
// Ignore, the successful insertion of the external ID is asserted later
}
}
}, retryer);
assertThat(doneBgUpdate.get()).isFalse();
update.insert(ExternalId.create(fooId, admin.id));
assertThat(doneBgUpdate.get()).isTrue();
assertThat(externalIds.get(fooId)).isNotNull();
assertThat(externalIds.get(barId)).isNotNull();
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class AbstractSubmit method setChangeStatusToNew.
private void setChangeStatusToNew(PushOneCommit.Result... changes) throws Exception {
for (PushOneCommit.Result change : changes) {
try (BatchUpdate bu = batchUpdateFactory.create(db, project, userFactory.create(admin.id), TimeUtil.nowTs())) {
bu.addOp(change.getChange().getId(), new BatchUpdateOp() {
@Override
public boolean updateChange(ChangeContext ctx) throws OrmException {
ctx.getChange().setStatus(Change.Status.NEW);
ctx.getUpdate(ctx.getChange().currentPatchSetId()).setStatus(Change.Status.NEW);
return true;
}
});
bu.execute();
}
}
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method mergeChange.
private ChangeControl mergeChange(ChangeControl ctl) throws Exception {
final ObjectId oldId = getDestRef(ctl);
final ObjectId newId = ObjectId.fromString(psUtil.current(db, ctl.getNotes()).getRevision().get());
final String dest = ctl.getChange().getDest().get();
try (BatchUpdate bu = newUpdate(adminId)) {
bu.addOp(ctl.getId(), new BatchUpdateOp() {
@Override
public void updateRepo(RepoContext ctx) throws IOException {
ctx.addRefUpdate(oldId, newId, dest);
}
@Override
public boolean updateChange(ChangeContext ctx) throws OrmException {
ctx.getChange().setStatus(Change.Status.MERGED);
ctx.getUpdate(ctx.getChange().currentPatchSetId()).fixStatus(Change.Status.MERGED);
return true;
}
});
bu.execute();
}
return reload(ctl);
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class CatServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException {
String keyStr = req.getPathInfo();
// We shouldn't have to do this extra decode pass, but somehow we
// are now receiving our "^1" suffix as "%5E1", which confuses us
// downstream. Other times we get our embedded "," as "%2C", which
// is equally bad. And yet when these happen a "%2F" is left as-is,
// rather than escaped as "%252F", which makes me feel really really
// uncomfortable with a blind decode right here.
//
keyStr = Url.decode(keyStr);
if (!keyStr.startsWith("/")) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
keyStr = keyStr.substring(1);
final Patch.Key patchKey;
final int side;
{
final int c = keyStr.lastIndexOf('^');
if (c == 0) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (c < 0) {
side = 0;
} else {
try {
side = Integer.parseInt(keyStr.substring(c + 1));
keyStr = keyStr.substring(0, c);
} catch (NumberFormatException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
try {
patchKey = Patch.Key.parse(keyStr);
} catch (NumberFormatException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
final Change.Id changeId = patchKey.getParentKey().getParentKey();
String revision;
try {
final ReviewDb db = requestDb.get();
final ChangeControl control = changeControl.validateFor(db, changeId, userProvider.get());
if (patchKey.getParentKey().get() == 0) {
// change edit
try {
Optional<ChangeEdit> edit = changeEditUtil.byChange(control.getChange());
if (edit.isPresent()) {
revision = ObjectId.toString(edit.get().getEditCommit());
} else {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
} catch (AuthException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
} else {
PatchSet patchSet = psUtil.get(db, control.getNotes(), patchKey.getParentKey());
if (patchSet == null) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
revision = patchSet.getRevision().get();
}
} catch (NoSuchChangeException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} catch (OrmException e) {
getServletContext().log("Cannot query database", e);
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
String path = patchKey.getFileName();
String restUrl = String.format("%s/changes/%d/revisions/%s/files/%s/download?parent=%d", req.getContextPath(), changeId.get(), revision, Url.encode(path), side);
rsp.sendRedirect(restUrl);
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class PerThreadReviewDbModule method configure.
@Override
protected void configure() {
final List<ReviewDb> dbs = Collections.synchronizedList(new ArrayList<ReviewDb>());
final ThreadLocal<ReviewDb> localDb = new ThreadLocal<>();
bind(ReviewDb.class).toProvider(new Provider<ReviewDb>() {
@Override
public ReviewDb get() {
ReviewDb db = localDb.get();
if (db == null) {
try {
db = schema.open();
dbs.add(db);
localDb.set(db);
} catch (OrmException e) {
throw new ProvisionException("unable to open ReviewDb", e);
}
}
return db;
}
});
listener().toInstance(new LifecycleListener() {
@Override
public void start() {
// Do nothing.
}
@Override
public void stop() {
for (ReviewDb db : dbs) {
db.close();
}
}
});
}
Aggregations