Search in sources :

Example 1 with GarbageCollectionResult

use of com.google.gerrit.common.data.GarbageCollectionResult 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 = Lists.newArrayListWithCapacity(projects.size());
        for (ProjectControl pc : projects) {
            projectNames.add(pc.getProject().getNameKey());
        }
    }
    GarbageCollectionResult result = garbageCollectionFactory.create().run(projectNames, aggressive, showProgress ? stdout : null);
    if (result.hasErrors()) {
        for (GarbageCollectionResult.Error 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 : ProjectControl(com.google.gerrit.server.project.ProjectControl) GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult)

Example 2 with GarbageCollectionResult

use of com.google.gerrit.common.data.GarbageCollectionResult 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);
    GarbageCollectionResult.Error error = result.getErrors().get(0);
    assertThat(error.getType()).isEqualTo(GarbageCollectionResult.Error.Type.GC_ALREADY_SCHEDULED);
    assertThat(error.getProjectName()).isEqualTo(project);
}
Also used : GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseLocalDisk(com.google.gerrit.acceptance.UseLocalDisk)

Example 3 with GarbageCollectionResult

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

the class GarbageCollection method run.

public GarbageCollectionResult run(List<Project.NameKey> projectNames, boolean aggressive, 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 GarbageCollectionResult.Error(GarbageCollectionResult.Error.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).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 GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.REPOSITORY_NOT_FOUND, p));
        } catch (Exception e) {
            logGcError(writer, p, e);
            result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.GC_FAILED, p));
        } finally {
            gcQueue.gcFinished(p);
        }
    }
    return result;
}
Also used : 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.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult)

Aggregations

GarbageCollectionResult (com.google.gerrit.common.data.GarbageCollectionResult)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 UseLocalDisk (com.google.gerrit.acceptance.UseLocalDisk)1 Project (com.google.gerrit.reviewdb.client.Project)1 ProjectControl (com.google.gerrit.server.project.ProjectControl)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