use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class RenameGroupCommand method run.
@Override
protected void run() throws Failure {
try {
GroupResource rsrc = groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName));
PutName.Input input = new PutName.Input();
input.name = newGroupName;
putName.apply(rsrc, input);
} catch (RestApiException | OrmException | IOException | NoSuchGroupException e) {
throw die(e);
}
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class ReviewCommand method run.
@Override
protected void run() throws UnloggedFailure {
if (abandonChange) {
if (restoreChange) {
throw die("abandon and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("abandon and submit actions are mutually exclusive");
}
if (publishPatchSet) {
throw die("abandon and publish actions are mutually exclusive");
}
if (deleteDraftPatchSet) {
throw die("abandon and delete actions are mutually exclusive");
}
if (rebaseChange) {
throw die("abandon and rebase actions are mutually exclusive");
}
if (moveToBranch != null) {
throw die("abandon and move actions are mutually exclusive");
}
}
if (publishPatchSet) {
if (restoreChange) {
throw die("publish and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("publish and submit actions are mutually exclusive");
}
if (deleteDraftPatchSet) {
throw die("publish and delete actions are mutually exclusive");
}
}
if (json) {
if (restoreChange) {
throw die("json and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("json and submit actions are mutually exclusive");
}
if (deleteDraftPatchSet) {
throw die("json and delete actions are mutually exclusive");
}
if (publishPatchSet) {
throw die("json and publish actions are mutually exclusive");
}
if (abandonChange) {
throw die("json and abandon actions are mutually exclusive");
}
if (changeComment != null) {
throw die("json and message are mutually exclusive");
}
if (rebaseChange) {
throw die("json and rebase actions are mutually exclusive");
}
if (moveToBranch != null) {
throw die("json and move actions are mutually exclusive");
}
if (changeTag != null) {
throw die("json and tag actions are mutually exclusive");
}
}
if (rebaseChange) {
if (deleteDraftPatchSet) {
throw die("rebase and delete actions are mutually exclusive");
}
if (submitChange) {
throw die("rebase and submit actions are mutually exclusive");
}
}
if (deleteDraftPatchSet && submitChange) {
throw die("delete and submit actions are mutually exclusive");
}
boolean ok = true;
ReviewInput input = null;
if (json) {
input = reviewFromJson();
}
for (final PatchSet patchSet : patchSets) {
try {
if (input != null) {
applyReview(patchSet, input);
} else {
reviewPatchSet(patchSet);
}
} catch (RestApiException | UnloggedFailure e) {
ok = false;
writeError("error", e.getMessage() + "\n");
} catch (NoSuchChangeException e) {
ok = false;
writeError("error", "no such change " + patchSet.getId().getParentKey().get());
} catch (Exception e) {
ok = false;
writeError("fatal", "internal server error while reviewing " + patchSet.getId() + "\n");
log.error("internal error while reviewing " + patchSet.getId(), e);
}
}
if (!ok) {
throw die("one or more reviews failed; review output above");
}
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class ReviewCommand method reviewPatchSet.
private void reviewPatchSet(final PatchSet patchSet) throws Exception {
if (notify == null) {
notify = NotifyHandling.ALL;
}
ReviewInput review = new ReviewInput();
review.message = Strings.emptyToNull(changeComment);
review.tag = Strings.emptyToNull(changeTag);
review.notify = notify;
review.labels = new TreeMap<>();
review.drafts = ReviewInput.DraftHandling.PUBLISH;
review.strictLabels = strictLabels;
for (ApproveOption ao : optionList) {
Short v = ao.value();
if (v != null) {
review.labels.put(ao.getLabelName(), v);
}
}
review.labels.putAll(customLabels);
// We don't need to add the review comment when abandoning/restoring.
if (abandonChange || restoreChange || moveToBranch != null) {
review.message = null;
}
try {
if (abandonChange) {
AbandonInput input = new AbandonInput();
input.message = Strings.emptyToNull(changeComment);
applyReview(patchSet, review);
changeApi(patchSet).abandon(input);
} else if (restoreChange) {
RestoreInput input = new RestoreInput();
input.message = Strings.emptyToNull(changeComment);
changeApi(patchSet).restore(input);
applyReview(patchSet, review);
} else {
applyReview(patchSet, review);
}
if (moveToBranch != null) {
MoveInput moveInput = new MoveInput();
moveInput.destinationBranch = moveToBranch;
moveInput.message = Strings.emptyToNull(changeComment);
changeApi(patchSet).move(moveInput);
}
if (rebaseChange) {
revisionApi(patchSet).rebase();
}
if (submitChange) {
revisionApi(patchSet).submit();
}
if (publishPatchSet) {
revisionApi(patchSet).publish();
} else if (deleteDraftPatchSet) {
revisionApi(patchSet).delete();
}
} catch (IllegalStateException | RestApiException e) {
throw die(e);
}
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class ReviewDbBatchUpdate method executeChangeOps.
private List<ChangeTask> executeChangeOps(boolean parallel, boolean dryrun) throws UpdateException, RestApiException {
List<ChangeTask> tasks;
boolean success = false;
Stopwatch sw = Stopwatch.createStarted();
try {
logDebug("Executing change ops (parallel? {})", parallel);
ListeningExecutorService executor = parallel ? changeUpdateExector : MoreExecutors.newDirectExecutorService();
tasks = new ArrayList<>(ops.keySet().size());
try {
if (notesMigration.commitChangeWrites() && repoView != null) {
// A NoteDb change may have been rebuilt since the repo was originally
// opened, so make sure we see that.
logDebug("Preemptively scanning for repo changes");
repoView.getRepository().scanForRepoChanges();
}
if (!ops.isEmpty() && notesMigration.failChangeWrites()) {
// Fail fast before attempting any writes if changes are read-only, as
// this is a programmer error.
logDebug("Failing early due to read-only Changes table");
throw new OrmException(NoteDbUpdateManager.CHANGES_READ_ONLY);
}
List<ListenableFuture<?>> futures = new ArrayList<>(ops.keySet().size());
for (Map.Entry<Change.Id, Collection<BatchUpdateOp>> e : ops.asMap().entrySet()) {
ChangeTask task = new ChangeTask(e.getKey(), e.getValue(), Thread.currentThread(), dryrun);
tasks.add(task);
if (!parallel) {
logDebug("Direct execution of task for ops: {}", ops);
}
futures.add(executor.submit(task));
}
if (parallel) {
logDebug("Waiting on futures for {} ops spanning {} changes", ops.size(), ops.keySet().size());
}
Futures.allAsList(futures).get();
if (notesMigration.commitChangeWrites()) {
if (!dryrun) {
executeNoteDbUpdates(tasks);
}
}
success = true;
} catch (ExecutionException | InterruptedException e) {
Throwables.throwIfInstanceOf(e.getCause(), UpdateException.class);
Throwables.throwIfInstanceOf(e.getCause(), RestApiException.class);
throw new UpdateException(e);
} catch (OrmException | IOException e) {
throw new UpdateException(e);
}
} finally {
metrics.executeChangeOpsLatency.record(success, sw.elapsed(NANOSECONDS), NANOSECONDS);
}
return tasks;
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class ReviewDbBatchUpdate method executeRefUpdates.
private void executeRefUpdates(boolean dryrun) throws IOException, RestApiException {
if (getRefUpdates().isEmpty()) {
logDebug("No ref updates to execute");
return;
}
// May not be opened if the caller added ref updates but no new objects.
// TODO(dborowitz): Really?
initRepository();
batchRefUpdate = repoView.getRepository().getRefDatabase().newBatchUpdate();
batchRefUpdate.setPushCertificate(pushCert);
batchRefUpdate.setRefLogMessage(refLogMessage, true);
batchRefUpdate.setAllowNonFastForwards(true);
repoView.getCommands().addTo(batchRefUpdate);
logDebug("Executing batch of {} ref updates", batchRefUpdate.getCommands().size());
if (dryrun) {
return;
}
// that might have access to unflushed objects.
try (RevWalk updateRw = new RevWalk(repoView.getRepository())) {
batchRefUpdate.execute(updateRw, NullProgressMonitor.INSTANCE);
}
boolean ok = true;
for (ReceiveCommand cmd : batchRefUpdate.getCommands()) {
if (cmd.getResult() != ReceiveCommand.Result.OK) {
ok = false;
break;
}
}
if (!ok) {
throw new RestApiException("BatchRefUpdate failed: " + batchRefUpdate);
}
}
Aggregations