Remove Rebuild REST endpoint and ChangeRebuilder
Rebuilding change NoteDb data from ReviewDb is no longer possible since ReviewDb is gone. Hence remove the Rebuild REST endpoint which allowed to manually trigger a rebuild of a change from ReviewDB. Change-Id: Ic8998d05ddd1039fcee77ccac38398db055436d1 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
committed by
Dave Borowitz
parent
7b8ea8902c
commit
7afc47cbb2
@@ -96,7 +96,6 @@ public class Module extends RestApiModule {
|
||||
get(CHANGE_KIND, "submitted_together").to(SubmittedTogether.class);
|
||||
post(CHANGE_KIND, "rebase").to(Rebase.CurrentRevision.class);
|
||||
post(CHANGE_KIND, "index").to(Index.class);
|
||||
post(CHANGE_KIND, "rebuild.notedb").to(Rebuild.class);
|
||||
post(CHANGE_KIND, "move").to(Move.class);
|
||||
post(CHANGE_KIND, "private").to(PostPrivate.class);
|
||||
post(CHANGE_KIND, "private.delete").to(DeletePrivateByPost.class);
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.CommentsUtil;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.notedb.ChangeBundle;
|
||||
import com.google.gerrit.server.notedb.ChangeBundleReader;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.NotesMigration;
|
||||
import com.google.gerrit.server.notedb.rebuild.ChangeRebuilder;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class Rebuild implements RestModifyView<ChangeResource, Input> {
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
private final NotesMigration migration;
|
||||
private final ChangeRebuilder rebuilder;
|
||||
private final ChangeBundleReader bundleReader;
|
||||
private final CommentsUtil commentsUtil;
|
||||
private final ChangeNotes.Factory notesFactory;
|
||||
|
||||
@Inject
|
||||
Rebuild(
|
||||
Provider<ReviewDb> db,
|
||||
NotesMigration migration,
|
||||
ChangeRebuilder rebuilder,
|
||||
ChangeBundleReader bundleReader,
|
||||
CommentsUtil commentsUtil,
|
||||
ChangeNotes.Factory notesFactory) {
|
||||
this.db = db;
|
||||
this.migration = migration;
|
||||
this.rebuilder = rebuilder;
|
||||
this.bundleReader = bundleReader;
|
||||
this.commentsUtil = commentsUtil;
|
||||
this.notesFactory = notesFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(ChangeResource rsrc, Input input)
|
||||
throws ResourceNotFoundException, IOException, OrmException, ConfigInvalidException,
|
||||
ResourceConflictException {
|
||||
if (!migration.commitChangeWrites()) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
if (!migration.readChanges()) {
|
||||
// ChangeBundle#fromNotes currently doesn't work if reading isn't enabled,
|
||||
// so don't attempt a diff.
|
||||
rebuild(rsrc);
|
||||
return BinaryResult.create("Rebuilt change successfully");
|
||||
}
|
||||
|
||||
// Not the same transaction as the rebuild, so may result in spurious diffs
|
||||
// in the case of races. This should be easy enough to detect by rerunning.
|
||||
ChangeBundle reviewDbBundle =
|
||||
bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db.get()), rsrc.getId());
|
||||
if (reviewDbBundle == null) {
|
||||
throw new ResourceConflictException("change is missing in ReviewDb");
|
||||
}
|
||||
rebuild(rsrc);
|
||||
ChangeNotes notes = notesFactory.create(db.get(), rsrc.getChange().getProject(), rsrc.getId());
|
||||
ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notes);
|
||||
List<String> diffs = reviewDbBundle.differencesFrom(noteDbBundle);
|
||||
if (diffs.isEmpty()) {
|
||||
return BinaryResult.create("No differences between ReviewDb and NoteDb");
|
||||
}
|
||||
return BinaryResult.create(
|
||||
diffs.stream().collect(joining("\n", "Differences between ReviewDb and NoteDb:\n", "\n")));
|
||||
}
|
||||
|
||||
private void rebuild(ChangeResource rsrc)
|
||||
throws ResourceNotFoundException, OrmException, IOException {
|
||||
try {
|
||||
rebuilder.rebuild(db.get(), rsrc.getId());
|
||||
} catch (NoSuchChangeException e) {
|
||||
throw new ResourceNotFoundException(IdString.fromDecoded(rsrc.getId().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,14 +112,6 @@ public class ChangesRestApiBindingsIT extends AbstractDaemonTest {
|
||||
RestCall.delete("/changes/%s/edit"),
|
||||
RestCall.delete("/changes/%s"));
|
||||
|
||||
/**
|
||||
* Change REST endpoints to be tested with NoteDb, each URL contains a placeholder for the change
|
||||
* identifier.
|
||||
*/
|
||||
private static final ImmutableList<RestCall> CHANGE_ENDPOINTS_NOTEDB =
|
||||
ImmutableList.of(
|
||||
RestCall.post("/changes/%s/hashtags"), RestCall.post("/changes/%s/rebuild.notedb"));
|
||||
|
||||
/**
|
||||
* Reviewer REST endpoints to be tested, each URL contains placeholders for the change identifier
|
||||
* and the reviewer identifier.
|
||||
@@ -284,14 +276,6 @@ public class ChangesRestApiBindingsIT extends AbstractDaemonTest {
|
||||
RestApiCallHelper.execute(adminRestSession, CHANGE_ENDPOINTS, changeId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeEndpointsNoteDb() throws Exception {
|
||||
assume().that(notesMigration.readChanges()).isTrue();
|
||||
|
||||
String changeId = createChange().getChangeId();
|
||||
RestApiCallHelper.execute(adminRestSession, CHANGE_ENDPOINTS_NOTEDB, changeId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reviewerEndpoints() throws Exception {
|
||||
String changeId = createChange().getChangeId();
|
||||
|
||||
@@ -42,8 +42,6 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
||||
import com.google.gerrit.extensions.client.Side;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -77,7 +75,6 @@ import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.server.project.testing.Util;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.restapi.change.PostReview;
|
||||
import com.google.gerrit.server.restapi.change.Rebuild;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.BatchUpdateOp;
|
||||
import com.google.gerrit.server.update.ChangeContext;
|
||||
@@ -134,8 +131,6 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
|
||||
|
||||
@Inject private NoteDbChecker checker;
|
||||
|
||||
@Inject private Rebuild rebuildHandler;
|
||||
|
||||
@Inject private Provider<ReviewDb> dbProvider;
|
||||
|
||||
@Inject private CommentsUtil commentsUtil;
|
||||
@@ -325,24 +320,6 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
|
||||
checker.checkChanges(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restApiNotFoundWhenNoteDbDisabled() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
rebuildHandler.apply(parseChangeResource(r.getChangeId()), new Input());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rebuildViaRestApi() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
Change.Id id = r.getPatchSetId().getParentKey();
|
||||
setNotesMigration(true, false);
|
||||
|
||||
checker.assertNoChangeRef(project, id);
|
||||
rebuildHandler.apply(parseChangeResource(r.getChangeId()), new Input());
|
||||
checker.checkChanges(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeToNewRefForNewChange() throws Exception {
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
|
||||
Reference in New Issue
Block a user