diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-07-30 15:06:46 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-08-02 20:21:35 +0200 |
commit | 5a9d2364785090379ad5e59a78b061f9d8e2866e (patch) | |
tree | df110e470b95baa2dc633608d9e63c7b87a0b331 /server/sonar-server-common | |
parent | 3df6519965c9409e5e13de6bc0ed6a703863fd85 (diff) | |
download | sonarqube-5a9d2364785090379ad5e59a78b061f9d8e2866e.tar.gz sonarqube-5a9d2364785090379ad5e59a78b061f9d8e2866e.zip |
SONAR-11077 add statistics to CE SendIssueNotificationsStep
Diffstat (limited to 'server/sonar-server-common')
2 files changed, 16 insertions, 12 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationService.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationService.java index 754380cbbae..56a5794dd20 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationService.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationService.java @@ -59,7 +59,7 @@ public class NotificationService { this(dbClient, new NotificationDispatcher[0]); } - public void deliver(Notification notification) { + public int deliver(Notification notification) { SetMultimap<String, NotificationChannel> recipients = HashMultimap.create(); for (NotificationDispatcher dispatcher : dispatchers) { NotificationDispatcher.Context context = new ContextImpl(recipients); @@ -70,23 +70,27 @@ public class NotificationService { LOG.warn(String.format("Unable to dispatch notification %s using %s", notification, dispatcher), e); } } - dispatch(notification, recipients); + return dispatch(notification, recipients); } - private static void dispatch(Notification notification, SetMultimap<String, NotificationChannel> recipients) { + private static int dispatch(Notification notification, SetMultimap<String, NotificationChannel> recipients) { + int count = 0; for (Map.Entry<String, Collection<NotificationChannel>> entry : recipients.asMap().entrySet()) { String username = entry.getKey(); Collection<NotificationChannel> userChannels = entry.getValue(); LOG.debug("For user {} via {}", username, userChannels); for (NotificationChannel channel : userChannels) { try { - channel.deliver(notification, username); + if (channel.deliver(notification, username)) { + count++; + } } catch (Exception e) { // catch all exceptions in order to deliver via other channels LOG.warn("Unable to deliver notification " + notification + " for user " + username + " via " + channel, e); } } } + return count; } @VisibleForTesting diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java index 671a507ac83..87235eecceb 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java @@ -95,17 +95,18 @@ public class EmailNotificationChannel extends NotificationChannel { } @Override - public void deliver(Notification notification, String username) { + public boolean deliver(Notification notification, String username) { User user = findByLogin(username); if (user == null || StringUtils.isBlank(user.email())) { LOG.debug("User does not exist or has no email: {}", username); - return; + return false; } EmailMessage emailMessage = format(notification); if (emailMessage != null) { emailMessage.setTo(user.email()); - deliver(emailMessage); + return deliver(emailMessage); } + return false; } @CheckForNull @@ -127,18 +128,17 @@ public class EmailNotificationChannel extends NotificationChannel { return null; } - /** - * Visibility has been relaxed for tests. - */ - void deliver(EmailMessage emailMessage) { + boolean deliver(EmailMessage emailMessage) { if (StringUtils.isBlank(configuration.getSmtpHost())) { LOG.debug("SMTP host was not configured - email will not be sent"); - return; + return false; } try { send(emailMessage); + return true; } catch (EmailException e) { LOG.error("Unable to send email", e); + return false; } } |