use of com.hubspot.singularity.config.SMTPConfiguration in project Singularity by HubSpot.
the class MailTemplateHelpers method getLogErrorRegex.
private Optional<Pattern> getLogErrorRegex(final Optional<SingularityTask> task) {
Optional<String> maybeRegex;
SMTPConfiguration configuration = smtpConfiguration.get();
if (task.isPresent() && task.get().getTaskRequest().getRequest().getTaskLogErrorRegex().isPresent() && !task.get().getTaskRequest().getRequest().getTaskLogErrorRegex().get().equals("")) {
maybeRegex = task.get().getTaskRequest().getRequest().getTaskLogErrorRegex();
} else {
maybeRegex = configuration.getTaskLogErrorRegex();
}
if (!maybeRegex.isPresent()) {
LOG.trace("No task log error regex provided.");
return Optional.absent();
}
String regex = maybeRegex.get();
Boolean caseSensitive;
if (task.isPresent() && task.get().getTaskRequest().getRequest().getTaskLogErrorRegexCaseSensitive().isPresent()) {
caseSensitive = task.get().getTaskRequest().getRequest().getTaskLogErrorRegexCaseSensitive().get();
} else if (configuration.getTaskLogErrorRegexCaseSensitive().isPresent()) {
caseSensitive = configuration.getTaskLogErrorRegexCaseSensitive().get();
} else {
caseSensitive = true;
}
try {
if (caseSensitive) {
return Optional.of(Pattern.compile(regex));
} else {
return Optional.of(Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE));
}
} catch (PatternSyntaxException e) {
LOG.error("Invalid task log error regex supplied: \"{}\". Received exception: {}", regex, e);
return Optional.absent();
}
}
use of com.hubspot.singularity.config.SMTPConfiguration in project Singularity by HubSpot.
the class SingularitySmtpSender method sendMail.
private void sendMail(List<String> toList, List<String> ccList, String subject, String body) {
final SMTPConfiguration smtpConfiguration = maybeSmtpConfiguration.get();
boolean useAuth = false;
if (smtpConfiguration.getUsername().isPresent() && smtpConfiguration.getPassword().isPresent()) {
useAuth = true;
} else if (smtpConfiguration.getUsername().isPresent() || smtpConfiguration.getPassword().isPresent()) {
LOG.warn("Not using smtp authentication because username ({}) or password ({}) was not present", smtpConfiguration.getUsername().isPresent(), smtpConfiguration.getPassword().isPresent());
}
try {
final Session session = createSession(smtpConfiguration, useAuth);
MimeMessage message = new MimeMessage(session);
Address[] toArray = getAddresses(toList);
message.addRecipients(RecipientType.TO, toArray);
if (!ccList.isEmpty()) {
Address[] ccArray = getAddresses(ccList);
message.addRecipients(RecipientType.CC, ccArray);
}
message.setFrom(new InternetAddress(smtpConfiguration.getFrom()));
message.setSubject(MimeUtility.encodeText(subject, "utf-8", null));
message.setContent(body, "text/html; charset=utf-8");
LOG.trace("Sending a message to {} - {}", Arrays.toString(toArray), getEmailLogFormat(toList, subject));
Transport.send(message);
} catch (Throwable t) {
LOG.warn("Unable to send message {}", getEmailLogFormat(toList, subject), t);
exceptionNotifier.notify(String.format("Unable to send message (%s)", t.getMessage()), t, ImmutableMap.of("subject", subject));
}
}
use of com.hubspot.singularity.config.SMTPConfiguration in project Singularity by HubSpot.
the class SingularityTestModule method getSingularityConfigurationForTestingServer.
private static SingularityConfiguration getSingularityConfigurationForTestingServer(final TestingServer ts) {
SingularityConfiguration config = new SingularityConfiguration();
config.setLoadBalancerUri("test");
MesosConfiguration mc = new MesosConfiguration();
mc.setDefaultCpus(1);
mc.setDefaultMemory(128);
mc.setDefaultDisk(1024);
config.setMesosConfiguration(mc);
config.setSmtpConfiguration(new SMTPConfiguration());
ZooKeeperConfiguration zookeeperConfiguration = new ZooKeeperConfiguration();
zookeeperConfiguration.setQuorum(ts.getConnectString());
config.setZooKeeperConfiguration(zookeeperConfiguration);
config.setConsiderTaskHealthyAfterRunningForSeconds(0);
return config;
}
Aggregations