airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject [40/48] airavata git commit: fixed nonASCII in pbs email content
Date Fri, 16 Sep 2016 16:12:15 GMT
fixed nonASCII in pbs email content


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

Branch: refs/heads/lahiru/AIRAVATA-2065
Commit: 9c02fe056abad5e0e737afd44e4d6c108189b119
Parents: a0c9be8
Author: Shameera Rathnayaka <shameerainfo@gmail.com>
Authored: Fri Sep 9 16:15:11 2016 -0400
Committer: Shameera Rathnayaka <shameerainfo@gmail.com>
Committed: Fri Sep 9 16:15:24 2016 -0400

----------------------------------------------------------------------
 .../monitor/email/parser/LSFEmailParser.java    | 27 +++++++++-------
 .../monitor/email/parser/PBSEmailParser.java    | 29 +++++++++--------
 .../monitor/email/parser/SLURMEmailParser.java  |  8 +++--
 .../monitor/email/parser/UGEEmailParser.java    |  6 +++-
 .../email/parser/PBSEmailParserTest.java        | 33 ++++++++++++++++++++
 5 files changed, 75 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/9c02fe05/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LSFEmailParser.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LSFEmailParser.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LSFEmailParser.java
index d6e396e..a2dd17e 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LSFEmailParser.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/LSFEmailParser.java
@@ -44,23 +44,28 @@ public class LSFEmailParser implements EmailParser {
     public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException
{
         JobStatusResult jobStatusResult = new JobStatusResult();
         try {
-            String content = ((String) message.getContent());
-            Pattern pattern = Pattern.compile(LONESTAR_REGEX);
-            Matcher matcher = pattern.matcher(content);
-            if (matcher.find()) {
-                jobStatusResult.setJobId(matcher.group(JOBID));
-                String status = matcher.group(STATUS);
-                jobStatusResult.setState(getJobState(status, content));
-                return jobStatusResult;
-            } else {
-                log.error("[EJM]: No matched found for content => \n" + content);
-            }
+            parseContent(((String) message.getContent()), jobStatusResult);
         } catch (IOException e) {
             throw new AiravataException("i[EJM]: Error while reading content of the email
message");
         }
         return jobStatusResult;
     }
 
+    private boolean parseContent(String content, JobStatusResult jobStatusResult) throws
IOException, MessagingException {
+        content = content.replaceAll("[^\\x00-\\x7F]", "");
+        Pattern pattern = Pattern.compile(LONESTAR_REGEX);
+        Matcher matcher = pattern.matcher(content);
+        if (matcher.find()) {
+            jobStatusResult.setJobId(matcher.group(JOBID));
+            String status = matcher.group(STATUS);
+            jobStatusResult.setState(getJobState(status, content));
+            return true;
+        } else {
+            log.error("[EJM]: No matched found for content => \n" + content);
+        }
+        return false;
+    }
+
     private JobState getJobState(String status, String content) {
         switch (status) {
             case "Aborted":

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c02fe05/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParser.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParser.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParser.java
index 3879daf..9e56d2f 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParser.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParser.java
@@ -39,7 +39,7 @@ public class PBSEmailParser implements EmailParser {
     public static final String EXECUTION_TERMINATED = "Execution terminated";
     public static final String ABORTED_BY_PBS_SERVER = "Aborted by PBS Server";
 
-    static final String REGEX = "[a-zA-Z ]*:[ ]*(?<" + JOBID + ">[a-zA-Z0-9-\\.]*)\\s+[a-zA-Z
]*:[ ]*(?<" +
+    static final String REGEX = "[a-zA-Z ]*:[ ]*(?<" + JOBID + ">[a-zA-Z0-9-_\\.]*)\\s+[a-zA-Z
]*:[ ]*(?<" +
             JOBNAME + ">[a-zA-Z0-9-\\.]*)\\s[\\S|\\s]*(?<" + STATUS + ">" + BEGUN_EXECUTION
+ "|" +
             EXECUTION_TERMINATED + "|" + ABORTED_BY_PBS_SERVER + ")";
 
@@ -51,24 +51,27 @@ public class PBSEmailParser implements EmailParser {
 //        log.info("Parsing -> " + message.getSubject());
         try {
             String content = ((String) message.getContent());
-            Pattern pattern = Pattern.compile(REGEX);
-            Matcher matcher = pattern.matcher(content);
-            if (matcher.find()) {
-                jobStatusResult.setJobId(matcher.group(JOBID));
-                jobStatusResult.setJobName(matcher.group(JOBNAME));
-                String statusLine = matcher.group(STATUS);
-                jobStatusResult.setState(getJobState(statusLine, content));
-                return jobStatusResult;
-            } else {
-                log.error("[EJM]: No matched found for content => \n" + content);
-            }
-
+            parseContent(content, jobStatusResult);
         } catch (IOException e) {
             throw new AiravataException("[EJM]: Error while reading content of the email
message");
         }
         return jobStatusResult;
     }
 
+    void parseContent(String content, JobStatusResult jobStatusResult) throws MessagingException,
AiravataException {
+        content = content.replaceAll("[^\\x00-\\x7F]", "");
+        Pattern pattern = Pattern.compile(REGEX);
+        Matcher matcher = pattern.matcher(content);
+        if (matcher.find()) {
+            jobStatusResult.setJobId(matcher.group(JOBID));
+            jobStatusResult.setJobName(matcher.group(JOBNAME));
+            String statusLine = matcher.group(STATUS);
+            jobStatusResult.setState(getJobState(statusLine, content));
+        } else {
+            log.error("[EJM]: No matched found for content => \n" + content);
+        }
+    }
+
     private JobState getJobState(String statusLine, String content) {
         switch (statusLine) {
             case BEGUN_EXECUTION:

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c02fe05/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/SLURMEmailParser.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/SLURMEmailParser.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/SLURMEmailParser.java
index 792b24b..70985c2 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/SLURMEmailParser.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/SLURMEmailParser.java
@@ -49,17 +49,19 @@ public class SLURMEmailParser implements EmailParser {
     @Override
     public JobStatusResult parseEmail(Message message) throws MessagingException, AiravataException{
         JobStatusResult jobStatusResult = new JobStatusResult();
-        String subject = message.getSubject();
+        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), subject));
-            return jobStatusResult;
         } else {
             log.error("[EJM]: No matched found for subject -> " + subject);
         }
-        return jobStatusResult;
     }
 
     private JobState getJobState(String state, String subject) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c02fe05/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/UGEEmailParser.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/UGEEmailParser.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/UGEEmailParser.java
index 266456e..e43c900 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/UGEEmailParser.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/email/parser/UGEEmailParser.java
@@ -49,6 +49,11 @@ public class UGEEmailParser implements EmailParser {
     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);
@@ -64,7 +69,6 @@ public class UGEEmailParser implements EmailParser {
         } catch (IOException e) {
             throw new AiravataException("[EJM]: Error while reading content of the email
message");
         }
-        return jobStatusResult;
     }
 
     private JobState getJobState(String status, String content) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c02fe05/modules/gfac/gfac-impl/src/test/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParserTest.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/test/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParserTest.java
b/modules/gfac/gfac-impl/src/test/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParserTest.java
new file mode 100644
index 0000000..36650b4
--- /dev/null
+++ b/modules/gfac/gfac-impl/src/test/java/org/apache/airavata/gfac/monitor/email/parser/PBSEmailParserTest.java
@@ -0,0 +1,33 @@
+package org.apache.airavata.gfac.monitor.email.parser;
+
+import org.apache.airavata.gfac.core.monitor.JobStatusResult;
+import org.apache.airavata.model.status.JobState;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by syodage on 9/9/16.
+ */
+public class PBSEmailParserTest {
+
+    @Test
+    public void parseContent_non_ASCII() throws Exception {
+        PBSEmailParser parser = new PBSEmailParser();
+        // test for non ascii contents
+        String nonascii = "PBS Job Id: 33.torque_server\n" +
+                "Job Name:   A2085606929\n" +
+                "Exec host:  compute-0/0-9\n" +
+                "Begun execution";
+        JobStatusResult jsr = new JobStatusResult();
+        parser.parseContent(nonascii, jsr);
+        Assert.assertNotNull(jsr.getJobId());
+        Assert.assertEquals("33.torque_server", jsr.getJobId());
+        Assert.assertEquals("A2085606929", jsr.getJobName());
+        Assert.assertEquals(JobState.ACTIVE, jsr.getState());
+    }
+
+}
\ No newline at end of file


Mime
View raw message