airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: adding a new Email parser to handle SIU peculiar failed email state
Date Wed, 31 May 2017 15:38:12 GMT
Repository: airavata
Updated Branches:
  refs/heads/master df6cfd7d2 -> 0194c2cf0


adding a new Email parser to handle SIU peculiar failed email state


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/0194c2cf
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/0194c2cf
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/0194c2cf

Branch: refs/heads/master
Commit: 0194c2cf06a040b523ebbe0b794cfd23c1a7d4f6
Parents: df6cfd7
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Wed May 31 11:36:34 2017 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Wed May 31 11:38:06 2017 -0400

----------------------------------------------------------------------
 .../monitor/email/parser/LDSIUEmailParser.java  | 107 +++++++++++++++++++
 1 file changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/0194c2cf/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LDSIUEmailParser.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LDSIUEmailParser.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LDSIUEmailParser.java
new file mode 100644
index 0000000..6edbc64
--- /dev/null
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LDSIUEmailParser.java
@@ -0,0 +1,107 @@
+/**
+ *
+ * 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.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class LDSIUEmailParser implements EmailParser {
+
+    private static final Logger log = LoggerFactory.getLogger(LDSIUEmailParser.class);
+    private static final String REGEX = "[\\w]*[ ]*(?<"+ JOBID + ">[\\d]*)[ ]*\\((?<"
+ JOBNAME
+            + ">[a-zA-Z0-9]*)\\)[ ]*(?<" + STATUS + ">[a-zA-Z\\s]*)";
+    public static final String STARTED = "Started";
+    public static final String COMPLETE = "Complete";
+    public static final String FAILED = "Set in error state";
+    public static final String KILLED = "Killed";
+    private static final String REGEX_EXIT_STATUS = "Exit Status[ ]*=[ ]*(?<" + EXIT_STATUS
+ ">[\\d]+)";
+    public static final String ABORTED = "Aborted";
+
+
+    @Override
+    public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException
{
+        JobStatusResult jobStatusResult = new JobStatusResult();
+
+        parseContent(message, jobStatusResult);
+        return jobStatusResult;
+    }
+
+    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");
+        }
+    }
+
+    private JobState getJobState(String status, String content) {
+        switch (status) {
+            case STARTED:
+                return JobState.ACTIVE;
+            case COMPLETE:
+                int exitStatus = getExitStatus(content);
+                if (exitStatus == 0) {
+                    return JobState.COMPLETE;
+                } else {
+                    log.info("[EJM]: Job returns with Exit Status = " + exitStatus + "  ,
Marked as Failed");
+                    return JobState.FAILED;
+                }
+            case FAILED:
+                return JobState.FAILED;
+            case ABORTED:
+                return JobState.CANCELED;
+            default:
+                return JobState.UNKNOWN;
+
+        }
+    }
+
+    private int getExitStatus(String content) {
+        Pattern statusPattern = Pattern.compile(REGEX_EXIT_STATUS);
+        Matcher statusMatcher = statusPattern.matcher(content);
+        if (statusMatcher.find()) {
+            String group = statusMatcher.group(EXIT_STATUS);
+            if (group != null && !group.trim().isEmpty()) {
+                return Integer.valueOf(group.trim());
+            }
+        }
+        return -1;
+    }
+}


Mime
View raw message