in zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java [394:501]
protected InterpreterResult jobRun() throws Throwable {
try {
if (localProperties.getOrDefault("isRecover", "false").equals("false")) {
this.runtimeInfos.clear();
}
this.interpreter = getBindedInterpreter();
if (this.interpreter == null) {
LOGGER.error("Can not find interpreter name {}", intpText);
throw new RuntimeException("Can not find interpreter for " + intpText);
}
LOGGER.info("Run paragraph [paragraph_id: {}, interpreter: {}, note_id: {}, user: {}]",
getId(), this.interpreter.getClassName(), note.getId(), subject.getUser());
InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup)
interpreter.getInterpreterGroup()).getInterpreterSetting();
if (interpreterSetting.getStatus() != InterpreterSetting.Status.READY) {
String message = String.format("Interpreter Setting '%s' is not ready, its status is %s",
interpreterSetting.getName(), interpreterSetting.getStatus());
LOGGER.error(message);
throw new RuntimeException(message);
}
if (this.user != null) {
if (subject != null && !interpreterSetting.isUserAuthorized(subject.getUsersAndRoles())) {
String msg = String.format("%s has no permission for %s", subject.getUser(), intpText);
LOGGER.error(msg);
return new InterpreterResult(Code.ERROR, msg);
}
}
for (Paragraph p : userParagraphMap.values()) {
p.setText(getText());
}
// inject form
String script = this.scriptText;
String form = localProperties.getOrDefault("form", interpreter.getFormType().name());
if (form.equalsIgnoreCase("simple")) {
// inputs will be built from script body
LinkedHashMap<String, Input> inputs = Input.extractSimpleQueryForm(script, false);
LinkedHashMap<String, Input> noteInputs = Input.extractSimpleQueryForm(script, true);
final AngularObjectRegistry angularRegistry =
interpreter.getInterpreterGroup().getAngularObjectRegistry();
String scriptBody = extractVariablesFromAngularRegistry(script, inputs, angularRegistry);
settings.setForms(inputs);
if (!noteInputs.isEmpty()) {
if (!note.getNoteForms().isEmpty()) {
Map<String, Input> currentNoteForms = note.getNoteForms();
for (String s : noteInputs.keySet()) {
if (!currentNoteForms.containsKey(s)) {
currentNoteForms.put(s, noteInputs.get(s));
}
}
} else {
note.setNoteForms(noteInputs);
}
}
script = Input.getSimpleQuery(note.getNoteParams(), scriptBody, true);
script = Input.getSimpleQuery(settings.getParams(), script, false);
} else {
settings.clear();
}
LOGGER.debug("RUN : {}", script);
try {
InterpreterContext context = getInterpreterContext();
InterpreterContext.set(context);
// Inject credentials
String injectPropStr = interpreter.getProperty(Constants.INJECT_CREDENTIALS, "false");
injectPropStr = context.getStringLocalProperty(Constants.INJECT_CREDENTIALS, injectPropStr);
boolean shouldInjectCredentials = Boolean.parseBoolean(injectPropStr);
InterpreterResult ret = null;
if (shouldInjectCredentials) {
UserCredentials creds = context.getAuthenticationInfo().getUserCredentials();
CredentialInjector credinjector = new CredentialInjector(creds);
String code = credinjector.replaceCredentials(script);
ret = interpreter.interpret(code, context);
ret = credinjector.hidePasswords(ret);
} else {
ret = interpreter.interpret(script, context);
}
if (interpreter.getFormType() == FormType.NATIVE) {
note.setNoteParams(context.getNoteGui().getParams());
note.setNoteForms(context.getNoteGui().getForms());
}
if (Code.KEEP_PREVIOUS_RESULT == ret.code()) {
return getReturn();
}
Paragraph p = getUserParagraph(getUser());
if (null != p) {
p.setResult(ret);
p.settings.setParams(settings.getParams());
}
return ret;
} finally {
InterpreterContext.remove();
}
} catch (Exception e) {
return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e));
} finally {
localProperties.remove("isRecover");
}
}