Search in sources :

Example 1 with ProjectData

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);
}
Also used : SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) ProjectData(com.google.gerrit.index.project.ProjectData) BytesRef(org.apache.lucene.util.BytesRef)

Example 2 with ProjectData

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();
    }
}
Also used : Project(com.google.gerrit.entities.Project) ProjectIndexCollection(com.google.gerrit.index.project.ProjectIndexCollection) QueryOptions(com.google.gerrit.index.QueryOptions) ProjectData(com.google.gerrit.index.project.ProjectData) StandaloneSiteTest(com.google.gerrit.acceptance.StandaloneSiteTest) Test(org.junit.Test)

Example 3 with ProjectData

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());
    }
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) ProjectQueryProcessor(com.google.gerrit.server.query.project.ProjectQueryProcessor) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ProjectData(com.google.gerrit.index.project.ProjectData) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 4 with ProjectData

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());
}
Also used : ArrayList(java.util.ArrayList) Stopwatch(com.google.common.base.Stopwatch) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.google.gerrit.entities.Project) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExecutionException(java.util.concurrent.ExecutionException) ProjectData(com.google.gerrit.index.project.ProjectData)

Example 5 with ProjectData

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);
            }
        }
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) StorageException(com.google.gerrit.exceptions.StorageException) ProjectData(com.google.gerrit.index.project.ProjectData)

Aggregations

ProjectData (com.google.gerrit.index.project.ProjectData)6 Project (com.google.gerrit.entities.Project)3 ProjectIndex (com.google.gerrit.index.project.ProjectIndex)3 QueryOptions (com.google.gerrit.index.QueryOptions)2 ProjectIndexCollection (com.google.gerrit.index.project.ProjectIndexCollection)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 SetMultimap (com.google.common.collect.SetMultimap)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 StandaloneSiteTest (com.google.gerrit.acceptance.StandaloneSiteTest)1 RefNames (com.google.gerrit.entities.RefNames)1 StorageException (com.google.gerrit.exceptions.StorageException)1 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 IndexConfig (com.google.gerrit.index.IndexConfig)1 RefState (com.google.gerrit.index.RefState)1 ProjectField (com.google.gerrit.index.project.ProjectField)1 FieldBundle (com.google.gerrit.index.query.FieldBundle)1