ZEPPELIN-2999: Cannot create shell interpreter without timeout property

This commit is contained in:
Prabhjyot Singh 2017-10-23 12:13:24 +05:30
parent 84cb4b5fb9
commit e2a62f63d2

View file

@ -47,7 +47,10 @@ import org.slf4j.LoggerFactory;
*/
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 Long DEFAULT_TIMEOUT_PROPERTY = 60000l;
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";
@ -98,7 +101,15 @@ public class ShellInterpreter extends KerberosInterpreter {
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(
contextInterpreter.out, contextInterpreter.out));
executor.setWatchdog(new ExecuteWatchdog(Long.valueOf(getProperty(TIMEOUT_PROPERTY))));
Long timeOutProperty;
try {
timeOutProperty = Long.valueOf(getProperty(TIMEOUT_PROPERTY));
} catch (Exception e) {
timeOutProperty = DEFAULT_TIMEOUT_PROPERTY;
LOGGER.error("Cannot convert TIMEOUT_PROPERTY to Long value, switching to default value", e);
}
executor.setWatchdog(new ExecuteWatchdog(timeOutProperty));
executors.put(contextInterpreter.getParagraphId(), executor);
if (Boolean.valueOf(getProperty(DIRECTORY_USER_HOME))) {
executor.setWorkingDirectory(new File(System.getProperty("user.home")));