Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time display emails #902

Merged
merged 6 commits into from Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.TimeZone;

import javax.validation.Valid;
import javax.validation.constraints.Max;
Expand Down Expand Up @@ -76,6 +77,8 @@ public class SingularityConfiguration extends Configuration {
@Min(value = 1, message = "Must be positive and non-zero")
private int defaultBounceExpirationMinutes = 60;

private String mailerDatePattern = "MMM dd h:mm:ss a zzz";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should move these mailer* config fields into SMTPConfiguration


@NotNull
private SlavePlacement defaultSlavePlacement = SlavePlacement.GREEDY;

Expand Down Expand Up @@ -185,6 +188,8 @@ public class SingularityConfiguration extends Configuration {

private long startNewReconcileEverySeconds = TimeUnit.MINUTES.toSeconds(10);

private TimeZone mailerTimeZone = TimeZone.getTimeZone("UTC");

@JsonProperty("ui")
@Valid
private UIConfiguration uiConfiguration = new UIConfiguration();
Expand Down Expand Up @@ -955,4 +960,20 @@ public Optional<Integer> getMaxStaleTasksPerRequestInZkWhenNoDatabase() {
public void setMaxStaleTasksPerRequestInZkWhenNoDatabase(Optional<Integer> maxStaleTasksPerRequestInZkWhenNoDatabase) {
this.maxStaleTasksPerRequestInZkWhenNoDatabase = maxStaleTasksPerRequestInZkWhenNoDatabase;
}

public String getMailerDatePattern() {
return mailerDatePattern;
}

public void setMailerDatePattern(String mailerDatePattern) {
this.mailerDatePattern = mailerDatePattern;
}

public TimeZone getMailerTimeZone() {
return mailerTimeZone;
}

public void setMailerTimeZone(TimeZone mailerTimeZone) {
this.mailerTimeZone = mailerTimeZone;
}
}
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;

import org.apache.commons.lang3.text.WordUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
Expand All @@ -29,7 +30,6 @@ public class MailTemplateHelpers {

private static final Logger LOG = LoggerFactory.getLogger(MailTemplateHelpers.class);

private static final String TASK_DATE_PATTERN = "MMM dd HH:mm:ss";
private static final String TASK_LINK_FORMAT = "%s/task/%s";
private static final String REQUEST_LINK_FORMAT = "%s/request/%s";
private static final String LOG_LINK_FORMAT = "%s/task/%s/tail/%s";
Expand All @@ -38,9 +38,13 @@ public class MailTemplateHelpers {

private final Optional<String> uiBaseUrl;
private final Optional<SMTPConfiguration> smtpConfiguration;
private final String taskDatePattern;
private final TimeZone timeZone;

@Inject
public MailTemplateHelpers(SandboxManager sandboxManager, SingularityConfiguration singularityConfiguration) {
this.taskDatePattern = singularityConfiguration.getMailerDatePattern();
this.timeZone = singularityConfiguration.getMailerTimeZone();
this.uiBaseUrl = singularityConfiguration.getUiConfiguration().getBaseUrl();
this.sandboxManager = sandboxManager;
this.smtpConfiguration = singularityConfiguration.getSmtpConfiguration();
Expand All @@ -52,7 +56,7 @@ public List<SingularityMailTaskHistoryUpdate> getJadeTaskHistory(Collection<Sing
for (SingularityTaskHistoryUpdate taskUpdate : taskHistory) {
output.add(
new SingularityMailTaskHistoryUpdate(
DateFormatUtils.formatUTC(taskUpdate.getTimestamp(), TASK_DATE_PATTERN),
DateFormatUtils.format(taskUpdate.getTimestamp(), taskDatePattern, timeZone),
WordUtils.capitalize(taskUpdate.getTaskState().getDisplayName()),
taskUpdate.getStatusMessage().or("")));
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -400,7 +401,7 @@ private void setupExpireFormat(Map<String, Object> additionalProperties, Optiona
final long now = System.currentTimeMillis();
final long future = now + durationMillis.get();

additionalProperties.put("expireFormat", new Date(future));
additionalProperties.put("expireFormat", DateFormatUtils.format(new Date(future), configuration.getMailerDatePattern(), configuration.getMailerTimeZone()));
}

public void sendRequestPausedMail(SingularityRequest request, Optional<SingularityPauseRequest> pauseRequest, Optional<String> user) {
Expand Down
Expand Up @@ -43,9 +43,9 @@ html
else
| #{ requestId } will not run again until it is manually unpaused.
if killTasks
| Existing tasks will be killed.
| Existing tasks will be killed.
else
| Existing tasks will not be killed.
| Existing tasks will not be killed.
else if requestUnpaused
| #{ requestId } will begin scheduling and executing tasks immediately.
else if requestScaled
Expand Down