Search in sources :

Example 11 with CeTaskSubmit

use of org.sonar.ce.queue.CeTaskSubmit in project sonarqube by SonarSource.

the class AsyncIssueIndexingImpl method triggerOnIndexCreation.

@Override
public void triggerOnIndexCreation() {
    try (DbSession dbSession = dbClient.openSession(false)) {
        // remove already existing indexation task, if any
        removeExistingIndexationTasks(dbSession);
        dbClient.branchDao().updateAllNeedIssueSync(dbSession);
        List<BranchDto> branchInNeedOfIssueSync = dbClient.branchDao().selectBranchNeedingIssueSync(dbSession);
        LOG.info("{} branch found in need of issue sync.", branchInNeedOfIssueSync.size());
        if (branchInNeedOfIssueSync.isEmpty()) {
            return;
        }
        List<String> projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(Collectors.toList());
        LOG.info("{} projects found in need of issue sync.", projectUuids.size());
        sortProjectUuids(dbSession, projectUuids);
        Map<String, List<BranchDto>> branchesByProject = branchInNeedOfIssueSync.stream().collect(Collectors.groupingBy(BranchDto::getProjectUuid));
        List<CeTaskSubmit> tasks = new ArrayList<>();
        for (String projectUuid : projectUuids) {
            List<BranchDto> branches = branchesByProject.get(projectUuid);
            for (BranchDto branch : branches) {
                tasks.add(buildTaskSubmit(branch));
            }
        }
        ceQueue.massSubmit(tasks);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit)

Aggregations

CeTaskSubmit (org.sonar.ce.queue.CeTaskSubmit)11 Test (org.junit.Test)9 CeTask (org.sonar.ce.queue.CeTask)5 ComponentDto (org.sonar.db.component.ComponentDto)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DbSession (org.sonar.db.DbSession)3 BranchDto (org.sonar.db.component.BranchDto)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatCode (org.assertj.core.api.Assertions.assertThatCode)2 Assertions.tuple (org.assertj.core.api.Assertions.tuple)2 Description (org.hamcrest.Description)2 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)2 Before (org.junit.Before)2