From 2d1bbbb08b3fd6065805dc229059c5e6455cf612 Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Thu, 24 May 2018 16:10:47 +0800 Subject: [PATCH] ZEPPELIN-3497. Improve error message when livy session is failed to create --- .../zeppelin/livy/BaseLivyInterpreter.java | 26 +++++++++++++++++-- .../main/resources/interpreter-setting.json | 6 +++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java index 9d2c0cfa93e..eef5f5caf71 100644 --- a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java +++ b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java @@ -94,6 +94,7 @@ public abstract class BaseLivyInterpreter extends Interpreter { private String livyURL; private int sessionCreationTimeout; private int pullStatusInterval; + private int maxLogLines; protected boolean displayAppInfo; private boolean restartDeadSession; protected LivyVersion livyVersion; @@ -119,6 +120,8 @@ public BaseLivyInterpreter(Properties property) { property.getProperty("zeppelin.livy.session.create_timeout", 120 + "")); this.pullStatusInterval = Integer.parseInt( property.getProperty("zeppelin.livy.pull_status.interval.millis", 1000 + "")); + this.maxLogLines = Integer.parseInt(property.getProperty("zeppelin.livy.maxLogLines", + "1000")); this.restTemplate = createRestTemplate(); if (!StringUtils.isBlank(property.getProperty("zeppelin.livy.http.headers"))) { String[] headers = property.getProperty("zeppelin.livy.http.headers").split(";"); @@ -338,7 +341,7 @@ private SessionInfo createSession(String user, String kind) if ((System.currentTimeMillis() - start) / 1000 > sessionCreationTimeout) { String msg = "The creation of session " + sessionInfo.id + " is timeout within " + sessionCreationTimeout + " seconds, appId: " + sessionInfo.appId - + ", log: " + sessionInfo.log; + + ", log:\n" + StringUtils.join(getSessionLog(sessionInfo.id).log, "\n"); throw new LivyException(msg); } Thread.sleep(pullStatusInterval); @@ -347,7 +350,7 @@ private SessionInfo createSession(String user, String kind) sessionInfo.appId); if (sessionInfo.isFinished()) { String msg = "Session " + sessionInfo.id + " is finished, appId: " + sessionInfo.appId - + ", log: " + sessionInfo.log; + + ", log:\n" + StringUtils.join(getSessionLog(sessionInfo.id).log, "\n"); throw new LivyException(msg); } } @@ -362,6 +365,11 @@ private SessionInfo getSessionInfo(int sessionId) throws LivyException { return SessionInfo.fromJson(callRestAPI("/sessions/" + sessionId, "GET")); } + private SessionLog getSessionLog(int sessionId) throws LivyException { + return SessionLog.fromJson(callRestAPI("/sessions/" + sessionId + "/log?size=" + maxLogLines, + "GET")); + } + public InterpreterResult interpret(String code, String paragraphId, boolean displayAppInfo, @@ -822,6 +830,20 @@ public static SessionInfo fromJson(String json) { } } + private static class SessionLog { + public int id; + public int from; + public int size; + public List log; + + SessionLog() { + } + + public static SessionLog fromJson(String json) { + return gson.fromJson(json, SessionLog.class); + } + } + static class ExecuteRequest { public final String code; public final String kind; diff --git a/livy/src/main/resources/interpreter-setting.json b/livy/src/main/resources/interpreter-setting.json index 8b9b90613a2..a7ce2b38454 100644 --- a/livy/src/main/resources/interpreter-setting.json +++ b/livy/src/main/resources/interpreter-setting.json @@ -97,6 +97,12 @@ "description": "The interval for checking paragraph execution status", "type": "number" }, + "zeppelin.livy.maxLogLines": { + "propertyName": "zeppelin.livy.maxLogLines", + "defaultValue": "1000", + "description": "Max number of lines of logs", + "type": "number" + }, "livy.spark.jars.packages": { "propertyName": "livy.spark.jars.packages", "defaultValue": "",