Skip to content

Commit

Permalink
Update email template
Browse files Browse the repository at this point in the history
  • Loading branch information
Samer-sef authored and DiegoTavares committed Jun 18, 2024
1 parent 184961c commit 992bcee
Show file tree
Hide file tree
Showing 52 changed files with 314 additions and 173 deletions.
115 changes: 67 additions & 48 deletions cuebot/src/main/java/com/imageworks/spcue/service/EmailSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@

package com.imageworks.spcue.service;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.*;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -64,7 +61,7 @@ public class EmailSupport {

private Properties opencueProperties;

private final Map<String, byte[]> imageMap;
private Map<String, byte[]> imageMap;

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

Expand All @@ -75,35 +72,6 @@ public EmailSupport() {
*/
opencueProperties = getOpenCueProperties();

Map<String, byte[]> map = new HashMap<String, byte[]>();

loadImage(map, "bar.png");
loadImage(map, "opencue.png");
loadImage(map, "fail.png");
loadImage(map, "frame.png");
loadImage(map, "graph_bar.png");
loadImage(map, "header.png");
loadImage(map, "html_bg.png");
loadImage(map, "logo.png");
loadImage(map, "memory.png");
loadImage(map, "play.png");
loadImage(map, "success.png");
loadImage(map, "services/comp.png");
loadImage(map, "services/default.png");
loadImage(map, "services/ginsu.png");
loadImage(map, "services/houdini.png");
loadImage(map, "services/katana.png");
loadImage(map, "services/maya.png");
loadImage(map, "services/mentalray.png");
loadImage(map, "services/nuke.png");
loadImage(map, "services/playblast.png");
loadImage(map, "services/prman.png");
loadImage(map, "services/shell.png");
loadImage(map, "services/simulation.png");
loadImage(map, "services/svea.png");
loadImage(map, "services/trinity.png");

imageMap = Collections.unmodifiableMap(map);
}

private static void loadImage(Map<String, byte[]> map, String path) {
Expand Down Expand Up @@ -169,6 +137,7 @@ private static void loadImage(Map<String, byte[]> map, String path) {
}
}


public void reportLaunchError(JobSpec spec, Throwable t) {

SimpleMailMessage msg = new SimpleMailMessage();
Expand Down Expand Up @@ -263,14 +232,28 @@ public void sendShutdownEmail(JobInterface job) {
ExecutionSummary exj = jobManager.getExecutionSummary(job);
FrameStateTotals jts = jobManager.getFrameStateTotals(job);

String status = "";
if (jts.total != jts.succeeded) {
status = "Failed ";
}
else {
status = "Succeeded ";
}

context.put("jobName", d.name);
context.put("jobStatus", status.toUpperCase());
context.put("deptName", d.deptName.toUpperCase());
context.put("showName", d.showName.toUpperCase());
context.put("totalLayers", d.totalLayers);
context.put("shotName", d.shot.toUpperCase());
context.put("totalFrames", String.format("%04d", jts.total));
context.put("succeededFrames", String.format("%04d", jts.succeeded));
context.put("failedFrames", String.format("%04d", jts.dead + jts.eaten + jts.waiting));
context.put("checkpointFrames", String.format("%04d", jts.checkpoint));
context.put("succeededFrames", jts.succeeded);
context.put("totalFrames", jts.total);
context.put("dependFrames", jts.depend);
context.put("deadFrames", jts.dead);
context.put("waitingFrames", jts.waiting);
context.put("eatenFrames", jts.eaten);
context.put("failedFrames", jts.dead + jts.eaten + jts.waiting);
context.put("checkpointFrames", jts.checkpoint);
context.put("maxRSS", String.format(Locale.ROOT, "%.1fGB",
exj.highMemoryKb / 1024.0 / 1024.0));
context.put("coreTime", String.format(Locale.ROOT, "%.1f",
Expand All @@ -281,35 +264,71 @@ public void sendShutdownEmail(JobInterface job) {
List<LayerDetail> layers = jobManager.getLayerDetails(job);
List<LayerStats> layerStats = new ArrayList<LayerStats>(layers.size());

boolean shouldCreateFile = false;

Map<String, byte[]> map = new HashMap<String, byte[]>();
loadImage(map, "opencue_logo.png");

for (LayerDetail layer: layers) {
if (layer.type.equals(LayerType.RENDER)) {
LayerStats stats = new LayerStats();
stats.setDetail(layer);
stats.setExecutionSummary(jobManager.getExecutionSummary(layer));
stats.setFrameStateTotals(jobManager.getFrameStateTotals(layer));
stats.setThreadStats(jobManager.getThreadStats(layer));
stats.setOutputs(jobManager.getLayerOutputs(layer));
stats.setOutputs(jobManager.getLayerOutputs(layer).stream().sorted().collect(Collectors.toList()));
layerStats.add(stats);
if(stats.getOutputs().size() > 3) shouldCreateFile = true;
if(!layer.services.isEmpty()) loadImage(map, "services/" + layer.services.toArray()[0] + ".png");
}
}

imageMap = Collections.unmodifiableMap(map);

context.put("layers", layerStats);

StringWriter w = new StringWriter();
t.merge(context, w);

String subject = "OpenCue Job " + d.getName();
if (jts.total != jts.succeeded) {
subject = "Failed " + subject;
}
else {
subject = "Succeeded " + subject;

subject = status + subject;

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

BufferedWriter output = null;
File file = null;
if (shouldCreateFile){
try {
logger.info("\n\n\n\nhouldCreateFile \n\n\n\n");
file = new File("my_outputs.txt");
output = new BufferedWriter(new FileWriter(file));
for (LayerDetail layer: layers) {
if (layer.type.equals(LayerType.RENDER)) {
List<String> sortedNames = jobManager
.getLayerOutputs(layer)
.stream()
.sorted()
.collect(Collectors.toList());
output.write(layer.name + "\n" + String.join("\n", sortedNames) + "\n" );
}
}
} catch ( IOException e ) {
e.printStackTrace();
} finally {
if ( output != null ) {
try {
output.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
}

String from = "middle-tier@imageworks.com";
for (String email : d.email.split(",")) {
try {
CueUtil.sendmail(email, from, subject, new StringBuilder(w.toString()), imageMap);
CueUtil.sendmail(email, from, 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: 7 additions & 1 deletion cuebot/src/main/java/com/imageworks/spcue/util/CueUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.imageworks.spcue.util;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
Expand Down Expand Up @@ -168,7 +169,7 @@ public static int findChunk(List<Integer> dependOnFrames, int dependErFrame) {
* @param body
* @param images
*/
public static void sendmail(String to, String from, String subject, StringBuilder body, Map<String, byte[]> images) {
public static void sendmail(String to, String from, String subject, StringBuilder body, Map<String, byte[]> images, File attachment) {
try {
Properties props = System.getProperties();
props.put("mail.smtp.host", CueUtil.smtpHost);
Expand Down Expand Up @@ -199,6 +200,11 @@ public static void sendmail(String to, String from, String subject, StringBuilde
imageBodyPart.setHeader("Content-ID", '<' + name + '>');
mimeMultipart.addBodyPart(imageBodyPart);
}
if (attachment != null && attachment.length() != 0){
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.attachFile(attachment);
mimeMultipart.addBodyPart(attachmentPart);
}

msg.setContent(mimeMultipart);
msg.setHeader("X-Mailer", "OpenCueMailer");
Expand Down
Loading

0 comments on commit 992bcee

Please sign in to comment.