Skip to content

Commit

Permalink
Get emails from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoTavares committed Jun 18, 2024
1 parent 992bcee commit fd16159
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
49 changes: 16 additions & 33 deletions cuebot/src/main/java/com/imageworks/spcue/service/EmailSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.apache.velocity.app.VelocityEngine;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
Expand All @@ -59,19 +61,21 @@ public class EmailSupport {
private MailSender mailSender;
private JobManager jobManager;

private Properties opencueProperties;
@Autowired
private Environment env;

private String emailDomain;
private String emailFromAddress;
private String[] emailCcAddresses;

private Map<String, byte[]> imageMap;

private static final Logger logger = LogManager.getLogger(EmailSupport.class);

public EmailSupport() {

/*
* The OpenCue configuration file which we need to find the email template.
*/
opencueProperties = getOpenCueProperties();

this.emailDomain = env.getProperty("email.domain", "opencue.io");
this.emailFromAddress = env.getProperty("email.from.address", "opencue-noreply@opencue.io");
this.emailCcAddresses = env.getProperty("email.cc.addresses", "").split(",");
}

private static void loadImage(Map<String, byte[]> map, String path) {
Expand Down Expand Up @@ -141,9 +145,9 @@ private static void loadImage(Map<String, byte[]> map, String path) {
public void reportLaunchError(JobSpec spec, Throwable t) {

SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(String.format("%s@imageworks.com", spec.getUser()));
msg.setFrom("middle-tier@imageworks.com");
msg.setCc("middle-tier@imageworks.com");
msg.setTo(String.format("%s@%s", spec.getUser(), this.emailDomain));
msg.setFrom(this.emailFromAddress);
msg.setCc(this.emailCcAddresses);
msg.setSubject("Failed to launch OpenCue job.");

StringBuilder sb = new StringBuilder(131072);
Expand Down Expand Up @@ -175,7 +179,7 @@ public void reportJobComment(JobInterface job, CommentDetail c, String[] emails)

SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(emails);
msg.setFrom("opencue-noreply@imageworks.com");
msg.setFrom(this.emailFromAddress);
msg.setSubject("New comment on " + job.getName());

StringBuilder sb = new StringBuilder(8096);
Expand All @@ -197,25 +201,6 @@ public void sendMessage(SimpleMailMessage message) {
}
}

public Properties getOpenCueProperties() {

// get the input stream of the properties file
InputStream in = EmailSupport.class.getClassLoader()
.getResourceAsStream("opencue.properties");

Properties props = new java.util.Properties();
try {
props.load(in);
} catch (IOException e) {
props = new Properties();
props.setProperty( "resource.loader", "file" );
props.setProperty("class.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.FileResourceLoader" );
props.setProperty("file.resource.loader.path", "/opt/opencue/webapps/spcue");
}
return props;
}

public void sendShutdownEmail(JobInterface job) {

JobDetail d = jobManager.getJobDetail(job.getJobId());
Expand Down Expand Up @@ -294,8 +279,6 @@ public void sendShutdownEmail(JobInterface job) {

subject = status + subject;

String from = "opencue-noreply@imageworks.com";

BufferedWriter output = null;
File file = null;
if (shouldCreateFile){
Expand Down Expand Up @@ -328,7 +311,7 @@ public void sendShutdownEmail(JobInterface job) {

for (String email : d.email.split(",")) {
try {
CueUtil.sendmail(email, from, subject, new StringBuilder(w.toString()), imageMap, file);
CueUtil.sendmail(email, this.emailFromAddress, subject, new StringBuilder(w.toString()), imageMap, file);
} catch (Exception e) {
// just log and eat if the mail server is down or something
// of that nature.
Expand Down
8 changes: 8 additions & 0 deletions cuebot/src/test/resources/opencue.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
cue.proxy = tcp -h cuetest01-vm -p 9019 -t 10000:tcp -h cuetest02-vm -p 9019 -t 10000:tcp -h cuetest03-vm -p 9019 -t 10000
spring.velocity.checkTemplateLocation=false

# A domain to attach to usernames to send job completition emails
# eg: job_user=jon -> email-to: jon@opencue.io
email.domain=opencue.io
# An email address to use as From for cuebot emails
email.from.address=opencue-noreply@opencue.io
# A comma-separated list of emails to be cc'ed on maintenance communications
email.cc.addresses=dev-team@opencue.io

grpc.cue_port=8453
grpc.rqd_server_port=${CUEBOT_GRPC_RQD_SERVER_PORT:50051}
grpc.max_message_bytes=104857600
Expand Down

0 comments on commit fd16159

Please sign in to comment.