Search in sources :

Example 6 with ProjectData

use of com.google.gerrit.index.project.ProjectData in project gerrit by GerritCodeReview.

the class StalenessChecker method check.

/**
 * Returns a {@link StalenessCheckResult} with structured information about staleness of the
 * provided {@link com.google.gerrit.entities.Project.NameKey}.
 */
public StalenessCheckResult check(Project.NameKey project) {
    ProjectData projectData = projectCache.get(project).orElseThrow(illegalState(project)).toProjectData();
    ProjectIndex i = indexes.getSearchIndex();
    if (i == null) {
        return StalenessCheckResult.notStale();
    }
    Optional<FieldBundle> result = i.getRaw(project, QueryOptions.create(indexConfig, 0, 1, FIELDS));
    if (!result.isPresent()) {
        return StalenessCheckResult.stale("Document %s missing from index", project);
    }
    SetMultimap<Project.NameKey, RefState> indexedRefStates = RefState.parseStates(result.get().getValue(ProjectField.REF_STATE));
    SetMultimap<Project.NameKey, RefState> currentRefStates = MultimapBuilder.hashKeys().hashSetValues().build();
    projectData.tree().stream().filter(p -> p.getProject().getConfigRefState() != null).forEach(p -> currentRefStates.put(p.getProject().getNameKey(), RefState.create(RefNames.REFS_CONFIG, p.getProject().getConfigRefState())));
    if (currentRefStates.equals(indexedRefStates)) {
        return StalenessCheckResult.notStale();
    }
    return StalenessCheckResult.stale("Document has unexpected ref states (%s != %s)", currentRefStates, indexedRefStates);
}
Also used : RefState(com.google.gerrit.index.RefState) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) ImmutableSet(com.google.common.collect.ImmutableSet) IndexConfig(com.google.gerrit.index.IndexConfig) ProjectCache(com.google.gerrit.server.project.ProjectCache) MultimapBuilder(com.google.common.collect.MultimapBuilder) ProjectField(com.google.gerrit.index.project.ProjectField) Inject(com.google.inject.Inject) QueryOptions(com.google.gerrit.index.QueryOptions) ProjectData(com.google.gerrit.index.project.ProjectData) SetMultimap(com.google.common.collect.SetMultimap) StalenessCheckResult(com.google.gerrit.server.index.StalenessCheckResult) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ProjectIndexCollection(com.google.gerrit.index.project.ProjectIndexCollection) Project(com.google.gerrit.entities.Project) RefNames(com.google.gerrit.entities.RefNames) FieldBundle(com.google.gerrit.index.query.FieldBundle) Optional(java.util.Optional) RefState(com.google.gerrit.index.RefState) FieldBundle(com.google.gerrit.index.query.FieldBundle) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) 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