use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AccountIndexerImpl method index.
@Override
public void index(Account.Id id) {
Optional<AccountState> accountState = byIdCache.get(id);
if (accountState.isPresent()) {
logger.atFine().log("Replace account %d in index", id.get());
} else {
logger.atFine().log("Delete account %d from index", id.get());
}
for (Index<Account.Id, AccountState> i : getWriteIndexes()) {
// Evict the cache to get an up-to-date value for sure.
if (accountState.isPresent()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Replacing account in index", Metadata.builder().accountId(id.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.replace(accountState.get());
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to replace account %d in index version %d", id.get(), i.getSchema().getVersion()), e);
}
} else {
try (TraceTimer traceTimer = TraceContext.newTimer("Deleting account in index", Metadata.builder().accountId(id.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.delete(id);
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to delete account %d from index version %d", id.get(), i.getSchema().getVersion()), e);
}
}
}
fireAccountIndexedEvent(id.get());
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class IndexUtils method setReady.
/**
* Mark an index version as ready to serve queries.
*/
public static void setReady(SitePaths sitePaths, String name, int version, boolean ready) {
try {
GerritIndexStatus cfg = new GerritIndexStatus(sitePaths);
cfg.setReady(name, version, ready);
cfg.save();
} catch (ConfigInvalidException | IOException e) {
throw new StorageException(e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class RevertSubmission method getDescription.
@Override
public Description getDescription(ChangeResource rsrc) {
Change change = rsrc.getChange();
boolean projectStatePermitsWrite = false;
try {
projectStatePermitsWrite = projectCache.get(rsrc.getProject()).map(ProjectState::statePermitsWrite).orElse(false);
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to check if project state permits write: %s", rsrc.getProject());
}
return new UiAction.Description().setLabel("Revert submission").setTitle("Revert this change and all changes that have been submitted together with this change").setVisible(and(and(change.isMerged() && change.getSubmissionId() != null && isChangePartOfSubmission(change.getSubmissionId()) && projectStatePermitsWrite, permissionBackend.user(rsrc.getUser()).ref(change.getDest()).testCond(CREATE_CHANGE)), permissionBackend.user(rsrc.getUser()).change(rsrc.getNotes()).testCond(REVERT)));
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AgreementJson method format.
public AgreementInfo format(ContributorAgreement ca) throws PermissionBackendException {
AgreementInfo info = new AgreementInfo();
info.name = ca.getName();
info.description = ca.getDescription();
info.url = ca.getAgreementUrl();
GroupReference autoVerifyGroup = ca.getAutoVerify();
if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
try {
GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
GroupResource group = new GroupResource(gc);
info.autoVerifyGroup = groupJson.format(group);
} catch (NoSuchGroupException | StorageException e) {
logger.atWarning().log("autoverify group \"%s\" does not exist, referenced in CLA \"%s\"", autoVerifyGroup.getName(), ca.getName());
}
}
return info;
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class SubmittedTogether method applyInfo.
public SubmittedTogetherInfo applyInfo(ChangeResource resource) throws AuthException, IOException, PermissionBackendException {
Change c = resource.getChange();
try {
List<ChangeData> cds;
int hidden;
if (c.isNew()) {
ChangeSet cs = mergeSuperSet.get().completeChangeSet(c, resource.getUser(), options.contains(TOPIC_CLOSURE));
cds = ensureRequiredDataIsLoaded(cs.changes().asList());
hidden = cs.nonVisibleChanges().size();
} else if (c.isMerged()) {
cds = queryProvider.get().bySubmissionId(c.getSubmissionId());
hidden = 0;
} else {
cds = Collections.emptyList();
hidden = 0;
}
if (hidden != 0 && !options.contains(NON_VISIBLE_CHANGES)) {
throw new AuthException("change would be submitted with a change that you cannot see");
}
cds = sort(cds, hidden);
SubmittedTogetherInfo info = new SubmittedTogetherInfo();
info.changes = json.create(jsonOpt).format(cds);
info.nonVisibleChanges = hidden;
return info;
} catch (StorageException | IOException e) {
logger.atSevere().withCause(e).log("Error on getting a ChangeSet");
throw e;
}
}
Aggregations