mirror of
https://github.com/apache/sqoop.git
synced 2025-05-05 04:50:47 +08:00
SQOOP-679 Wrap exception to MSubmission metadata object
(Jarek Jarcec Cecho)
This commit is contained in:
parent
0976713f01
commit
25f3fd331f
@ -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 static void display(IO io, MSubmission submission) {
|
||||
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 static void display(IO io, MSubmission submission) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 JSONObject extract() {
|
||||
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 void restore(JSONObject json) {
|
||||
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)));
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
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 String getExternalLink() {
|
||||
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();
|
||||
|
@ -72,4 +72,8 @@ public static SubmissionStatus[] unfinished() {
|
||||
public boolean isRunning() {
|
||||
return this == RUNNING || this == BOOTING;
|
||||
}
|
||||
|
||||
public boolean isFailure() {
|
||||
return this == FAILED || this == UNKNOWN || this == FAILURE_ON_SUBMIT;
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,22 @@ public void testTransferExternalLink() {
|
||||
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);
|
||||
|
@ -197,6 +197,7 @@ public boolean submit(SubmissionRequest request) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user