use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.
the class EmailBasedMonitor method parse.
private JobStatusResult parse(Message message) throws MessagingException, AiravataException {
Address fromAddress = message.getFrom()[0];
String addressStr = fromAddress.toString();
ResourceJobManagerType jobMonitorType = getJobMonitorType(addressStr);
EmailParser emailParser = emailParserMap.get(jobMonitorType);
if (emailParser == null) {
throw new AiravataException("[EJM]: Un-handle resource job manager type: " + jobMonitorType.toString() + " for email monitoring --> " + addressStr);
}
return emailParser.parseEmail(message);
}
use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.
the class EmailBasedMonitor method run.
@Override
public void run() {
boolean quite = false;
while (!stopMonitoring && !ServerSettings.isStopAllThreads()) {
try {
session = Session.getDefaultInstance(properties);
store = session.getStore(storeProtocol);
store.connect(host, emailAddress, password);
emailFolder = store.getFolder(folderName);
// first time we search for all unread messages.
SearchTerm unseenBefore = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
while (!(stopMonitoring || ServerSettings.isStopAllThreads())) {
// sleep a bit - get a rest till job finishes
Thread.sleep(ServerSettings.getEmailMonitorPeriod());
if (jobMonitorMap.isEmpty()) {
if (!quite) {
log.info("[EJM]: Job Monitor Map is empty, no need to retrieve emails");
}
quite = true;
continue;
} else {
quite = false;
log.info("[EJM]: {} job/s in job monitor map", jobMonitorMap.size());
}
if (!store.isConnected()) {
store.connect();
emailFolder = store.getFolder(folderName);
}
log.info("[EJM]: Retrieving unseen emails");
emailFolder.open(Folder.READ_WRITE);
if (emailFolder.isOpen()) {
// flush if any message left in flushUnseenMessage
if (flushUnseenMessages != null && flushUnseenMessages.length > 0) {
try {
emailFolder.setFlags(flushUnseenMessages, new Flags(Flags.Flag.SEEN), false);
flushUnseenMessages = null;
} catch (MessagingException e) {
if (!store.isConnected()) {
store.connect();
emailFolder.setFlags(flushUnseenMessages, new Flags(Flags.Flag.SEEN), false);
flushUnseenMessages = null;
}
}
}
Message[] searchMessages = emailFolder.search(unseenBefore);
if (searchMessages == null || searchMessages.length == 0) {
log.info("[EJM]: No new email messages");
} else {
log.info("[EJM]: " + searchMessages.length + " new email/s received");
}
processMessages(searchMessages);
emailFolder.close(false);
}
}
} catch (MessagingException e) {
log.error("[EJM]: Couldn't connect to the store ", e);
} catch (InterruptedException e) {
log.error("[EJM]: Interrupt exception while sleep ", e);
} catch (AiravataException e) {
log.error("[EJM]: UnHandled arguments ", e);
} catch (Throwable e) {
log.error("[EJM]: Caught a throwable ", e);
} finally {
try {
emailFolder.close(false);
store.close();
} catch (MessagingException e) {
log.error("[EJM]: Store close operation failed, couldn't close store", e);
} catch (Throwable e) {
log.error("[EJM]: Caught a throwable while closing email store ", e);
}
}
}
log.info("[EJM]: Email monitoring daemon stopped");
}
use of org.apache.airavata.common.exception.AiravataException in project airavata by apache.
the class LSFEmailParser method parseContent.
private void parseContent(Message message, JobStatusResult jobStatusResult) throws MessagingException, AiravataException {
String subject = message.getSubject();
Pattern pattern = Pattern.compile(REGEX);
Matcher matcher = pattern.matcher(subject);
try {
if (matcher.find()) {
jobStatusResult.setJobId(matcher.group(JOBID));
jobStatusResult.setJobName(matcher.group(JOBNAME));
String content = (String) message.getContent();
jobStatusResult.setState(getJobState(matcher.group(STATUS), content));
} else {
log.error("[EJM]: No matched found for subject => \n" + subject);
}
} catch (IOException e) {
throw new AiravataException("[EJM]: Error while reading content of the email message");
}
}
use of org.apache.airavata.common.exception.AiravataException 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.common.exception.AiravataException in project airavata by apache.
the class RabbitMQPublisher method publish.
/**
* This method is used only for publishing DB Events
* @param messageContext object of message context which will include actual db event and other information
* @param routingKey
* @throws AiravataException
*/
@Override
public void publish(MessageContext messageContext, String routingKey) throws AiravataException {
try {
byte[] body = ThriftUtils.serializeThriftObject(messageContext.getEvent());
Message message = new Message();
message.setEvent(body);
message.setMessageId(messageContext.getMessageId());
message.setMessageType(messageContext.getType());
if (messageContext.getUpdatedTime() != null) {
message.setUpdatedTime(messageContext.getUpdatedTime().getTime());
}
// log.info("publish messageId:" + messageContext.getMessageId() + ", messageType:" + messageContext.getType() + ", to routingKey:" + routingKey);
byte[] messageBody = ThriftUtils.serializeThriftObject(message);
send(messageBody, routingKey);
} catch (TException e) {
String msg = "Error while deserializing the object";
log.error(msg, e);
throw new AiravataException(msg, e);
} catch (Exception e) {
String msg = "Error while sending to rabbitmq";
log.error(msg, e);
throw new AiravataException(msg, e);
}
}
Aggregations