use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.
the class LuceneProjectIndex method add.
@Override
void add(Document doc, Values<ProjectData> values) {
// Add separate DocValues field for the field that is needed for sorting.
FieldDef<ProjectData, ?> f = values.getField();
if (f == NAME) {
String value = (String) getOnlyElement(values.getValues());
doc.add(new SortedDocValuesField(NAME_SORT_FIELD, new BytesRef(value)));
}
super.add(doc, values);
}
use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.
the class InitIT method indexesAllProjectsAndAllUsers.
@Test
public void indexesAllProjectsAndAllUsers() throws Exception {
initSite();
try (ServerContext ctx = startServer()) {
ProjectIndexCollection projectIndex = ctx.getInjector().getInstance(ProjectIndexCollection.class);
Project.NameKey allProjects = ctx.getInjector().getInstance(AllProjectsName.class);
Project.NameKey allUsers = ctx.getInjector().getInstance(AllUsersName.class);
QueryOptions opts = QueryOptions.create(IndexConfig.createDefault(), 0, 1, ImmutableSet.of("name"));
Optional<ProjectData> allProjectsData = projectIndex.getSearchIndex().get(allProjects, opts);
assertThat(allProjectsData).isPresent();
Optional<ProjectData> allUsersData = projectIndex.getSearchIndex().get(allUsers, opts);
assertThat(allUsersData).isPresent();
}
}
use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.
the class QueryProjects method apply.
public List<ProjectInfo> apply() throws BadRequestException, MethodNotAllowedException {
if (Strings.isNullOrEmpty(query)) {
throw new BadRequestException("missing query field");
}
ProjectIndex searchIndex = indexes.getSearchIndex();
if (searchIndex == null) {
throw new MethodNotAllowedException("no project index");
}
ProjectQueryProcessor queryProcessor = queryProcessorProvider.get();
if (start != 0) {
queryProcessor.setStart(start);
}
if (limit != 0) {
queryProcessor.setUserProvidedLimit(limit);
}
try {
QueryResult<ProjectData> result = queryProcessor.query(queryBuilder.parse(query));
List<ProjectData> pds = result.entities();
ArrayList<ProjectInfo> projectInfos = Lists.newArrayListWithCapacity(pds.size());
for (ProjectData pd : pds) {
projectInfos.add(json.format(pd.getProject()));
}
return projectInfos;
} catch (QueryParseException e) {
throw new BadRequestException(e.getMessage());
}
}
use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.
the class AllProjectsIndexer method reindexProjects.
private SiteIndexer.Result reindexProjects(ProjectIndex index, List<Project.NameKey> names, ProgressMonitor progress) {
progress.beginTask("Reindexing projects", names.size());
List<ListenableFuture<?>> futures = new ArrayList<>(names.size());
AtomicBoolean ok = new AtomicBoolean(true);
AtomicInteger done = new AtomicInteger();
AtomicInteger failed = new AtomicInteger();
Stopwatch sw = Stopwatch.createStarted();
for (Project.NameKey name : names) {
String desc = "project " + name;
ListenableFuture<?> future = executor.submit(() -> {
try {
projectCache.evict(name);
ProjectData projectData = projectCache.get(name).orElseThrow(illegalState(name)).toProjectData();
if (isFirstInsertForEntry.equals(IsFirstInsertForEntry.YES)) {
index.insert(projectData);
} else {
index.replace(projectData);
}
verboseWriter.println("Reindexed " + desc);
done.incrementAndGet();
} catch (Exception e) {
failed.incrementAndGet();
throw e;
}
return null;
});
addErrorListener(future, desc, progress, ok);
futures.add(future);
}
try {
Futures.successfulAsList(futures).get();
} catch (ExecutionException | InterruptedException e) {
logger.atSevere().withCause(e).log("Error waiting on project futures");
return SiteIndexer.Result.create(sw, false, 0, 0);
}
progress.endTask();
return SiteIndexer.Result.create(sw, ok.get(), done.get(), failed.get());
}
use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.
the class ProjectIndexerImpl method index.
@Override
public void index(Project.NameKey nameKey) {
Optional<ProjectState> projectState = projectCache.get(nameKey);
if (projectState.isPresent()) {
logger.atFine().log("Replace project %s in index", nameKey.get());
ProjectData projectData = projectState.get().toProjectData();
for (ProjectIndex i : getWriteIndexes()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Replacing project", Metadata.builder().projectName(nameKey.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.replace(projectData);
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to replace project %s in index version %d", nameKey.get(), i.getSchema().getVersion()), e);
}
}
fireProjectIndexedEvent(nameKey.get());
} else {
logger.atFine().log("Delete project %s from index", nameKey.get());
for (ProjectIndex i : getWriteIndexes()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Deleting project", Metadata.builder().projectName(nameKey.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.delete(nameKey);
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to delete project %s from index version %d", nameKey.get(), i.getSchema().getVersion()), e);
}
}
}
}
Aggregations