From: Jacek Date: Tue, 14 Sep 2021 13:05:42 +0000 (+0200) Subject: SONAR-15225 Cancelled tasks for indexations should be count as failures X-Git-Tag: 9.1.0.47736~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3e19b6036b1d3c84119c88f09c9e41d07f48fec0;p=sonarqube.git SONAR-15225 Cancelled tasks for indexations should be count as failures --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java index 0c9b277b638..613f000eb6d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java @@ -88,8 +88,8 @@ public class CeActivityDao implements Dao { return Optional.ofNullable(mapper(dbSession).selectLastByComponentUuidAndTaskType(componentUuid, taskType)); } - public boolean hasAnyFailedIssueSyncTask(DbSession dbSession) { - return mapper(dbSession).hasAnyFailedIssueSyncTask() > 0; + public boolean hasAnyFailedOrCancelledIssueSyncTask(DbSession dbSession) { + return mapper(dbSession).hasAnyFailedOrCancelledIssueSyncTask() > 0; } private static CeActivityMapper mapper(DbSession dbSession) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java index a52771f9a51..b6a2a00c1cb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java @@ -47,7 +47,7 @@ public interface CeActivityMapper { @CheckForNull CeActivityDto selectLastByComponentUuidAndTaskType(@Param("componentUuid") String componentUuid, @Param("taskType") String taskType); - short hasAnyFailedIssueSyncTask(); + short hasAnyFailedOrCancelledIssueSyncTask(); List selectByTaskType(@Param("taskType") String taskType); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml index cc24d1b5dab..17c222152dd 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml @@ -248,13 +248,13 @@ and ca.is_last = ${_true} - + select case when exists ( select ca.uuid from ce_activity ca inner join project_branches pb on ca.component_uuid = pb.uuid where ca.task_type = 'ISSUE_SYNC' - and ca.status = 'FAILED' + and ca.status in ('FAILED', 'CANCELED') and pb.need_issue_sync = ${_true} ) then 1 @@ -262,12 +262,12 @@ end - + - + from dual diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java index af602397115..870eacaea7b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java @@ -762,8 +762,8 @@ public class CeActivityDaoTest { } @Test - public void hasAnyFailedIssueSyncTask() { - assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse(); + public void hasAnyFailedOrCancelledIssueSyncTask() { + assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse(); insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS); insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED); @@ -779,31 +779,40 @@ public class CeActivityDaoTest { }); insert("TASK_4", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto2.getUuid(), projectDto2.getUuid(), SUCCESS); - assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse(); + assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse(); ProjectDto projectDto3 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> { }, p -> { }); insert("TASK_5", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto3.getUuid(), projectDto3.getUuid(), SUCCESS); - BranchDto projectBranch = db.components() + BranchDto projectBranch1 = db.components() .insertProjectBranch(projectDto3, branchDto -> branchDto.setNeedIssueSync(true)); - insert("TASK_6", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch.getUuid(), projectDto3.getUuid(), FAILED); + insert("TASK_6", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch1.getUuid(), projectDto3.getUuid(), FAILED); + + BranchDto projectBranch2 = db.components() + .insertProjectBranch(projectDto3, branchDto -> branchDto.setNeedIssueSync(true)); + + insert("TASK_7", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch2.getUuid(), projectDto3.getUuid(), CANCELED); // failed task and project branch still exists and need sync - assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isTrue(); + assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isTrue(); + + // assume branch has been re-analysed + db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch1.getUuid(), false); // assume branch has been re-analysed - db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch.getUuid(), false); + db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch2.getUuid(), false); - assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse(); + assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse(); // assume branch has been deleted - db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch.getUuid()); + db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch1.getUuid()); + db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch2.getUuid()); // associated branch does not exist, so there is no failures - either it has been deleted or purged or reanalysed - assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse(); + assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse(); } private CeActivityDto insert(String uuid, String type, @Nullable String mainComponentUuid, CeActivityDto.Status status) { diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java index 9633d2c4e75..4b233836b55 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndexSyncProgressChecker.java @@ -42,7 +42,7 @@ public class IssueIndexSyncProgressChecker { public IssueSyncProgress getIssueSyncProgress(DbSession dbSession) { int completed = dbClient.branchDao().countByNeedIssueSync(dbSession, false); - boolean hasFailures = dbClient.ceActivityDao().hasAnyFailedIssueSyncTask(dbSession); + boolean hasFailures = dbClient.ceActivityDao().hasAnyFailedOrCancelledIssueSyncTask(dbSession); boolean isCompleted = !dbClient.ceQueueDao().hasAnyIssueSyncTaskPendingOrInProgress(dbSession); int total = dbClient.branchDao().countAll(dbSession); return new IssueSyncProgress(isCompleted, completed, total, hasFailures); diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 2af634fa6ae..6dbc9287cc6 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -4119,7 +4119,7 @@ indexation.progression_with_error={0}% complete with some {link}. indexation.progression_with_error.link=tasks failing indexation.completed=All project data has been reloaded. indexation.completed_with_error=SonarQube completed the reload of project data. Some {link} causing some projects to remain unavailable. -indexation.completed_with_error.link=tasks failed +indexation.completed_with_error.link=tasks failed or cancelled indexation.admin_link=See {link} for more information. indexation.page_unavailable.title.issues=Issues page is temporarily unavailable indexation.page_unavailable.title.portfolios=Portfolios page is temporarily unavailable