Search in sources :

Example 31 with StorageException

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());
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) AccountState(com.google.gerrit.server.account.AccountState) StorageException(com.google.gerrit.exceptions.StorageException)

Example 32 with StorageException

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);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 33 with StorageException

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)));
}
Also used : ProjectState(com.google.gerrit.server.project.ProjectState) Change(com.google.gerrit.entities.Change) UiAction(com.google.gerrit.extensions.webui.UiAction) StorageException(com.google.gerrit.exceptions.StorageException)

Example 34 with StorageException

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;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) AgreementInfo(com.google.gerrit.extensions.common.AgreementInfo) GroupReference(com.google.gerrit.entities.GroupReference) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) StorageException(com.google.gerrit.exceptions.StorageException) GroupResource(com.google.gerrit.server.group.GroupResource) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 35 with StorageException

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;
    }
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.entities.Change) SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) IOException(java.io.IOException) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeSet(com.google.gerrit.server.submit.ChangeSet) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)153 IOException (java.io.IOException)68 Change (com.google.gerrit.entities.Change)47 ObjectId (org.eclipse.jgit.lib.ObjectId)37 Repository (org.eclipse.jgit.lib.Repository)33 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)30 PatchSet (com.google.gerrit.entities.PatchSet)29 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 ArrayList (java.util.ArrayList)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)24 Project (com.google.gerrit.entities.Project)22 Ref (org.eclipse.jgit.lib.Ref)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 Account (com.google.gerrit.entities.Account)20 Inject (com.google.inject.Inject)19 Map (java.util.Map)19 Test (org.junit.Test)19 List (java.util.List)18 BranchNameKey (com.google.gerrit.entities.BranchNameKey)17