This is an automated email from the ASF dual-hosted git repository.

liuxun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/master by this push:
     new faf082b  ZEPPELIN-4747. Terminal interpreter support internal and 
external IP mapping
faf082b is described below

commit faf082bc07433454bcdc7dec7869cb9f6f2e5bef
Author: Xun Liu <liu...@apache.org>
AuthorDate: Sat Apr 11 15:06:39 2020 +0800

    ZEPPELIN-4747. Terminal interpreter support internal and external IP mapping
    
    ### What is this PR for?
    When running the terminal interpreter in the notebook, the front end of the 
notebook needs to obtain the IP address of the server where the terminal 
interpreter is located to communicate.
    
    In a public cloud environment, the cloud host has an internal IP and an 
external access IP, and the interpreter runs in the cloud host. This will cause 
the notebook front end to be unable to connect to the terminal interpreter 
properly, resulting in the terminal interpreter being unusable.
    
    Solution: Set the mapping between internal IP and external IP in the 
terminal interpreter, and connect the front end of the notebook through the 
external IP of the terminal interpreter.
    
    ### What type of PR is it?
    [Improvement]
    
    ### What is the Jira issue?
    * https://jira.apache.org/jira/browse/ZEPPELIN-4747
    
    ### How should this be tested?
    * First time? Setup Travis CI as described on 
https://zeppelin.apache.org/contribution/contributions.html#continuous-integration
    * Strongly recommended: add automated unit tests for any new or changed 
behavior
    * Outline any manual steps to test the PR here.
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update?
    * Is there breaking changes for older versions?
    * Does this needs documentation?
    
    Author: Xun Liu <liu...@apache.org>
    
    Closes #3732 from liuxunorg/ZEPPELIN-4747 and squashes the following 
commits:
    
    68f16caa4 [Xun Liu] Fixed
    c462c3e46 [Xun Liu] ZEPPELIN-4747. Terminal interpreter support internal 
and external IP mapping
---
 docs/interpreter/shell.md                            | 16 ++++++++++++++++
 .../apache/zeppelin/shell/TerminalInterpreter.java   | 20 ++++++++++++++++++++
 shell/src/main/resources/interpreter-setting.json    |  7 +++++++
 3 files changed, 43 insertions(+)

diff --git a/docs/interpreter/shell.md b/docs/interpreter/shell.md
index c38391b..631c133 100644
--- a/docs/interpreter/shell.md
+++ b/docs/interpreter/shell.md
@@ -74,6 +74,11 @@ At the "Interpreters" menu in Zeppelin dropdown menu, you 
can set the property v
     <td>false</td>
     <td>Enable ZeppelinContext variable interpolation into paragraph text</td>
   </tr>
+  <tr>
+    <td>zeppelin.terminal.ip.mapping</td>
+    <td></td>
+    <td>Internal and external IP mapping of zeppelin server</td>
+  </tr>
 </table>
 
 ## Example
@@ -129,3 +134,14 @@ input any char
 ```
 
 <img 
src="{{BASE_PATH}}/assets/themes/zeppelin/img/docs-img/shell-terminal.gif" />
+
+### zeppelin.terminal.ip.mapping
+
+When running the terminal interpreter in the notebook, the front end of the 
notebook needs to obtain the IP address of the server where the terminal 
interpreter is located to communicate.
+
+In a public cloud environment, the cloud host has an internal IP and an 
external access IP, and the interpreter runs in the cloud host. This will cause 
the notebook front end to be unable to connect to the terminal interpreter 
properly, resulting in the terminal interpreter being unusable.
+
+Solution: Set the mapping between internal IP and external IP in the terminal 
interpreter, and connect the front end of the notebook through the external IP 
of the terminal interpreter.
+
+Example: 
+{"internal-ip1":"external-ip1", "internal-ip2":"external-ip2"}
diff --git 
a/shell/src/main/java/org/apache/zeppelin/shell/TerminalInterpreter.java 
b/shell/src/main/java/org/apache/zeppelin/shell/TerminalInterpreter.java
index f18c8b4..d54495e 100644
--- a/shell/src/main/java/org/apache/zeppelin/shell/TerminalInterpreter.java
+++ b/shell/src/main/java/org/apache/zeppelin/shell/TerminalInterpreter.java
@@ -19,6 +19,8 @@ package org.apache.zeppelin.shell;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.io.Resources;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import com.hubspot.jinjava.Jinjava;
 import org.apache.commons.io.Charsets;
 import org.apache.commons.lang3.StringUtils;
@@ -43,6 +45,7 @@ import java.net.URL;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 /**
@@ -61,6 +64,10 @@ public class TerminalInterpreter extends KerberosInterpreter 
{
 
   private int terminalPort = 0;
 
+  // Internal and external IP mapping of zeppelin server
+  private HashMap<String, String> mapIpMapping = new HashMap<>();
+  private Gson gson = new Gson();
+
   // terminal web socket status
   // ui_templates/terminal-dashboard.jinja
   public static final String TERMINAL_SOCKET_STATUS = "TERMINAL_SOCKET_STATUS";
@@ -123,6 +130,12 @@ public class TerminalInterpreter extends 
KerberosInterpreter {
       }
     }
     setParagraphConfig();
+    Properties properties = getProperties();
+    String strIpMapping = 
properties.getProperty("zeppelin.terminal.ip.mapping");
+    if (!StringUtils.isEmpty(strIpMapping)) {
+      mapIpMapping = gson.fromJson(strIpMapping, new TypeToken<Map<String, 
String>>(){}.getType());
+    }
+
     createTerminalDashboard(context.getNoteId(), context.getParagraphId(), 
terminalPort);
 
     return new InterpreterResult(Code.SUCCESS);
@@ -137,6 +150,13 @@ public class TerminalInterpreter extends 
KerberosInterpreter {
       InetAddress addr = InetAddress.getLocalHost();
       hostName = addr.getHostName().toString();
       hostIp = RemoteInterpreterUtils.findAvailableHostAddress();
+
+      // Internal and external IP mapping of zeppelin server
+      if (mapIpMapping.containsKey(hostIp)) {
+        LOGGER.info("Internal IP: {}", hostIp);
+        hostIp = mapIpMapping.get(hostIp);
+        LOGGER.info("External IP: {}", hostIp);
+      }
     } catch (IOException e) {
       LOGGER.error(e.getMessage(), e);
     }
diff --git a/shell/src/main/resources/interpreter-setting.json 
b/shell/src/main/resources/interpreter-setting.json
index 1db6528..57b6fa1 100644
--- a/shell/src/main/resources/interpreter-setting.json
+++ b/shell/src/main/resources/interpreter-setting.json
@@ -59,6 +59,13 @@
     "name": "terminal",
     "className": "org.apache.zeppelin.shell.TerminalInterpreter",
     "properties": {
+      "zeppelin.terminal.ip.mapping": {
+        "envName": null,
+        "propertyName": "zeppelin.terminal.ip.mapping",
+        "defaultValue": "",
+        "description": "Internal and external IP mapping of zeppelin server",
+        "type": "string"
+      }
     },
     "editor": {
       "language": "sh",

Reply via email to