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 2020/04/24 14:35:22 UTC

[zeppelin] branch master updated: [ZEPPELIN-4768] Correct a typo in isUserImpersonateForSparkInterpreter

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 badb2b4  [ZEPPELIN-4768] Correct a typo in isUserImpersonateForSparkInterpreter
badb2b4 is described below

commit badb2b4ba2b731f585e0aec6b791eeff792076b3
Author: Philipp Dallig <ph...@gmail.com>
AuthorDate: Tue Apr 21 10:25:01 2020 +0200

    [ZEPPELIN-4768] Correct a typo in isUserImpersonateForSparkInterpreter
    
    ### What is this PR for?
    Small typo fix
    
    ### What type of PR is it?
    Bug Fix
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-4768
    
    ### How should this be tested?
    * **Travis-CI**: https://travis-ci.org/github/Reamer/zeppelin/builds/677598691
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Philipp Dallig <ph...@gmail.com>
    
    Closes #3744 from Reamer/typo_in_spark_user_impersonate and squashes the following commits:
    
    7094ab04e [Philipp Dallig] Correct a typo in isUserImpersonateForSparkInterpreter
---
 .../launcher/K8sStandardInterpreterLauncher.java   |  2 +-
 .../K8sStandardInterpreterLauncherTest.java        | 87 ++++++++++++++++++++++
 2 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncher.java b/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncher.java
index 085c3f9..80bd4aa 100644
--- a/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncher.java
+++ b/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncher.java
@@ -135,7 +135,7 @@ public class K8sStandardInterpreterLauncher extends InterpreterLauncher {
   private boolean isUserImpersonateForSparkInterpreter(InterpreterLaunchContext context) {
       return zConf.getZeppelinImpersonateSparkProxyUser() &&
           context.getOption().isUserImpersonate() &&
-          "spark".equalsIgnoreCase(context.getInterpreterGroupId());
+          "spark".equalsIgnoreCase(context.getInterpreterSettingGroup());
   }
 
   @Override
diff --git a/zeppelin-plugins/launcher/k8s-standard/src/test/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncherTest.java b/zeppelin-plugins/launcher/k8s-standard/src/test/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncherTest.java
index 4cd035a..b25373d 100644
--- a/zeppelin-plugins/launcher/k8s-standard/src/test/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncherTest.java
+++ b/zeppelin-plugins/launcher/k8s-standard/src/test/java/org/apache/zeppelin/interpreter/launcher/K8sStandardInterpreterLauncherTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
 import java.io.IOException;
 import java.util.Properties;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -75,4 +76,90 @@ public class K8sStandardInterpreterLauncherTest {
     // then
     assertTrue(client instanceof K8sRemoteInterpreterProcess);
   }
+
+  @Test
+  public void testK8sLauncherWithSparkAndUserImpersonate() throws IOException {
+    // given
+    Kubectl kubectl = mock(Kubectl.class);
+    when(kubectl.getNamespace()).thenReturn("default");
+
+    ZeppelinConfiguration zConf = new ZeppelinConfiguration();
+    K8sStandardInterpreterLauncher launcher = new K8sStandardInterpreterLauncher(zConf, null, kubectl);
+    Properties properties = new Properties();
+    properties.setProperty("ENV_1", "VALUE_1");
+    properties.setProperty("property_1", "value_1");
+    properties.setProperty("CALLBACK_HOST", "zeppelin-server.default.svc");
+    properties.setProperty("CALLBACK_PORT", "12320");
+    properties.setProperty("SERVICE_DOMAIN", "example.com");
+    properties.setProperty("zeppelin.interpreter.connect.timeout", "60");
+    InterpreterOption option = new InterpreterOption();
+    option.setUserImpersonate(true);
+    InterpreterLaunchContext context = new InterpreterLaunchContext(
+            properties,
+            option,
+            null,
+            "user1", // username
+            "spark-user1", //interpretergroupId
+            "dummy", // interpreterSettingId
+            "spark", // interpreterSettingGroup
+            "spark", // interpreterSettingName
+            0,
+            "host");
+    // when
+    InterpreterClient client = launcher.launch(context);
+
+    // then
+    assertTrue(client instanceof K8sRemoteInterpreterProcess);
+    K8sRemoteInterpreterProcess process = (K8sRemoteInterpreterProcess) client;
+    assertTrue(process.isSpark());
+
+    // when
+    process.start(context.getUserName());
+
+    // then
+    assertTrue(process.buildSparkSubmitOptions().contains("--proxy-user user1"));
+  }
+
+  @Test
+  public void testK8sLauncherWithSparkAndWithoutUserImpersonate() throws IOException {
+    // given
+    Kubectl kubectl = mock(Kubectl.class);
+    when(kubectl.getNamespace()).thenReturn("default");
+
+    ZeppelinConfiguration zConf = new ZeppelinConfiguration();
+    K8sStandardInterpreterLauncher launcher = new K8sStandardInterpreterLauncher(zConf, null, kubectl);
+    Properties properties = new Properties();
+    properties.setProperty("ENV_1", "VALUE_1");
+    properties.setProperty("property_1", "value_1");
+    properties.setProperty("CALLBACK_HOST", "zeppelin-server.default.svc");
+    properties.setProperty("CALLBACK_PORT", "12320");
+    properties.setProperty("SERVICE_DOMAIN", "example.com");
+    properties.setProperty("zeppelin.interpreter.connect.timeout", "60");
+    InterpreterOption option = new InterpreterOption();
+    option.setUserImpersonate(false);
+    InterpreterLaunchContext context = new InterpreterLaunchContext(
+            properties,
+            option,
+            null,
+            "user1", // username
+            "spark-user1", //interpretergroupId
+            "dummy", // interpreterSettingId
+            "spark", // interpreterSettingGroup
+            "spark", // interpreterSettingName
+            0,
+            "host");
+    // when
+    InterpreterClient client = launcher.launch(context);
+
+    // then
+    assertTrue(client instanceof K8sRemoteInterpreterProcess);
+    K8sRemoteInterpreterProcess process = (K8sRemoteInterpreterProcess) client;
+    assertTrue(process.isSpark());
+
+    // when
+    process.start(context.getUserName());
+
+    // then
+    assertFalse(process.buildSparkSubmitOptions().contains("--proxy-user user1"));
+  }
 }