use of org.apache.airavata.gfac.core.monitor.JobStatusResult in project airavata by apache.
the class EmailBasedMonitor method processMessages.
private void processMessages(Message[] searchMessages) throws MessagingException {
List<Message> processedMessages = new ArrayList<>();
List<Message> unreadMessages = new ArrayList<>();
for (Message message : searchMessages) {
try {
JobStatusResult jobStatusResult = parse(message);
TaskContext taskContext = null;
if (jobStatusResult.getJobId() != null) {
taskContext = jobMonitorMap.get(jobStatusResult.getJobId());
} else {
log.info("Returned null for job id, message subject--> {}", message.getSubject());
}
if (taskContext == null) {
if (jobStatusResult.getJobName() != null) {
taskContext = jobMonitorMap.get(jobStatusResult.getJobName());
} else {
log.info("Returned null for job name, message subject --> {}", message.getSubject());
}
}
if (taskContext != null) {
process(jobStatusResult, taskContext);
processedMessages.add(message);
} else if (!jobStatusResult.isAuthoritative() && (new Date()).getTime() - message.getSentDate().getTime() > 1000 * 60 * 5) {
// marking old custom Airavata emails as read
processedMessages.add(message);
log.info("Marking old Airavata custom emails as read, message subject --> {}", message.getSubject());
} else {
// we can get JobExecutionContext null in multiple Gfac instances environment,
// where this job is not submitted by this Gfac instance hence we ignore this message.
unreadMessages.add(message);
// log.info("JobExecutionContext is not found for job Id " + jobStatusResult.getJobId());
}
} catch (AiravataException e) {
log.error("[EJM]: Error parsing email message =====================================>", e);
try {
writeEnvelopeOnError(message);
} catch (MessagingException e1) {
log.error("[EJM]: Error printing envelop of the email");
}
unreadMessages.add(message);
} catch (MessagingException e) {
log.error("[EJM]: Error while retrieving sender address from message : " + message.toString());
unreadMessages.add(message);
}
}
if (!processedMessages.isEmpty()) {
Message[] seenMessages = new Message[processedMessages.size()];
processedMessages.toArray(seenMessages);
try {
emailFolder.setFlags(seenMessages, new Flags(Flags.Flag.SEEN), true);
} catch (MessagingException e) {
if (!store.isConnected()) {
store.connect();
emailFolder.setFlags(seenMessages, new Flags(Flags.Flag.SEEN), true);
}
}
}
if (!unreadMessages.isEmpty()) {
Message[] unseenMessages = new Message[unreadMessages.size()];
unreadMessages.toArray(unseenMessages);
try {
emailFolder.setFlags(unseenMessages, new Flags(Flags.Flag.SEEN), false);
} catch (MessagingException e) {
if (!store.isConnected()) {
store.connect();
emailFolder.setFlags(unseenMessages, new Flags(Flags.Flag.SEEN), false);
// anyway we need to push this update.
flushUnseenMessages = unseenMessages;
} else {
// anyway we need to push this update.
flushUnseenMessages = unseenMessages;
}
}
}
}
use of org.apache.airavata.gfac.core.monitor.JobStatusResult in project airavata by apache.
the class AiravataCustomMailParser method parseEmail.
@Override
public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException {
JobStatusResult jobStatusResult = new JobStatusResult();
parseSubject(message.getSubject(), jobStatusResult);
return jobStatusResult;
}
use of org.apache.airavata.gfac.core.monitor.JobStatusResult in project airavata by apache.
the class LSFEmailParser method parseEmail.
@Override
public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException {
JobStatusResult jobStatusResult = new JobStatusResult();
parseContent(message, jobStatusResult);
return jobStatusResult;
}
use of org.apache.airavata.gfac.core.monitor.JobStatusResult in project airavata by apache.
the class PBSEmailParser method parseEmail.
@Override
public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException {
JobStatusResult jobStatusResult = new JobStatusResult();
// log.info("Parsing -> " + message.getSubject());
try {
String content = ((String) message.getContent());
parseContent(content, jobStatusResult);
} catch (IOException e) {
throw new AiravataException("[EJM]: Error while reading content of the email message");
}
return jobStatusResult;
}
use of org.apache.airavata.gfac.core.monitor.JobStatusResult in project airavata by apache.
the class SLURMEmailParser method parseEmail.
@Override
public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException {
JobStatusResult jobStatusResult = new JobStatusResult();
parseSubject(message.getSubject(), jobStatusResult);
return jobStatusResult;
}
Aggregations