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/11/18 01:54:07 UTC

[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5131]. Code completion pop up error message in shell interpreter

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

zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 8220ee9  [ZEPPELIN-5131]. Code completion pop up error message in shell interpreter
8220ee9 is described below

commit 8220ee91d5f0212341f0d206aa7c533d7520bc5d
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Sat Nov 14 07:16:28 2020 +0800

    [ZEPPELIN-5131]. Code completion pop up error message in shell interpreter
    
    ### What is this PR for?
    
    Minor PR to fix the code completion pop up issue in shell interpreter. Besides that, I also did some code refactoring in this PR.
    
    ### What type of PR is it?
    [Bug Fix | Improvement ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5131
    
    ### How should this be tested?
    * CI pass
    
    ### 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 #3970 from zjffdu/ZEPPELIN-5131 and squashes the following commits:
    
    f55d1349a [Jeff Zhang] remove string cacontation
    cfa0643e7 [Jeff Zhang] [ZEPPELIN-5131]. Code completion pop up error message in shell interpreter
    
    (cherry picked from commit 885a8425c6b3048353b360c779ce24d23f4bb00f)
    Signed-off-by: Jeff Zhang <zj...@apache.org>
---
 .../apache/zeppelin/shell/ShellInterpreter.java    | 52 +++++++++-------------
 .../submarine/SubmarineShellInterpreter.java       |  6 +--
 2 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java b/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java
index d0c9027..c6f6496 100644
--- a/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java
+++ b/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java
@@ -27,11 +27,8 @@ import org.apache.zeppelin.interpreter.ZeppelinContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -40,7 +37,6 @@ import org.apache.zeppelin.interpreter.InterpreterException;
 import org.apache.zeppelin.interpreter.InterpreterResult;
 import org.apache.zeppelin.interpreter.InterpreterResult.Code;
 import org.apache.zeppelin.interpreter.KerberosInterpreter;
-import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
 import org.apache.zeppelin.scheduler.Scheduler;
 import org.apache.zeppelin.scheduler.SchedulerFactory;
 
@@ -51,9 +47,9 @@ public class ShellInterpreter extends KerberosInterpreter {
   private static final Logger LOGGER = LoggerFactory.getLogger(ShellInterpreter.class);
 
   private static final String TIMEOUT_PROPERTY = "shell.command.timeout.millisecs";
-  private String defaultTimeoutProperty = "60000";
-
+  private static final String DEFAULT_TIMEOUT = "60000";
   private static final String DIRECTORY_USER_HOME = "shell.working.directory.user.home";
+
   private final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
   private final String shell = isWindows ? "cmd /c" : "bash -c";
   ConcurrentHashMap<String, DefaultExecutor> executors;
@@ -96,9 +92,8 @@ public class ShellInterpreter extends KerberosInterpreter {
 
   @Override
   public InterpreterResult internalInterpret(String cmd,
-                                             InterpreterContext contextInterpreter) {
-    LOGGER.debug("Run shell command '" + cmd + "'");
-    OutputStream outStream = new ByteArrayOutputStream();
+                                             InterpreterContext context) {
+    LOGGER.debug("Run shell command '{}'", cmd);
 
     CommandLine cmdLine = CommandLine.parse(shell);
     // the Windows CMD shell doesn't handle multiline statements,
@@ -112,37 +107,40 @@ public class ShellInterpreter extends KerberosInterpreter {
     try {
       DefaultExecutor executor = new DefaultExecutor();
       executor.setStreamHandler(new PumpStreamHandler(
-          contextInterpreter.out, contextInterpreter.out));
+          context.out, context.out));
 
       executor.setWatchdog(new ExecuteWatchdog(
-          Long.valueOf(getProperty(TIMEOUT_PROPERTY, defaultTimeoutProperty))));
-      executors.put(contextInterpreter.getParagraphId(), executor);
+          Long.valueOf(getProperty(TIMEOUT_PROPERTY, DEFAULT_TIMEOUT))));
+      executors.put(context.getParagraphId(), executor);
       if (Boolean.valueOf(getProperty(DIRECTORY_USER_HOME))) {
         executor.setWorkingDirectory(new File(System.getProperty("user.home")));
       }
 
       int exitVal = executor.execute(cmdLine);
-      LOGGER.info("Paragraph " + contextInterpreter.getParagraphId()
-          + " return with exit value: " + exitVal);
-      return new InterpreterResult(Code.SUCCESS, outStream.toString());
+      LOGGER.info("Paragraph {} return with exit value: {}", context.getParagraphId(), exitVal);
+      if (exitVal == 0) {
+        return new InterpreterResult(Code.SUCCESS);
+      } else {
+        return new InterpreterResult(Code.ERROR);
+      }
     } catch (ExecuteException e) {
       int exitValue = e.getExitValue();
-      LOGGER.error("Can not run " + cmd, e);
+      LOGGER.error("Can not run command: " + cmd, e);
       Code code = Code.ERROR;
-      String message = outStream.toString();
+      StringBuilder messageBuilder = new StringBuilder();
       if (exitValue == 143) {
         code = Code.INCOMPLETE;
-        message += "Paragraph received a SIGTERM\n";
-        LOGGER.info("The paragraph " + contextInterpreter.getParagraphId()
-            + " stopped executing: " + message);
+        messageBuilder.append("Paragraph received a SIGTERM\n");
+        LOGGER.info("The paragraph {} stopped executing: {}",
+                context.getParagraphId(), messageBuilder.toString());
       }
-      message += "ExitValue: " + exitValue;
-      return new InterpreterResult(code, message);
+      messageBuilder.append("ExitValue: " + exitValue);
+      return new InterpreterResult(code, messageBuilder.toString());
     } catch (IOException e) {
-      LOGGER.error("Can not run " + cmd, e);
+      LOGGER.error("Can not run command: " + cmd, e);
       return new InterpreterResult(Code.ERROR, e.getMessage());
     } finally {
-      executors.remove(contextInterpreter.getParagraphId());
+      executors.remove(context.getParagraphId());
     }
   }
 
@@ -175,12 +173,6 @@ public class ShellInterpreter extends KerberosInterpreter {
   }
 
   @Override
-  public List<InterpreterCompletion> completion(String buf, int cursor,
-                                                InterpreterContext interpreterContext) {
-    return null;
-  }
-
-  @Override
   protected boolean runKerberosLogin() {
     try {
       createSecureConfiguration();
diff --git a/submarine/src/main/java/org/apache/zeppelin/submarine/SubmarineShellInterpreter.java b/submarine/src/main/java/org/apache/zeppelin/submarine/SubmarineShellInterpreter.java
index caa6661..f282fee 100644
--- a/submarine/src/main/java/org/apache/zeppelin/submarine/SubmarineShellInterpreter.java
+++ b/submarine/src/main/java/org/apache/zeppelin/submarine/SubmarineShellInterpreter.java
@@ -50,8 +50,8 @@ public class SubmarineShellInterpreter extends ShellInterpreter {
   }
 
   @Override
-  public InterpreterResult internalInterpret(String cmd, InterpreterContext intpContext) {
-    setParagraphConfig(intpContext);
+  public InterpreterResult internalInterpret(String cmd, InterpreterContext context) {
+    setParagraphConfig(context);
 
     // algorithm path & checkpoint path support replaces ${username} with real user name
     String algorithmPath = properties.getProperty(SUBMARINE_ALGORITHM_HDFS_PATH, "");
@@ -66,7 +66,7 @@ public class SubmarineShellInterpreter extends ShellInterpreter {
       properties.setProperty(TF_CHECKPOINT_PATH, checkpointPath);
     }
 
-    return super.internalInterpret(cmd, intpContext);
+    return super.internalInterpret(cmd, context);
   }
 
   private void setParagraphConfig(InterpreterContext context) {