sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [3/3] git commit: SQOOP-679 Wrap exception to MSubmission metadata object (Jarek Jarcec Cecho)
Date Tue, 06 Nov 2012 20:16:10 GMT
SQOOP-679 Wrap exception to MSubmission metadata object
(Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/25f3fd33
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/25f3fd33
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/25f3fd33

Branch: refs/heads/sqoop2
Commit: 25f3fd331fefaea9da5b90ceda1d788fe79c51dc
Parents: 0976713
Author: Bilung Lee <blee@apache.org>
Authored: Mon Nov 5 14:16:09 2012 -0800
Committer: Bilung Lee <blee@apache.org>
Committed: Mon Nov 5 14:16:09 2012 -0800

----------------------------------------------------------------------
 .../sqoop/client/utils/SubmissionDisplayer.java    |   25 +++++++-
 .../java/org/apache/sqoop/json/SubmissionBean.java |   14 ++++
 .../java/org/apache/sqoop/model/MSubmission.java   |   51 ++++++++++++++-
 .../apache/sqoop/submission/SubmissionStatus.java  |    4 +
 .../org/apache/sqoop/json/TestSubmissionBean.java  |   16 +++++
 .../mapreduce/MapreduceSubmissionEngine.java       |    1 +
 6 files changed, 109 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/25f3fd33/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
index d4d6825..a7b4bca 100644
--- a/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
+++ b/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
@@ -18,6 +18,7 @@
 package org.apache.sqoop.client.utils;
 
 import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.submission.SubmissionStatus;
 import org.apache.sqoop.submission.counter.Counter;
 import org.apache.sqoop.submission.counter.CounterGroup;
 import org.apache.sqoop.submission.counter.Counters;
@@ -35,7 +36,8 @@ public final class SubmissionDisplayer {
     io.out.println(submission.getJobId());
 
     io.out.print("Status: ");
-    io.out.println(submission.getStatus());
+    printColoredStatus(io, submission.getStatus());
+    io.out.println();
 
     String externalId = submission.getExternalId();
     if(externalId != null) {
@@ -72,5 +74,26 @@ public final class SubmissionDisplayer {
         }
       }
     }
+
+    // Exception handling
+    if(submission.getExceptionInfo() != null) {
+      io.out.print("@|red Exception: |@");
+      io.out.println(submission.getExceptionInfo());
+
+      if(submission.getExceptionStackTrace() != null) {
+        io.out.print("@|bold Stack trace: |@");
+        io.out.println(submission.getExceptionStackTrace());
+      }
+    }
+  }
+
+  public static void printColoredStatus(IO io, SubmissionStatus status) {
+    if(status.isRunning()) {
+      io.out.print("@|green " + status.toString() + " |@");
+    } else if(status.isFailure()) {
+      io.out.print("@|red " + status.toString() + " |@");
+    } else {
+      io.out.print(status.toString());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/25f3fd33/common/src/main/java/org/apache/sqoop/json/SubmissionBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/SubmissionBean.java b/common/src/main/java/org/apache/sqoop/json/SubmissionBean.java
index d7188f4..0880418 100644
--- a/common/src/main/java/org/apache/sqoop/json/SubmissionBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/SubmissionBean.java
@@ -38,6 +38,8 @@ public class SubmissionBean implements JsonBean {
   private static final String STATUS = "status";
   private static final String EXTERNAL_ID = "external-id";
   private static final String EXTERNAL_LINK = "external-link";
+  private static final String EXCEPTION = "exception";
+  private static final String EXCEPTION_TRACE = "exception-trace";
   private static final String PROGRESS = "progress";
   private static final String COUNTERS = "counters";
 
@@ -74,6 +76,12 @@ public class SubmissionBean implements JsonBean {
     if(submission.getExternalLink() != null) {
       ret.put(EXTERNAL_LINK, submission.getExternalLink());
     }
+    if(submission.getExceptionInfo() != null) {
+      ret.put(EXCEPTION, submission.getExceptionInfo());
+    }
+    if(submission.getExceptionStackTrace() != null) {
+      ret.put(EXCEPTION_TRACE, submission.getExceptionStackTrace());
+    }
     if(submission.getCounters() != null) {
       ret.put(COUNTERS, extractCounters(submission.getCounters()));
     }
@@ -113,6 +121,12 @@ public class SubmissionBean implements JsonBean {
     if(json.containsKey(EXTERNAL_LINK)) {
       submission.setExternalLink((String) json.get(EXTERNAL_LINK));
     }
+    if(json.containsKey(EXCEPTION)) {
+      submission.setExceptionInfo((String) json.get(EXCEPTION));
+    }
+    if(json.containsKey(EXCEPTION_TRACE)) {
+      submission.setExceptionStackTrace((String) json.get(EXCEPTION_TRACE));
+    }
     if(json.containsKey(COUNTERS)) {
       submission.setCounters(restoreCounters((JSONObject) json.get(COUNTERS)));
     }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/25f3fd33/common/src/main/java/org/apache/sqoop/model/MSubmission.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MSubmission.java b/common/src/main/java/org/apache/sqoop/model/MSubmission.java
index f8ca32e..c8ba0e2 100644
--- a/common/src/main/java/org/apache/sqoop/model/MSubmission.java
+++ b/common/src/main/java/org/apache/sqoop/model/MSubmission.java
@@ -20,6 +20,8 @@ package org.apache.sqoop.model;
 import org.apache.sqoop.submission.SubmissionStatus;
 import org.apache.sqoop.submission.counter.Counters;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.Date;
 
 /**
@@ -82,6 +84,20 @@ public class MSubmission extends MPersistableEntity {
    */
   String externalLink;
 
+  /**
+   * Associated exception info with this job (if any).
+   *
+   * This is optional property that is not serialized in metastore.
+   */
+  String exceptionInfo;
+
+  /**
+   * Associated exception stacktrace with this job (if any).
+   *
+   * This is optional property that is not serialized in metastore.
+   */
+  String exceptionStackTrace;
+
   public MSubmission() {
     status = SubmissionStatus.UNKNOWN;
     progress = -1;
@@ -168,13 +184,46 @@ public class MSubmission extends MPersistableEntity {
     return externalLink;
   }
 
+  public void setExceptionInfo(String exceptionInfo) {
+    this.exceptionInfo = exceptionInfo;
+  }
+
+  public String getExceptionInfo() {
+    return exceptionInfo;
+  }
+
+  public void setExceptionStackTrace(String stackTrace) {
+    this.exceptionStackTrace = stackTrace;
+  }
+
+  public String getExceptionStackTrace() {
+    return exceptionStackTrace;
+  }
+
+  public void setException(Throwable e) {
+    // Exception info
+    this.setExceptionInfo(e.toString());
+
+    // Exception stack trace
+    StringWriter writer = new StringWriter();
+    e.printStackTrace(new PrintWriter(writer));
+    writer.flush();
+    this.setExceptionStackTrace(writer.toString());
+  }
+
   @Override
   public String toString() {
     return "MSubmission{" +
       "jobId=" + jobId +
       ", date=" + date +
       ", status=" + status +
-      ", externalId=" + externalId + "}";
+      ", externalId='" + externalId + '\'' +
+      ", progress=" + progress +
+      ", counters=" + counters +
+      ", externalLink='" + externalLink + '\'' +
+      ", exceptionInfo='" + exceptionInfo + '\'' +
+      ", exceptionStackTrace='" + exceptionStackTrace + '\'' +
+      '}';
   }
 
   public static MSubmission UNKNOWN = new MSubmission();

http://git-wip-us.apache.org/repos/asf/sqoop/blob/25f3fd33/common/src/main/java/org/apache/sqoop/submission/SubmissionStatus.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/submission/SubmissionStatus.java b/common/src/main/java/org/apache/sqoop/submission/SubmissionStatus.java
index 025690a..e2da8f5 100644
--- a/common/src/main/java/org/apache/sqoop/submission/SubmissionStatus.java
+++ b/common/src/main/java/org/apache/sqoop/submission/SubmissionStatus.java
@@ -72,4 +72,8 @@ public enum SubmissionStatus {
   public boolean isRunning() {
     return this == RUNNING || this == BOOTING;
   }
+
+  public boolean isFailure() {
+    return this == FAILED || this == UNKNOWN || this == FAILURE_ON_SUBMIT;
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/25f3fd33/common/src/test/java/org/apache/sqoop/json/TestSubmissionBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestSubmissionBean.java b/common/src/test/java/org/apache/sqoop/json/TestSubmissionBean.java
index 9c5e043..9732fa1 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestSubmissionBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestSubmissionBean.java
@@ -78,6 +78,22 @@ public class TestSubmissionBean extends TestCase {
     assertEquals("http://", target.getExternalLink());
   }
 
+  public void testTransferException() {
+    MSubmission source = new MSubmission();
+    source.setExceptionInfo("EndOfTheWorldException");
+
+    MSubmission target = transfer(source);
+    assertEquals("EndOfTheWorldException", target.getExceptionInfo());
+  }
+
+  public void testTransferExceptionTrace() {
+    MSubmission source = new MSubmission();
+    source.setExceptionStackTrace("void.java(3): line infinity");
+
+    MSubmission target = transfer(source);
+    assertEquals("void.java(3): line infinity", target.getExceptionStackTrace());
+  }
+
   public void testTransferProgress() {
     MSubmission source = new MSubmission();
     source.setProgress(25.0);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/25f3fd33/submission/mapreduce/src/main/java/org/apache/sqoop/submission/mapreduce/MapreduceSubmissionEngine.java
----------------------------------------------------------------------
diff --git a/submission/mapreduce/src/main/java/org/apache/sqoop/submission/mapreduce/MapreduceSubmissionEngine.java
b/submission/mapreduce/src/main/java/org/apache/sqoop/submission/mapreduce/MapreduceSubmissionEngine.java
index 7049924..94098de 100644
--- a/submission/mapreduce/src/main/java/org/apache/sqoop/submission/mapreduce/MapreduceSubmissionEngine.java
+++ b/submission/mapreduce/src/main/java/org/apache/sqoop/submission/mapreduce/MapreduceSubmissionEngine.java
@@ -197,6 +197,7 @@ public class MapreduceSubmissionEngine extends SubmissionEngine {
 
       LOG.debug("Executed new map-reduce job with id " + jobId);
     } catch (Exception e) {
+      request.getSummary().setException(e);
       LOG.error("Error in submitting job", e);
       return false;
     }


Mime
View raw message