From 2e316498a58c98f1c7f2f7ba017aa7608f8163b7 Mon Sep 17 00:00:00 2001 From: Whitney Sorenson Date: Mon, 28 Dec 2015 17:02:26 +0000 Subject: [PATCH 1/2] fix issue with incorrect parsing of task status --- .../singularity/smtp/SingularityMailer.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java b/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java index 8c88e6f906..8a4cf76e62 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java @@ -7,6 +7,8 @@ import java.util.Map; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.lang3.time.DurationFormatUtils; import org.slf4j.Logger; @@ -65,6 +67,8 @@ public class SingularityMailer implements Managed { private final Joiner adminJoiner; private final MailTemplateHelpers mailTemplateHelpers; + private final static Pattern TASK_STATUS_BY_PATTERN = Pattern.compile("(\\w+) by \\w+"); + @Inject public SingularityMailer( SingularitySmtpSender smtpSender, @@ -155,13 +159,21 @@ private void populateTaskEmailProperties(Map templateProperties, templateProperties.put("taskRan", mailTemplateHelpers.didTaskRun(taskHistory)); } - private Optional getTaskCleanupTypefromSingularityTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate) { + private static Optional getTaskCleanupTypefromSingularityTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate) { if (!taskHistoryUpdate.getStatusMessage().isPresent()) { return Optional.absent(); } + String taskCleanupTypeMsg = taskHistoryUpdate.getStatusMessage().get(); + + Matcher matcher = TASK_STATUS_BY_PATTERN.matcher(taskCleanupTypeMsg); + + if (matcher.find()) { + taskCleanupTypeMsg = matcher.group(1); + } + try { - return Optional.of(TaskCleanupType.valueOf(taskHistoryUpdate.getStatusMessage().get())); + return Optional.of(TaskCleanupType.valueOf(taskCleanupTypeMsg.toUpperCase())); } catch (IllegalArgumentException iae) { LOG.warn("Couldn't parse TaskCleanupType from update {}", taskHistoryUpdate); return Optional.absent(); From 6bede3bbab0b62cc8bf3ba564b5177166805d270 Mon Sep 17 00:00:00 2001 From: Whitney Sorenson Date: Mon, 28 Dec 2015 17:30:30 +0000 Subject: [PATCH 2/2] check style happy --- .../java/com/hubspot/singularity/smtp/SingularityMailer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java b/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java index 8a4cf76e62..1fef128bf7 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/smtp/SingularityMailer.java @@ -67,7 +67,7 @@ public class SingularityMailer implements Managed { private final Joiner adminJoiner; private final MailTemplateHelpers mailTemplateHelpers; - private final static Pattern TASK_STATUS_BY_PATTERN = Pattern.compile("(\\w+) by \\w+"); + private static final Pattern TASK_STATUS_BY_PATTERN = Pattern.compile("(\\w+) by \\w+"); @Inject public SingularityMailer(