Search in sources :

Example 1 with MergeUpdateException

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

the class SubmitByRebaseAlwaysIT method failingChangeMessageModifierShortCircuits.

@Test
public void failingChangeMessageModifierShortCircuits() throws Throwable {
    ChangeMessageModifier modifier1 = (msg, orig, tip, dest) -> {
        throw new IllegalStateException("boom");
    };
    ChangeMessageModifier modifier2 = (msg, orig, tip, dest) -> msg + "A-footer: value\n";
    try (Registration registration = extensionRegistry.newRegistration().add(modifier1).add(modifier2)) {
        MergeUpdateException thrown = assertThrows(MergeUpdateException.class, () -> submitWithRebase());
        Throwable cause = Throwables.getRootCause(thrown);
        assertThat(cause).isInstanceOf(RuntimeException.class);
        assertThat(cause).hasMessageThat().isEqualTo("boom");
    }
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ImmutableList(com.google.common.collect.ImmutableList) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) ChangeData(com.google.gerrit.server.query.change.ChangeData) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) FooterConstants(com.google.gerrit.common.FooterConstants) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) Test(org.junit.Test)

Example 2 with MergeUpdateException

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

the class MergeOp method integrateIntoHistory.

private void integrateIntoHistory(ChangeSet cs, SubmissionExecutor submissionExecutor) throws RestApiException, UpdateException {
    checkArgument(!cs.furtherHiddenChanges(), "cannot integrate hidden changes into history");
    logger.atFine().log("Beginning merge attempt on %s", cs);
    Map<BranchNameKey, BranchBatch> toSubmit = new HashMap<>();
    ListMultimap<BranchNameKey, ChangeData> cbb;
    try {
        cbb = cs.changesByBranch();
    } catch (StorageException e) {
        throw new StorageException("Error reading changes to submit", e);
    }
    Set<BranchNameKey> branches = cbb.keySet();
    for (BranchNameKey branch : branches) {
        OpenRepo or = openRepo(branch.project());
        if (or != null) {
            toSubmit.put(branch, validateChangeList(or, cbb.get(branch)));
        }
    }
    // Done checks that don't involve running submit strategies.
    commitStatus.maybeFailVerbose();
    try {
        SubscriptionGraph subscriptionGraph = subscriptionGraphFactory.compute(branches, orm);
        SubmoduleCommits submoduleCommits = submoduleCommitsFactory.create(orm);
        UpdateOrderCalculator updateOrderCalculator = new UpdateOrderCalculator(subscriptionGraph);
        List<SubmitStrategy> strategies = getSubmitStrategies(toSubmit, updateOrderCalculator, submoduleCommits, subscriptionGraph, dryrun);
        this.allProjects = updateOrderCalculator.getProjectsInOrder();
        List<BatchUpdate> batchUpdates = orm.batchUpdates(allProjects);
        // Group batch updates by project
        Map<Project.NameKey, BatchUpdate> batchUpdatesByProject = batchUpdates.stream().collect(Collectors.toMap(b -> b.getProject(), Function.identity()));
        for (Map.Entry<Change.Id, ChangeData> entry : cs.changesById().entrySet()) {
            Project.NameKey project = entry.getValue().project();
            Change.Id changeId = entry.getKey();
            ChangeData cd = entry.getValue();
            batchUpdatesByProject.get(project).addOp(changeId, storeSubmitRequirementsOpFactory.create(cd.submitRequirementsIncludingLegacy().values(), cd));
        }
        try {
            submissionExecutor.setAdditionalBatchUpdateListeners(ImmutableList.of(new SubmitStrategyListener(submitInput, strategies, commitStatus)));
            submissionExecutor.execute(batchUpdates);
        } finally {
            // If the BatchUpdate fails it can be that merging some of the changes was actually
            // successful. This is why we must to collect the updated changes also when an
            // exception was thrown.
            strategies.forEach(s -> updatedChanges.putAll(s.getUpdatedChanges()));
            // Do not leave executed BatchUpdates in the OpenRepos
            if (!dryrun) {
                orm.resetUpdates(ImmutableSet.copyOf(this.allProjects));
            }
        }
    } catch (NoSuchProjectException e) {
        throw new ResourceNotFoundException(e.getMessage());
    } catch (IOException e) {
        throw new StorageException(e);
    } catch (SubmoduleConflictException e) {
        throw new IntegrationConflictException(e.getMessage(), e);
    } catch (UpdateException e) {
        if (e.getCause() instanceof LockFailureException) {
            // as to be unnoticeable, assuming RetryHelper is retrying sufficiently.
            throw e;
        }
        // inner IntegrationConflictException to a ResourceConflictException.
        if (e.getCause() instanceof IntegrationConflictException) {
            throw (IntegrationConflictException) e.getCause();
        }
        throw new MergeUpdateException(genericMergeError(cs), e);
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) SuperprojectUpdateOnSubmission(com.google.gerrit.server.update.SuperprojectUpdateOnSubmission) ListMultimap(com.google.common.collect.ListMultimap) MultimapBuilder(com.google.common.collect.MultimapBuilder) InternalUser(com.google.gerrit.server.InternalUser) Inject(com.google.inject.Inject) SubmissionId(com.google.gerrit.entities.SubmissionId) UpdateException(com.google.gerrit.server.update.UpdateException) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) StoreSubmitRequirementsOp(com.google.gerrit.server.notedb.StoreSubmitRequirementsOp) RetryHelper(com.google.gerrit.server.update.RetryHelper) MergeTip(com.google.gerrit.server.git.MergeTip) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Status(com.google.gerrit.entities.Change.Status) ImmutableMap(com.google.common.collect.ImmutableMap) TraceContext(com.google.gerrit.server.logging.TraceContext) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) Set(java.util.Set) Constants(org.eclipse.jgit.lib.Constants) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) Instant(java.time.Instant) RetryListener(com.github.rholder.retry.RetryListener) SubmitRecord(com.google.gerrit.entities.SubmitRecord) Collectors(java.util.stream.Collectors) BranchNameKey(com.google.gerrit.entities.BranchNameKey) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) SubmitTypeRecord(com.google.gerrit.entities.SubmitTypeRecord) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Ref(org.eclipse.jgit.lib.Ref) AutoValue(com.google.auto.value.AutoValue) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Counter0(com.google.gerrit.metrics.Counter0) MetricMaker(com.google.gerrit.metrics.MetricMaker) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) FluentLogger(com.google.common.flogger.FluentLogger) Joiner(com.google.common.base.Joiner) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Singleton(com.google.inject.Singleton) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) HashMap(java.util.HashMap) Function(java.util.function.Function) SubmissionListener(com.google.gerrit.server.update.SubmissionListener) MergeValidators(com.google.gerrit.server.git.validators.MergeValidators) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) SubmissionExecutor(com.google.gerrit.server.update.SubmissionExecutor) Description(com.google.gerrit.metrics.Description) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Comparator.comparing(java.util.Comparator.comparing) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeUtil(com.google.gerrit.server.ChangeUtil) LockFailureException(com.google.gerrit.git.LockFailureException) ChangeContext(com.google.gerrit.server.update.ChangeContext) MergeValidationException(com.google.gerrit.server.git.validators.MergeValidationException) LinkedHashSet(java.util.LinkedHashSet) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) OpenBranch(com.google.gerrit.server.submit.MergeOpRepoManager.OpenBranch) StorageException(com.google.gerrit.exceptions.StorageException) Attempt(com.github.rholder.retry.Attempt) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) SubmitRuleOptions(com.google.gerrit.server.project.SubmitRuleOptions) SetMultimap(com.google.common.collect.SetMultimap) ObjectId(org.eclipse.jgit.lib.ObjectId) Provider(com.google.inject.Provider) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) RequestId(com.google.gerrit.server.logging.RequestId) HashMap(java.util.HashMap) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) LockFailureException(com.google.gerrit.git.LockFailureException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) UpdateException(com.google.gerrit.server.update.UpdateException) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Change(com.google.gerrit.entities.Change) IOException(java.io.IOException) ChangeData(com.google.gerrit.server.query.change.ChangeData) BranchNameKey(com.google.gerrit.entities.BranchNameKey) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) Project(com.google.gerrit.entities.Project) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) SubmissionId(com.google.gerrit.entities.SubmissionId) ObjectId(org.eclipse.jgit.lib.ObjectId) RequestId(com.google.gerrit.server.logging.RequestId) StorageException(com.google.gerrit.exceptions.StorageException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 3 with MergeUpdateException

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

the class SubmitByRebaseAlwaysIT method changeMessageModifierReturningNullShortCircuits.

@Test
public void changeMessageModifierReturningNullShortCircuits() throws Throwable {
    ChangeMessageModifier modifier1 = (msg, orig, tip, dest) -> null;
    ChangeMessageModifier modifier2 = (msg, orig, tip, dest) -> msg + "A-footer: value\n";
    try (Registration registration = extensionRegistry.newRegistration().add(modifier1, "modifier-1").add(modifier2, "modifier-2")) {
        MergeUpdateException thrown = assertThrows(MergeUpdateException.class, () -> submitWithRebase());
        Throwable cause = Throwables.getRootCause(thrown);
        assertThat(cause).isInstanceOf(RuntimeException.class);
        assertThat(cause).hasMessageThat().isEqualTo(modifier1.getClass().getName() + ".onSubmit from plugin modifier-1 returned null instead of new commit" + " message");
    }
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ImmutableList(com.google.common.collect.ImmutableList) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) ChangeData(com.google.gerrit.server.query.change.ChangeData) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) FooterConstants(com.google.gerrit.common.FooterConstants) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 PatchSet (com.google.gerrit.entities.PatchSet)3 MergeUpdateException (com.google.gerrit.exceptions.MergeUpdateException)3 SubmitType (com.google.gerrit.extensions.client.SubmitType)3 ChangeData (com.google.gerrit.server.query.change.ChangeData)3 Inject (com.google.inject.Inject)3 Comparator.comparing (java.util.Comparator.comparing)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Throwables (com.google.common.base.Throwables)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)2 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)2 FooterConstants (com.google.gerrit.common.FooterConstants)2 LabelId (com.google.gerrit.entities.LabelId)2