use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class SubmitStrategyListener method afterUpdateRepos.
@Override
public void afterUpdateRepos() throws ResourceConflictException {
try {
markCleanMerges();
List<Change.Id> alreadyMerged = checkCommitStatus();
findUnmergedChanges(alreadyMerged);
} catch (IntegrationException e) {
throw new ResourceConflictException(e.getMessage(), e);
}
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class PutName method renameGroup.
private GroupDetail renameGroup(AccountGroup group, String newName) throws ResourceConflictException, OrmException, NoSuchGroupException, IOException {
AccountGroup.Id groupId = group.getId();
AccountGroup.NameKey old = group.getNameKey();
AccountGroup.NameKey key = new AccountGroup.NameKey(newName);
try {
AccountGroupName id = new AccountGroupName(key, groupId);
db.get().accountGroupNames().insert(Collections.singleton(id));
} catch (OrmException e) {
AccountGroupName other = db.get().accountGroupNames().get(key);
if (other != null) {
//
if (other.getId().equals(groupId)) {
return groupDetailFactory.create(groupId).call();
}
//
throw new ResourceConflictException("group with name " + newName + "already exists");
}
throw e;
}
group.setNameKey(key);
db.get().accountGroups().update(Collections.singleton(group));
AccountGroupName priorName = db.get().accountGroupNames().get(old);
if (priorName != null) {
db.get().accountGroupNames().delete(Collections.singleton(priorName));
}
groupCache.evict(group);
groupCache.evictAfterRename(old, key);
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = renameGroupOpFactory.create(currentUser.get().newCommitterIdent(new Date(), TimeZone.getDefault()), group.getGroupUUID(), old.get(), newName).start(0, TimeUnit.MILLISECONDS);
return groupDetailFactory.create(groupId).call();
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class ReviewDbBatchUpdate method executeNoteDbUpdates.
private void executeNoteDbUpdates(List<ChangeTask> tasks) throws ResourceConflictException, IOException {
// Aggregate together all NoteDb ref updates from the ops we executed,
// possibly in parallel. Each task had its own NoteDbUpdateManager instance
// with its own thread-local copy of the repo(s), but each of those was just
// used for staging updates and was never executed.
//
// Use a new BatchRefUpdate as the original batchRefUpdate field is intended
// for use only by the updateRepo phase.
//
// See the comments in NoteDbUpdateManager#execute() for why we execute the
// updates on the change repo first.
logDebug("Executing NoteDb updates for {} changes", tasks.size());
try {
initRepository();
BatchRefUpdate changeRefUpdate = repoView.getRepository().getRefDatabase().newBatchUpdate();
boolean hasAllUsersCommands = false;
try (ObjectInserter ins = repoView.getRepository().newObjectInserter()) {
int objs = 0;
for (ChangeTask task : tasks) {
if (task.noteDbResult == null) {
logDebug("No-op update to {}", task.id);
continue;
}
for (ReceiveCommand cmd : task.noteDbResult.changeCommands()) {
changeRefUpdate.addCommand(cmd);
}
for (InsertedObject obj : task.noteDbResult.changeObjects()) {
objs++;
ins.insert(obj.type(), obj.data().toByteArray());
}
hasAllUsersCommands |= !task.noteDbResult.allUsersCommands().isEmpty();
}
logDebug("Collected {} objects and {} ref updates to change repo", objs, changeRefUpdate.getCommands().size());
executeNoteDbUpdate(getRevWalk(), ins, changeRefUpdate);
}
if (hasAllUsersCommands) {
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
RevWalk allUsersRw = new RevWalk(allUsersRepo);
ObjectInserter allUsersIns = allUsersRepo.newObjectInserter()) {
int objs = 0;
BatchRefUpdate allUsersRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
for (ChangeTask task : tasks) {
for (ReceiveCommand cmd : task.noteDbResult.allUsersCommands()) {
allUsersRefUpdate.addCommand(cmd);
}
for (InsertedObject obj : task.noteDbResult.allUsersObjects()) {
allUsersIns.insert(obj.type(), obj.data().toByteArray());
}
}
logDebug("Collected {} objects and {} ref updates to All-Users", objs, allUsersRefUpdate.getCommands().size());
executeNoteDbUpdate(allUsersRw, allUsersIns, allUsersRefUpdate);
}
} else {
logDebug("No All-Users updates");
}
} catch (IOException e) {
if (tasks.stream().allMatch(t -> t.storage == PrimaryStorage.REVIEW_DB)) {
// Ignore all errors trying to update NoteDb at this point. We've already written the
// NoteDbChangeStates to ReviewDb, which means if any state is out of date it will be
// rebuilt the next time it is needed.
//
// Always log even without RequestId.
log.debug("Ignoring NoteDb update error after ReviewDb write", e);
// Otherwise, we can't prove it's safe to ignore the error, either because some change had
// NOTE_DB primary, or a task failed before determining the primary storage.
} else if (e instanceof LockFailureException) {
// although it happened too late for us to produce anything but a generic error message.
throw new ResourceConflictException("Updating change failed due to conflicting write", e);
}
throw e;
}
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class BatchUpdate method wrapAndThrowException.
static void wrapAndThrowException(Exception e) throws UpdateException, RestApiException {
Throwables.throwIfUnchecked(e);
// Propagate REST API exceptions thrown by operations; they commonly throw exceptions like
// ResourceConflictException to indicate an atomic update failure.
Throwables.throwIfInstanceOf(e, UpdateException.class);
Throwables.throwIfInstanceOf(e, RestApiException.class);
// REST exception types
if (e instanceof InvalidChangeOperationException) {
throw new ResourceConflictException(e.getMessage(), e);
} else if (e instanceof NoSuchChangeException || e instanceof NoSuchRefException || e instanceof NoSuchProjectException) {
throw new ResourceNotFoundException(e.getMessage(), e);
}
// Otherwise, wrap in a generic UpdateException, which does not include a user-visible message.
throw new UpdateException(e);
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class SetWorkInProgress method applyImpl.
@Override
protected Response<?> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input) throws RestApiException, UpdateException {
Change change = rsrc.getChange();
if (!rsrc.isUserOwner()) {
throw new AuthException("not allowed to set work in progress");
}
if (change.getStatus() != Status.NEW) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
}
if (change.isWorkInProgress()) {
throw new ResourceConflictException("change is already work in progress");
}
try (BatchUpdate bu = updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
bu.addOp(rsrc.getChange().getId(), new WorkInProgressOp(cmUtil, true, input));
bu.execute();
return Response.ok("");
}
}
Aggregations