Search in sources :

Example 1 with GcError

use of com.google.gerrit.common.data.GarbageCollectionResult.GcError in project gerrit by GerritCodeReview.

the class GarbageCollectionCommand method runGC.

private void runGC() {
    List<Project.NameKey> projectNames;
    if (all) {
        projectNames = Lists.newArrayList(projectCache.all());
    } else {
        projectNames = projects.stream().map(ProjectState::getNameKey).collect(toList());
    }
    GarbageCollectionResult result = garbageCollectionFactory.create().run(projectNames, aggressive, showProgress ? stdout : null);
    if (result.hasErrors()) {
        for (GcError e : result.getErrors()) {
            String msg;
            switch(e.getType()) {
                case REPOSITORY_NOT_FOUND:
                    msg = "error: project \"" + e.getProjectName() + "\" not found";
                    break;
                case GC_ALREADY_SCHEDULED:
                    msg = "error: garbage collection for project \"" + e.getProjectName() + "\" was already scheduled";
                    break;
                case GC_FAILED:
                    msg = "error: garbage collection for project \"" + e.getProjectName() + "\" failed";
                    break;
                default:
                    msg = "error: garbage collection for project \"" + e.getProjectName() + "\" failed: " + e.getType();
            }
            stdout.print(msg + "\n");
        }
    }
}
Also used : GcError(com.google.gerrit.common.data.GarbageCollectionResult.GcError) ProjectState(com.google.gerrit.server.project.ProjectState) GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult)

Example 2 with GcError

use of com.google.gerrit.common.data.GarbageCollectionResult.GcError in project gerrit by GerritCodeReview.

the class GarbageCollection method run.

/**
 * Runs GC on the given projects, serially. Progress is written to writer if non-null.
 */
public GarbageCollectionResult run(List<Project.NameKey> projectNames, boolean aggressive, @Nullable PrintWriter writer) {
    GarbageCollectionResult result = new GarbageCollectionResult();
    Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames);
    for (Project.NameKey projectName : Sets.difference(Sets.newHashSet(projectNames), projectsToGc)) {
        result.addError(new GcError(GcError.Type.GC_ALREADY_SCHEDULED, projectName));
    }
    for (Project.NameKey p : projectsToGc) {
        try (Repository repo = repoManager.openRepository(p)) {
            logGcConfiguration(p, repo, aggressive);
            print(writer, "collecting garbage for \"" + p + "\":\n");
            GarbageCollectCommand gc = Git.wrap(repo instanceof DelegateRepository ? ((DelegateRepository) repo).delegate() : repo).gc();
            gc.setAggressive(aggressive);
            logGcInfo(p, "before:", gc.getStatistics());
            gc.setProgressMonitor(writer != null ? new TextProgressMonitor(writer) : NullProgressMonitor.INSTANCE);
            Properties statistics = gc.call();
            logGcInfo(p, "after: ", statistics);
            print(writer, "done.\n\n");
            fire(p, statistics);
        } catch (RepositoryNotFoundException e) {
            logGcError(writer, p, e);
            result.addError(new GcError(GcError.Type.REPOSITORY_NOT_FOUND, p));
        } catch (Exception e) {
            logGcError(writer, p, e);
            result.addError(new GcError(GcError.Type.GC_FAILED, p));
        } finally {
            gcQueue.gcFinished(p);
        }
    }
    return result;
}
Also used : GcError(com.google.gerrit.common.data.GarbageCollectionResult.GcError) GarbageCollectCommand(org.eclipse.jgit.api.GarbageCollectCommand) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) Properties(java.util.Properties) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult)

Example 3 with GcError

use of com.google.gerrit.common.data.GarbageCollectionResult.GcError in project gerrit by GerritCodeReview.

the class GarbageCollectionIT method testGcAlreadyScheduled.

@Test
@UseLocalDisk
public void testGcAlreadyScheduled() throws Exception {
    gcQueue.addAll(Arrays.asList(project));
    GarbageCollectionResult result = garbageCollectionFactory.create().run(Arrays.asList(allProjects, project, project2, project3));
    assertThat(result.hasErrors()).isTrue();
    assertThat(result.getErrors()).hasSize(1);
    GcError error = result.getErrors().get(0);
    assertThat(error.getType()).isEqualTo(GcError.Type.GC_ALREADY_SCHEDULED);
    assertThat(error.getProjectName()).isEqualTo(project);
}
Also used : GcError(com.google.gerrit.common.data.GarbageCollectionResult.GcError) GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseLocalDisk(com.google.gerrit.acceptance.UseLocalDisk)

Aggregations

GarbageCollectionResult (com.google.gerrit.common.data.GarbageCollectionResult)3 GcError (com.google.gerrit.common.data.GarbageCollectionResult.GcError)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 UseLocalDisk (com.google.gerrit.acceptance.UseLocalDisk)1 Project (com.google.gerrit.entities.Project)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 Properties (java.util.Properties)1 GarbageCollectCommand (org.eclipse.jgit.api.GarbageCollectCommand)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1 Repository (org.eclipse.jgit.lib.Repository)1 TextProgressMonitor (org.eclipse.jgit.lib.TextProgressMonitor)1 Test (org.junit.Test)1