Search in sources :

Example 51 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class ChangeDraftUpdate method applyImpl.

@Override
protected CommitBuilder applyImpl(RevWalk rw, ObjectInserter ins, ObjectId curr) throws IOException {
    CommitBuilder cb = new CommitBuilder();
    cb.setMessage("Update draft comments");
    try {
        return storeCommentsInNotes(rw, ins, curr, cb);
    } catch (ConfigInvalidException e) {
        throw new StorageException(e);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) StorageException(com.google.gerrit.exceptions.StorageException)

Example 52 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class IntBlob method parse.

private static Optional<IntBlob> parse(Repository repo, String refName, ObjectReader or) throws IOException {
    Ref ref = repo.exactRef(refName);
    if (ref == null) {
        return Optional.empty();
    }
    ObjectId id = ref.getObjectId();
    ObjectLoader ol = or.open(id, OBJ_BLOB);
    if (ol.getType() != OBJ_BLOB) {
        // (certainly InMemoryRepository doesn't).
        throw new IncorrectObjectTypeException(id, OBJ_BLOB);
    }
    String str = CharMatcher.whitespace().trimFrom(new String(ol.getCachedBytes(), UTF_8));
    Integer value = Ints.tryParse(str);
    if (value == null) {
        throw new StorageException("invalid value in " + refName + " blob at " + id.name());
    }
    return Optional.of(IntBlob.create(id, value));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 53 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class GroupIndexerImpl method reindexIfStale.

@Override
public boolean reindexIfStale(AccountGroup.UUID uuid) {
    try {
        StalenessCheckResult stalenessCheckResult = stalenessChecker.check(uuid);
        if (stalenessCheckResult.isStale()) {
            logger.atInfo().log("Reindexing stale document %s", stalenessCheckResult);
            index(uuid);
            return true;
        }
    } catch (IOException e) {
        throw new StorageException(e);
    }
    return false;
}
Also used : StalenessCheckResult(com.google.gerrit.server.index.StalenessCheckResult) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 54 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class AbstractChangeNotes method load.

public T load(Repository repo) {
    if (loaded) {
        return self();
    }
    if (args.failOnLoadForTest.get()) {
        throw new StorageException("Reading from NoteDb is disabled");
    }
    try (Timer0.Context timer = args.metrics.readLatency.start();
        // auto-rebuilding before this object may get passed to a ChangeUpdate.
        LoadHandle handle = openHandle(repo, revision)) {
        revision = handle.id();
        onLoad(handle);
        loaded = true;
    } catch (ConfigInvalidException | IOException e) {
        throw new StorageException(e);
    }
    return self();
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Timer0(com.google.gerrit.metrics.Timer0) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 55 with StorageException

use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.

the class PrologRuleEvaluator method evaluate.

/**
 * Evaluate the submit rules.
 *
 * @return {@link SubmitRecord} returned from the evaluated rules. Can include errors.
 */
public SubmitRecord evaluate() {
    Change change;
    try {
        change = cd.change();
        if (change == null) {
            throw new StorageException("No change found");
        }
        if (projectState == null) {
            throw new NoSuchProjectException(cd.project());
        }
    } catch (StorageException | NoSuchProjectException e) {
        return ruleError("Error looking up change " + cd.getId(), e);
    }
    logger.atFine().log("input approvals: %s", cd.approvals());
    List<Term> results;
    try {
        results = evaluateImpl("locate_submit_rule", "can_submit", "locate_submit_filter", "filter_submit_results");
    } catch (RuleEvalException e) {
        return ruleError(e.getMessage(), e);
    }
    if (results.isEmpty()) {
        // whether or not that is actually possible given the permissions.
        return ruleError(String.format("Submit rule '%s' for change %s of %s has no solution.", getSubmitRuleName(), cd.getId(), projectState.getName()));
    }
    SubmitRecord submitRecord = resultsToSubmitRecord(getSubmitRule(), results);
    logger.atFine().log("submit record: %s", submitRecord);
    return submitRecord;
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) RuleEvalException(com.google.gerrit.server.project.RuleEvalException) Change(com.google.gerrit.entities.Change) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) 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