use of com.google.gerrit.entities.Project 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);
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class DiffOperationsImpl method getModifiedFiles.
private ImmutableMap<String, FileDiffOutput> getModifiedFiles(DiffParameters diffParams, DiffOptions diffOptions) throws DiffNotAvailableException {
try {
Project.NameKey project = diffParams.project();
ObjectId newCommit = diffParams.newCommit();
ObjectId oldCommit = diffParams.baseCommit();
ComparisonType cmp = diffParams.comparisonType();
ImmutableList<ModifiedFile> modifiedFiles = modifiedFilesCache.get(createModifiedFilesKey(project, oldCommit, newCommit));
List<FileDiffCacheKey> fileCacheKeys = new ArrayList<>();
fileCacheKeys.add(createFileDiffCacheKey(project, oldCommit, newCommit, COMMIT_MSG, DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, /* whitespace= */
null));
if (cmp.isAgainstAutoMerge() || isMergeAgainstParent(cmp, project, newCommit)) {
fileCacheKeys.add(createFileDiffCacheKey(project, oldCommit, newCommit, MERGE_LIST, DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, /*whitespace = */
null));
}
if (diffParams.skipFiles() == null) {
modifiedFiles.stream().map(entity -> createFileDiffCacheKey(project, oldCommit, newCommit, entity.newPath().isPresent() ? entity.newPath().get() : entity.oldPath().get(), DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, /* whitespace= */
null)).forEach(fileCacheKeys::add);
}
return getModifiedFilesForKeys(fileCacheKeys, diffOptions);
} catch (IOException e) {
throw new DiffNotAvailableException(e);
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectConfig method getCacheable.
/**
* Returns an immutable, thread-safe representation of this object that can be cached.
*/
public CachedProjectConfig getCacheable() {
CachedProjectConfig.Builder builder = CachedProjectConfig.builder().setProject(project).setAccountsSection(accountsSection).setBranchOrderSection(Optional.ofNullable(branchOrderSection)).setMimeTypes(mimeTypes).setRulesId(Optional.ofNullable(rulesId)).setRevision(Optional.ofNullable(getRevision())).setMaxObjectSizeLimit(maxObjectSizeLimit).setCheckReceivedObjects(checkReceivedObjects).setExtensionPanelSections(extensionPanelSections);
groupList.byUUID().values().forEach(g -> builder.addGroup(g));
contributorAgreements.values().forEach(c -> builder.addContributorAgreement(c));
notifySections.values().forEach(n -> builder.addNotifySection(n));
subscribeSections.values().forEach(s -> builder.addSubscribeSection(s));
commentLinkSections.values().forEach(c -> builder.addCommentLinkSection(c));
labelSections.values().forEach(l -> builder.addLabelSection(l));
submitRequirementSections.values().forEach(sr -> builder.addSubmitRequirementSection(sr));
pluginConfigs.entrySet().forEach(c -> builder.addPluginConfig(c.getKey(), c.getValue().toText()));
projectLevelConfigs.entrySet().forEach(c -> builder.addProjectLevelConfig(c.getKey(), c.getValue().toText()));
if (projectName.equals(allProjectsName)) {
// Filter out permissions that aren't allowed to be set on All-Projects
accessSections.values().forEach(a -> {
List<Permission.Builder> copy = new ArrayList<>();
for (Permission p : a.getPermissions()) {
if (Permission.canBeOnAllProjects(a.getName(), p.getName())) {
copy.add(p.toBuilder());
}
}
AccessSection section = AccessSection.builder(a.getName()).modifyPermissions(permissions -> permissions.addAll(copy)).build();
builder.addAccessSection(section);
});
} else {
accessSections.values().forEach(a -> builder.addAccessSection(a));
}
return builder.build();
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectCacheWarmer method start.
@Override
public void start() {
int cpus = Runtime.getRuntime().availableProcessors();
if (config.getBoolean("cache", "projects", "loadOnStartup", false)) {
ExecutorService pool = new LoggingContextAwareExecutorService(new ScheduledThreadPoolExecutor(config.getInt("cache", "projects", "loadThreads", cpus), new ThreadFactoryBuilder().setNameFormat("ProjectCacheLoader-%d").build()));
Thread scheduler = new Thread(() -> {
for (Project.NameKey name : cache.all()) {
pool.execute(() -> {
Optional<ProjectState> project = cache.get(name);
if (!project.isPresent()) {
throw new IllegalStateException("race while traversing projects. got " + name + " when loading all projects, but can't load it now");
}
});
}
pool.shutdown();
try {
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
logger.atInfo().log("Finished loading project cache");
} catch (InterruptedException e) {
logger.atWarning().log("Interrupted while waiting for project cache to load");
}
});
scheduler.setName("ProjectCacheWarmer");
scheduler.setDaemon(true);
logger.atInfo().log("Loading project cache");
scheduler.start();
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectCreator method createProject.
public ProjectState createProject(CreateProjectArgs args) throws BadRequestException, ResourceConflictException, IOException, ConfigInvalidException {
final Project.NameKey nameKey = args.getProject();
try {
final String head = args.permissionsOnly ? RefNames.REFS_CONFIG : args.branch.get(0);
Status status = repoManager.getRepositoryStatus(nameKey);
if (!status.equals(Status.NON_EXISTENT)) {
throw new RepositoryExistsException(nameKey, "Repository status: " + status);
}
try (Repository repo = repoManager.createRepository(nameKey)) {
RefUpdate u = repo.updateRef(Constants.HEAD);
u.disableRefLog();
u.link(head);
createProjectConfig(args);
if (!args.permissionsOnly && args.createEmptyCommit) {
createEmptyCommits(repo, nameKey, args.branch);
}
fire(nameKey, head);
return projectCache.get(nameKey).orElseThrow(illegalState(nameKey));
}
} catch (RepositoryExistsException e) {
throw new ResourceConflictException("Cannot create " + nameKey.get() + " because the name is already occupied by another project.", e);
} catch (RepositoryNotFoundException badName) {
throw new BadRequestException("invalid project name: " + nameKey, badName);
}
}
Aggregations