Search in sources :

Example 1 with ReportAnalysisFailureNotification

use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification in project sonarqube by SonarSource.

the class ReportAnalysisFailureNotificationExecutionListener method onEnd.

@Override
public void onEnd(CeTask ceTask, CeActivityDto.Status status, Duration duration, @Nullable CeTaskResult taskResult, @Nullable Throwable error) {
    if (status == CeActivityDto.Status.SUCCESS) {
        return;
    }
    String projectUuid = ceTask.getComponent().map(CeTask.Component::getUuid).orElse(null);
    if (!CeTaskTypes.REPORT.equals(ceTask.getType()) || projectUuid == null) {
        return;
    }
    if (notificationService.hasProjectSubscribersForTypes(projectUuid, singleton(ReportAnalysisFailureNotification.class))) {
        try (DbSession dbSession = dbClient.openSession(false)) {
            ComponentDto projectDto = dbClient.componentDao().selectOrFailByUuid(dbSession, projectUuid);
            checkScopeAndQualifier(projectDto);
            CeActivityDto ceActivityDto = dbClient.ceActivityDao().selectByUuid(dbSession, ceTask.getUuid()).orElseThrow(() -> new RowNotFoundException(format("CeActivity with uuid '%s' not found", ceTask.getUuid())));
            ReportAnalysisFailureNotificationBuilder taskFailureNotification = buildNotification(ceActivityDto, projectDto, error);
            ReportAnalysisFailureNotification notification = taskFailureNotificationSerializer.toNotification(taskFailureNotification);
            notificationService.deliverEmails(singleton(notification));
            // compatibility with old API
            notificationService.deliver(notification);
        }
    }
}
Also used : DbSession(org.sonar.db.DbSession) ReportAnalysisFailureNotificationBuilder(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder) CeActivityDto(org.sonar.db.ce.CeActivityDto) RowNotFoundException(org.sonar.db.RowNotFoundException) ComponentDto(org.sonar.db.component.ComponentDto) CeTask(org.sonar.ce.task.CeTask) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification)

Example 2 with ReportAnalysisFailureNotification

use of org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification in project sonarqube by SonarSource.

the class ReportAnalysisFailureNotificationExecutionListenerTest method mockSerializer.

private ReportAnalysisFailureNotification mockSerializer() {
    ReportAnalysisFailureNotification notificationMock = mock(ReportAnalysisFailureNotification.class);
    when(serializer.toNotification(any(ReportAnalysisFailureNotificationBuilder.class))).thenReturn(notificationMock);
    return notificationMock;
}
Also used : ReportAnalysisFailureNotificationBuilder(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification)

Aggregations

ReportAnalysisFailureNotification (org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification)2 ReportAnalysisFailureNotificationBuilder (org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder)2 CeTask (org.sonar.ce.task.CeTask)1 DbSession (org.sonar.db.DbSession)1 RowNotFoundException (org.sonar.db.RowNotFoundException)1 CeActivityDto (org.sonar.db.ce.CeActivityDto)1 ComponentDto (org.sonar.db.component.ComponentDto)1