Automatically detect default interpreter for registerHook()

This commit is contained in:
Alex Goodman 2016-10-06 15:55:40 -07:00
parent 044a99ddd7
commit 56ede60780
3 changed files with 22 additions and 31 deletions

View file

@ -716,10 +716,16 @@ public class ZeppelinContext {
}
/**
* Get the interpreter class name from repl name entered in paragraph
* @param replName
* Get the interpreter class name from name entered in paragraph
* @param replName if replName is a valid className, return that instead.
*/
public String getClassNameFromReplName(String replName) {
for (String name : interpreterClassMap.values()) {
if (replName.equals(name)) {
return replName;
}
}
if (replName.contains("spark.")) {
replName = replName.replace("spark.", "");
}
@ -746,8 +752,8 @@ public class ZeppelinContext {
*/
@Experimental
public void registerHook(String event, String cmd) {
String replName = interpreterContext.getRequiredReplName();
registerHook(event, cmd, replName);
String className = interpreterContext.getClassName();
registerHook(event, cmd, className);
}
/**
@ -768,8 +774,8 @@ public class ZeppelinContext {
*/
@Experimental
public String getHook(String event) {
String replName = interpreterContext.getRequiredReplName();
return getHook(event, replName);
String className = interpreterContext.getClassName();
return getHook(event, className);
}
/**
@ -790,8 +796,8 @@ public class ZeppelinContext {
*/
@Experimental
public void unregisterHook(String event) {
String replName = interpreterContext.getRequiredReplName();
unregisterHook(event, replName);
String className = interpreterContext.getClassName();
unregisterHook(event, className);
}
/**

View file

@ -57,6 +57,7 @@ public class InterpreterContext {
private AngularObjectRegistry angularObjectRegistry;
private ResourcePool resourcePool;
private List<InterpreterContextRunner> runners;
private String className;
public InterpreterContext(String noteId,
String paragraphId,
@ -124,28 +125,11 @@ public class InterpreterContext {
return runners;
}
public String getRequiredReplName() {
if (paragraphText == null) {
return null;
}
// get script head
int scriptHeadIndex = 0;
for (int i = 0; i < paragraphText.length(); i++) {
char ch = paragraphText.charAt(i);
if (Character.isWhitespace(ch) || ch == '(') {
scriptHeadIndex = i;
break;
}
}
if (scriptHeadIndex == 0) {
return null;
}
String head = paragraphText.substring(0, scriptHeadIndex);
if (head.startsWith("%")) {
return head.substring(1);
} else {
return null;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}

View file

@ -295,6 +295,7 @@ public class RemoteInterpreterServer
}
Interpreter intp = getInterpreter(noteId, className);
InterpreterContext context = convert(interpreterContext);
context.setClassName(intp.getClassName());
Scheduler scheduler = intp.getScheduler();
InterpretJobListener jobListener = new InterpretJobListener();