adding Airavata custom email parser
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/3c453aea Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/3c453aea Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/3c453aea Branch: refs/heads/ansible-testing-0.17 Commit: 3c453aeac578f309b03ce37c91bab5518bce08b5 Parents: e34722a Author: scnakandala <[email protected]> Authored: Thu Mar 2 14:20:57 2017 -0500 Committer: scnakandala <[email protected]> Committed: Thu Mar 2 14:20:57 2017 -0500 ---------------------------------------------------------------------- .../email/parser/AiravataCustomMailParser.java | 72 ++++++++++++++++++++ 1 file changed, 72 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/3c453aea/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/AiravataCustomMailParser.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/AiravataCustomMailParser.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/AiravataCustomMailParser.java new file mode 100644 index 0000000..8810814 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/AiravataCustomMailParser.java @@ -0,0 +1,72 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ +package org.apache.airavata.gfac.monitor.email.parser; + +import org.apache.airavata.common.exception.AiravataException; +import org.apache.airavata.gfac.core.monitor.EmailParser; +import org.apache.airavata.gfac.core.monitor.JobStatusResult; +import org.apache.airavata.model.status.JobState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.mail.Message; +import javax.mail.MessagingException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class AiravataCustomMailParser implements EmailParser { + + private static final Logger log = LoggerFactory.getLogger(SLURMEmailParser.class); + + private static final String REGEX = "[a-zA-Z]*_[a-z]*=(?<" + JOBID + ">\\d*)[ ]*[a-zA-Z]*=(?<" + + JOBNAME + ">[a-zA-Z0-9-]*)[ ]*[a-zA-Z]*=(?<" + STATUS + ">[a-zA-Z]*).*"; + + public static final String COMPLETED = "COMPLETED"; + private static final Pattern pattern = Pattern.compile(REGEX); + + @Override + public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException { + JobStatusResult jobStatusResult = new JobStatusResult(); + parseSubject(message.getSubject(), jobStatusResult); + return jobStatusResult; + } + + private void parseSubject(String subject, JobStatusResult jobStatusResult) throws MessagingException { + Matcher matcher = pattern.matcher(subject); + if (matcher.find()) { + jobStatusResult.setJobId(matcher.group(JOBID)); + jobStatusResult.setJobName(matcher.group(JOBNAME)); + jobStatusResult.setState(getJobState(matcher.group(STATUS))); + } else { + log.error("[EJM]: No matched found for subject -> " + subject); + } + } + + private JobState getJobState(String state) { + switch (state.trim()) { + case COMPLETED: + return JobState.COMPLETE; + default: + log.error("[EJM]: Job State " + state + " isn't handle by Airavata custom parser"); + return JobState.UNKNOWN; + } + } +} \ No newline at end of file
