You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2021/08/03 03:48:12 UTC

[zeppelin] branch master updated: [ZEPPELIN-5474] Add configuration to specify the port range of shiny app

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

zjffdu 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 934e38a  [ZEPPELIN-5474] Add configuration to specify the port range of shiny app
934e38a is described below

commit 934e38add26157b87d6b247e4efca4f795411a2c
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Fri Jul 2 13:46:55 2021 +0800

    [ZEPPELIN-5474] Add configuration to specify the port range of shiny app
    
    ### What is this PR for?
    
    Add configuration `zeppelin.R.shiny.portRange` for both R interpreter and SparkR, so that user can specify the portRange of shiny app. This would be useful when user has port usage constraint due to security reason.
    
    ### What type of PR is it?
    [Improvement ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5474
    
    ### How should this be tested?
    * Manually tested
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <zj...@apache.org>
    
    Closes #4191 from zjffdu/ZEPPELIN-5474 and squashes the following commits:
    
    2649b27b72 [Jeff Zhang] [ZEPPELIN-5474] Add configuration to specify the port range of shiny app
---
 rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java  | 6 ++++--
 rlang/src/main/resources/interpreter-setting.json             | 7 +++++++
 spark/interpreter/src/main/resources/interpreter-setting.json | 7 +++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java b/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java
index 0dcb836..ef6d60d 100644
--- a/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java
+++ b/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java
@@ -53,6 +53,7 @@ public class IRInterpreter extends JupyterKernelInterpreter {
   // only one shiny app can be hosted in one R session.
   private File shinyAppFolder;
   private SparkRBackend sparkRBackend;
+  private String shinyPortRange;
 
   public IRInterpreter(Properties properties) {
     super("ir", properties);
@@ -113,6 +114,7 @@ public class IRInterpreter extends JupyterKernelInterpreter {
     try {
       this.shinyAppFolder = Files.createTempDirectory("zeppelin-shiny").toFile();
       this.shinyAppFolder.deleteOnExit();
+      this.shinyPortRange = properties.getProperty("zeppelin.R.shiny.portRange", ":");
     } catch (IOException e) {
       throw new InterpreterException(e);
     }
@@ -185,11 +187,11 @@ public class IRInterpreter extends JupyterKernelInterpreter {
     try {
       StringBuilder builder = new StringBuilder("library(shiny)\n");
       String host = RemoteInterpreterUtils.findAvailableHostAddress();
-      int port = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
+      int port = RemoteInterpreterUtils.findAvailablePort(shinyPortRange);
       builder.append("runApp(appDir='" + shinyAppFolder.getAbsolutePath() + "', " +
               "port=" + port + ", host='" + host + "', launch.browser=FALSE)");
       // shiny app will launch and block there until user cancel the paragraph.
-      LOGGER.info("Run shiny app code: {}", builder);
+      LOGGER.info("Run shiny app code: {}", builder.toString());
       return internalInterpret(builder.toString(), context);
     } finally {
       getKernelProcessLauncher().setRedirectedContext(null);
diff --git a/rlang/src/main/resources/interpreter-setting.json b/rlang/src/main/resources/interpreter-setting.json
index 24d1a48..f0a9677 100644
--- a/rlang/src/main/resources/interpreter-setting.json
+++ b/rlang/src/main/resources/interpreter-setting.json
@@ -31,6 +31,13 @@
         "defaultValue": "out.format = 'html', comment = NA, echo = FALSE, results = 'asis', message = F, warning = F, fig.retina = 2",
         "description": "",
         "type": "textarea"
+      },
+      "zeppelin.R.shiny.portRange": {
+        "envName": "",
+        "propertyName": "zeppelin.R.shiny.portRange",
+        "defaultValue": ":",
+        "description": "Shiny app would launch a web app at some port, this property is to specify the portRange via format '<start>:<end>', e.g. '5000:5001'. By default it is ':' which means any port",
+        "type": "string"
       }
     },
     "editor": {
diff --git a/spark/interpreter/src/main/resources/interpreter-setting.json b/spark/interpreter/src/main/resources/interpreter-setting.json
index 1502f64..5ba5f23 100644
--- a/spark/interpreter/src/main/resources/interpreter-setting.json
+++ b/spark/interpreter/src/main/resources/interpreter-setting.json
@@ -289,6 +289,13 @@
         "defaultValue": "out.format = 'html', comment = NA, echo = FALSE, results = 'asis', message = F, warning = F, fig.retina = 2",
         "description": "",
         "type": "textarea"
+      },
+      "zeppelin.R.shiny.portRange": {
+        "envName": "",
+        "propertyName": "zeppelin.R.shiny.portRange",
+        "defaultValue": ":",
+        "description": "Shiny app would launch a web app at some port, this property is to specify the portRange via format '<start>:<end>', e.g. '5000:5001'. By default it is ':' which means any port",
+        "type": "string"
       }
     },
     "editor": {