From 52fc20426751cf4e07bff0200a142dafdd833eee Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Mon, 20 Mar 2017 16:11:38 +0800 Subject: [PATCH] address comment --- .../zeppelin/livy/BaseLivyInterprereter.java | 14 +++++++++++--- .../zeppelin/livy/LivySQLInterpreterTest.java | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java index e2d2ffba12..7f9897e9cb 100644 --- a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java +++ b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java @@ -65,6 +65,7 @@ public abstract class BaseLivyInterprereter extends Interpreter { protected boolean displayAppInfo; private AtomicBoolean sessionExpired = new AtomicBoolean(false); protected LivyVersion livyVersion; + private RestTemplate restTemplate; // keep tracking the mapping between paragraphId and statementId, so that we can cancel the // statement after we execute it. @@ -79,6 +80,7 @@ public abstract class BaseLivyInterprereter extends Interpreter { property.getProperty("zeppelin.livy.session.create_timeout", 120 + "")); this.pullStatusInterval = Integer.parseInt( property.getProperty("zeppelin.livy.pull_status.interval.millis", 1000 + "")); + this.restTemplate = createRestTemplate(); } public abstract String getSessionKind(); @@ -388,11 +390,18 @@ public abstract class BaseLivyInterprereter extends Interpreter { } - private RestTemplate getRestTemplate() throws LivyException { + private RestTemplate createRestTemplate() { HttpClient httpClient = null; if (livyURL.startsWith("https:")) { String keystoreFile = property.getProperty("zeppelin.livy.ssl.trustStore"); String password = property.getProperty("zeppelin.livy.ssl.trustStorePassword"); + if (StringUtils.isBlank(keystoreFile)) { + throw new RuntimeException("No zeppelin.livy.ssl.trustStore specified for livy ssl"); + } + if (StringUtils.isBlank(password)) { + throw new RuntimeException("No zeppelin.livy.ssl.trustStorePassword specified " + + "for livy ssl"); + } FileInputStream inputStream = null; try { inputStream = new FileInputStream(keystoreFile); @@ -404,7 +413,7 @@ public abstract class BaseLivyInterprereter extends Interpreter { SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); } catch (Exception e) { - throw new LivyException("Failed to create SSL HttpClient", e); + throw new RuntimeException("Failed to create SSL HttpClient", e); } finally { if (inputStream != null) { try { @@ -440,7 +449,6 @@ public abstract class BaseLivyInterprereter extends Interpreter { throws LivyException { targetURL = livyURL + targetURL; LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData); - RestTemplate restTemplate = getRestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); headers.add("X-Requested-By", "zeppelin"); diff --git a/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java b/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java index 9065f35591..fdef9b13d1 100644 --- a/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java +++ b/livy/src/test/java/org/apache/zeppelin/livy/LivySQLInterpreterTest.java @@ -36,6 +36,7 @@ public class LivySQLInterpreterTest { @Before public void setUp() { Properties properties = new Properties(); + properties.setProperty("zeppelin.livy.url", "http://localhost:8998"); properties.setProperty("zeppelin.livy.session.create_timeout", "120"); properties.setProperty("zeppelin.livy.spark.sql.maxResult", "3"); sqlInterpreter = new LivySparkSQLInterpreter(properties);