Repository: incubator-zeppelin Updated Branches: refs/heads/master a0428f06d -> b33bf5000
Fix process creation behavior #52 introduces new side effect around creation of interpreter process. As a result, some functions, such as 'z.run(2)' wouldn't able to run. This includes fix and unit test. Author: Lee moon soo <[email protected]> Closes #57 from Leemoonsoo/fix_process_creation and squashes the following commits: 018af91 [Lee moon soo] make code clean 0379410 [Lee moon soo] Fix process creation behavior Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/b33bf500 Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/b33bf500 Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/b33bf500 Branch: refs/heads/master Commit: b33bf5000f667c6e258477b66b6fc0b3615516dd Parents: a0428f0 Author: Lee moon soo <[email protected]> Authored: Thu Apr 30 10:15:08 2015 +0900 Committer: Lee moon soo <[email protected]> Committed: Thu Apr 30 19:54:15 2015 +0900 ---------------------------------------------------------------------- .../interpreter/remote/RemoteInterpreter.java | 23 ++++++++++---------- .../remote/RemoteInterpreterTest.java | 21 ++++++++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/b33bf500/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java index fbadce9..4f1e262 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java @@ -324,18 +324,19 @@ public class RemoteInterpreter extends Interpreter { super.setInterpreterGroup(interpreterGroup); synchronized (interpreterGroupReference) { - if (interpreterGroupReference - .containsKey(getInterpreterGroupKey(interpreterGroup))) { - interpreterGroupReference.remove(getInterpreterGroupKey(interpreterGroup)); + RemoteInterpreterProcess intpProcess = interpreterGroupReference + .get(getInterpreterGroupKey(interpreterGroup)); + + // when interpreter process is not created or terminated + if (intpProcess == null || (!intpProcess.isRunning() && intpProcess.getPort() > 0)) { + interpreterGroupReference.put(getInterpreterGroupKey(interpreterGroup), + new RemoteInterpreterProcess(interpreterRunner, + interpreterPath, env, interpreterContextRunnerPool)); + + logger.info("setInterpreterGroup = " + + getInterpreterGroupKey(interpreterGroup) + " class=" + className + + ", path=" + interpreterPath); } - - interpreterGroupReference.put(getInterpreterGroupKey(interpreterGroup), - new RemoteInterpreterProcess(interpreterRunner, - interpreterPath, env, interpreterContextRunnerPool)); - - logger.info("setInterpreterGroup = " - + getInterpreterGroupKey(interpreterGroup) + " class=" + className - + ", path=" + interpreterPath); } } http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/b33bf500/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java index e743eab..0661bfa 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java @@ -457,4 +457,25 @@ public class RemoteInterpreterTest { intpA.close(); } + + @Test + public void testProcessCreation() { + Properties p = new Properties(); + + RemoteInterpreter intpA = new RemoteInterpreter( + p, + MockInterpreterA.class.getName(), + new File("../bin/interpreter.sh").getAbsolutePath(), + "fake", + env + ); + + intpA.setInterpreterGroup(intpGroup); + RemoteInterpreterProcess processA = intpA.getInterpreterProcess(); + + intpA.setInterpreterGroup(new InterpreterGroup(intpA.getInterpreterGroup().getId())); + RemoteInterpreterProcess processB = intpA.getInterpreterProcess(); + + assertEquals(processA.hashCode(), processB.hashCode()); + } }
