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");
}
}
}
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);
}
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;
}
Aggregations