use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ChangeIdHandler method parseArguments.
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
String token = params.getParameter(0);
List<String> tokens = Splitter.on(',').splitToList(token);
if (tokens.size() != 3) {
throw new CmdLineException(owner, localizable("change should be specified as <project>,<branch>,<change-id>"));
}
try {
Change.Key key = Change.Key.parse(tokens.get(2));
Project.NameKey project = Project.nameKey(tokens.get(0));
BranchNameKey branch = BranchNameKey.create(project, tokens.get(1));
List<ChangeData> changes = queryProvider.get().byBranchKey(branch, key);
if (!changes.isEmpty()) {
if (changes.size() > 1) {
String msg = "\"%s\": resolves to multiple changes";
logger.atSevere().log(msg, token);
throw new CmdLineException(owner, localizable(msg), token);
}
setter.addValue(changes.get(0).getId());
return 1;
}
} catch (IllegalArgumentException e) {
throw new CmdLineException(owner, localizable("Change-Id is not valid: %s"), e.getMessage());
} catch (StorageException e) {
throw new CmdLineException(owner, localizable("Database error: %s"), e.getMessage());
}
throw new CmdLineException(owner, localizable("\"%s\": change not found"), token);
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AccountIdHandler method parseArguments.
@Override
public int parseArguments(Parameters params) throws CmdLineException {
String token = params.getParameter(0);
Account.Id accountId;
try {
try {
accountId = accountResolver.resolve(token).asUnique().account().id();
} catch (UnprocessableEntityException e) {
switch(authType) {
case HTTP_LDAP:
case CLIENT_SSL_CERT_LDAP:
case LDAP:
accountId = createAccountByLdap(token);
break;
case CUSTOM_EXTENSION:
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
case HTTP:
case LDAP_BIND:
case OAUTH:
case OPENID:
case OPENID_SSO:
default:
String msg = "user \"%s\" not found";
logger.atSevere().withCause(e).log(msg, token);
throw new CmdLineException(owner, localizable(msg), token);
}
}
} catch (StorageException e) {
CmdLineException newException = new CmdLineException(owner, localizable("database is down"));
newException.initCause(e);
throw newException;
} catch (IOException e) {
throw new CmdLineException(owner, "Failed to load account", e);
} catch (ConfigInvalidException e) {
throw new CmdLineException(owner, "Invalid account config", e);
}
setter.addValue(accountId);
return 1;
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ChangeJson method format.
private ChangeInfo format(ChangeData cd, Optional<PatchSet.Id> limitToPsId, boolean fillAccountLoader, List<PluginDefinedInfo> pluginInfosForChange) {
try {
if (fillAccountLoader) {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
ChangeInfo res = toChangeInfo(cd, limitToPsId, pluginInfosForChange);
accountLoader.fill();
return res;
}
return toChangeInfo(cd, limitToPsId, pluginInfosForChange);
} catch (PatchListNotAvailableException | GpgException | IOException | PermissionBackendException | RuntimeException e) {
if (!has(CHECK)) {
Throwables.throwIfInstanceOf(e, StorageException.class);
throw new StorageException(e);
}
return checkOnly(cd);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ChangeJson method loadPatchSets.
private Map<PatchSet.Id, PatchSet> loadPatchSets(ChangeData cd, Optional<PatchSet.Id> limitToPsId) {
Collection<PatchSet> src;
if (has(ALL_REVISIONS) || has(MESSAGES)) {
src = cd.patchSets();
} else {
PatchSet ps;
if (limitToPsId.isPresent()) {
ps = cd.patchSet(limitToPsId.get());
if (ps == null) {
throw new StorageException("missing patch set " + limitToPsId.get());
}
} else {
ps = cd.currentPatchSet();
if (ps == null) {
throw new StorageException("missing current patch set for change " + cd.getId());
}
}
src = Collections.singletonList(ps);
}
Map<PatchSet.Id, PatchSet> map = Maps.newHashMapWithExpectedSize(src.size());
for (PatchSet patchSet : src) {
map.put(patchSet.id(), patchSet);
}
return map;
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AbandonUtil method abandonInactiveOpenChanges.
public void abandonInactiveOpenChanges(BatchUpdate.Factory updateFactory) {
if (cfg.getAbandonAfter() <= 0) {
return;
}
try {
String query = "status:new age:" + TimeUnit.MILLISECONDS.toMinutes(cfg.getAbandonAfter()) + "m";
if (!cfg.getAbandonIfMergeable()) {
query += " -is:mergeable";
}
List<ChangeData> changesToAbandon = queryProvider.get().enforceVisibility(false).query(queryBuilderProvider.get().parse(query)).entities();
ImmutableListMultimap.Builder<Project.NameKey, ChangeData> builder = ImmutableListMultimap.builder();
for (ChangeData cd : changesToAbandon) {
builder.put(cd.project(), cd);
}
int count = 0;
ListMultimap<Project.NameKey, ChangeData> abandons = builder.build();
String message = cfg.getAbandonMessage();
for (Project.NameKey project : abandons.keySet()) {
Collection<ChangeData> changes = getValidChanges(abandons.get(project), query);
try {
batchAbandon.batchAbandon(updateFactory, project, internalUser, changes, message);
count += changes.size();
} catch (Exception e) {
StringBuilder msg = new StringBuilder("Failed to auto-abandon inactive change(s):");
for (ChangeData change : changes) {
msg.append(" ").append(change.getId().get());
}
msg.append(".");
logger.atSevere().withCause(e).log("%s", msg);
}
}
logger.atInfo().log("Auto-Abandoned %d of %d changes.", count, changesToAbandon.size());
} catch (QueryParseException | StorageException e) {
logger.atSevere().withCause(e).log("Failed to query inactive open changes for auto-abandoning.");
}
}
Aggregations