Search in sources :

Example 11 with AiravataException

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);
}
Also used : ResourceJobManagerType(org.apache.airavata.model.appcatalog.computeresource.ResourceJobManagerType) Address(javax.mail.Address) EmailParser(org.apache.airavata.gfac.core.monitor.EmailParser) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 12 with AiravataException

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");
}
Also used : FlagTerm(javax.mail.search.FlagTerm) Message(javax.mail.Message) MessagingException(javax.mail.MessagingException) Flags(javax.mail.Flags) SearchTerm(javax.mail.search.SearchTerm) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 13 with AiravataException

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");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 14 with AiravataException

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;
}
Also used : JobStatusResult(org.apache.airavata.gfac.core.monitor.JobStatusResult) IOException(java.io.IOException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 15 with AiravataException

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);
    }
}
Also used : TException(org.apache.thrift.TException) Message(org.apache.airavata.model.messaging.event.Message) TException(org.apache.thrift.TException) IOException(java.io.IOException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Aggregations

AiravataException (org.apache.airavata.common.exception.AiravataException)40 IOException (java.io.IOException)10 TException (org.apache.thrift.TException)8 GFacException (org.apache.airavata.gfac.core.GFacException)6 RegistryException (org.apache.airavata.registry.cpi.RegistryException)6 XmlElement (org.xmlpull.infoset.XmlElement)5 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)4 MessagingException (javax.mail.MessagingException)3 MessageContext (org.apache.airavata.messaging.core.MessageContext)3 Session (com.jcraft.jsch.Session)2 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Flags (javax.mail.Flags)2 Message (javax.mail.Message)2 EmailParser (org.apache.airavata.gfac.core.monitor.EmailParser)2