liuxunorg commented on a change in pull request #3359: [ZEPPELIN-4131] 
Refactoring shell interpreter
URL: https://github.com/apache/zeppelin/pull/3359#discussion_r289765730
 
 

 ##########
 File path: 
shell/src/main/java/org/apache/zeppelin/shell/TerminalInterpreter.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zeppelin.shell;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.io.Resources;
+import com.hubspot.jinjava.Jinjava;
+import org.apache.commons.io.Charsets;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.zeppelin.interpreter.BaseZeppelinContext;
+import org.apache.zeppelin.interpreter.InterpreterContext;
+import org.apache.zeppelin.interpreter.InterpreterResult;
+import org.apache.zeppelin.interpreter.InterpreterResult.Code;
+import org.apache.zeppelin.interpreter.InterpreterResultMessageOutput;
+import org.apache.zeppelin.interpreter.KerberosInterpreter;
+import org.apache.zeppelin.interpreter.remote.RemoteInterpreterUtils;
+import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
+import org.apache.zeppelin.scheduler.Scheduler;
+import org.apache.zeppelin.scheduler.SchedulerFactory;
+import org.apache.zeppelin.shell.terminal.TerminalManager;
+import org.apache.zeppelin.shell.terminal.TerminalThread;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URL;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Shell interpreter for Zeppelin.
+ */
+public class TerminalInterpreter extends KerberosInterpreter {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(TerminalInterpreter.class);
+
+  public TerminalInterpreter(Properties property) {
+    super(property);
+  }
+
+  private TerminalThread terminalThread = null;
+
+  private InterpreterContext intpContext;
+
+  private int terminalPort = 0;
+
+  // terminal web socket status
+  // ui_templates/terminal-dashboard.jinja
+  public static final String TERMINAL_SOCKET_STATUS = "TERMINAL_SOCKET_STATUS";
+  public static final String TERMINAL_SOCKET_CONNECT = 
"TERMINAL_SOCKET_CONNECT";
+  public static final String TERMINAL_SOCKET_CLOSE = "TERMINAL_SOCKET_CLOSE";
+  public static final String TERMINAL_SOCKET_ERROR = "TERMINAL_SOCKET_ERROR";
+
+  @Override
+  public void open() {
+    super.open();
+  }
+
+  private void setParagraphConfig() {
+    intpContext.getConfig().put("editorHide", true);
+    intpContext.getConfig().put("title", false);
+  }
+
+  @Override
+  public void close() {
+    intpContext.getAngularObjectRegistry().add(TERMINAL_SOCKET_STATUS, 
TERMINAL_SOCKET_CLOSE,
+        intpContext.getNoteId(), intpContext.getParagraphId());
+    if (null != terminalThread) {
+      TerminalManager.getInstance().cleanIntpContext(intpContext.getNoteId());
+      terminalThread.stopRunning();
+    }
+    super.close();
+  }
+
+  @Override
+  public BaseZeppelinContext getZeppelinContext() {
+    return null;
+  }
+
+  @Override
+  public InterpreterResult internalInterpret(String cmd, InterpreterContext 
context) {
+    this.intpContext = context;
+    TerminalManager.getInstance().setInterpreterContext(context);
+
+    if (null == terminalThread) {
+      try {
+        terminalPort = 
RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
+        terminalThread = new TerminalThread(terminalPort);
+        terminalThread.start();
+      } catch (IOException e) {
+        LOGGER.error(e.getMessage(), e);
+        return new InterpreterResult(Code.ERROR, e.getMessage());
+      }
+
+      for (int i = 0; i < 5 && !terminalThread.isRunning(); i++) {
 
 Review comment:
   Ok, I am adding a timeout error log.
   But I want to change 5 to 10, wait a total of 5 seconds, it should be 
enough. Zeppelin has a lot of configuration items. right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to