mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Change the way to read interpreter language from interpreter-setting.json after #1145
This commit is contained in:
parent
75543b3ecf
commit
9e4f2e93d1
5 changed files with 72 additions and 16 deletions
|
|
@ -49,6 +49,7 @@ import java.util.Properties;
|
|||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
|
@ -223,7 +224,8 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
InterpreterInfo interpreterInfo;
|
||||
for (RegisteredInterpreter r : Interpreter.registeredInterpreters.values()) {
|
||||
interpreterInfo =
|
||||
new InterpreterInfo(r.getClassName(), r.getName(), r.isDefaultInterpreter());
|
||||
new InterpreterInfo(r.getClassName(), r.getName(), r.isDefaultInterpreter(),
|
||||
r.getEditor());
|
||||
add(r.getGroup(), interpreterInfo, convertInterpreterProperties(r.getProperties()),
|
||||
r.getPath());
|
||||
}
|
||||
|
|
@ -335,7 +337,7 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
for (RegisteredInterpreter registeredInterpreter : registeredInterpreters) {
|
||||
InterpreterInfo interpreterInfo =
|
||||
new InterpreterInfo(registeredInterpreter.getClassName(), registeredInterpreter.getName(),
|
||||
registeredInterpreter.isDefaultInterpreter());
|
||||
registeredInterpreter.isDefaultInterpreter(), registeredInterpreter.getEditor());
|
||||
Properties properties = new Properties();
|
||||
Map<String, InterpreterProperty> p = registeredInterpreter.getProperties();
|
||||
|
||||
|
|
@ -370,10 +372,11 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
fis.close();
|
||||
|
||||
String json = sb.toString();
|
||||
InterpreterInfoSaving info = gson.fromJson(json, InterpreterInfoSaving.class);
|
||||
InterpreterInfoSaving infoSaving = gson.fromJson(json, InterpreterInfoSaving.class);
|
||||
|
||||
for (String k : info.interpreterSettings.keySet()) {
|
||||
InterpreterSetting setting = info.interpreterSettings.get(k);
|
||||
for (String k : infoSaving.interpreterSettings.keySet()) {
|
||||
InterpreterSetting setting = infoSaving.interpreterSettings.get(k);
|
||||
List<InterpreterInfo> infos = setting.getInterpreterInfos();
|
||||
|
||||
// Always use separate interpreter process
|
||||
// While we decided to turn this feature on always (without providing
|
||||
|
|
@ -391,15 +394,23 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
depClassPath = interpreterSettingObject.getPath();
|
||||
setting.setPath(depClassPath);
|
||||
|
||||
for (InterpreterInfo info : infos) {
|
||||
if (info.getEditor() == null) {
|
||||
Map<String, Object> editor = getEditorFromSettingByClassName(interpreterSettingObject,
|
||||
info.getClassName());
|
||||
info.setEditor(editor);
|
||||
}
|
||||
}
|
||||
|
||||
setting.setInterpreterGroupFactory(this);
|
||||
loadInterpreterDependencies(setting);
|
||||
interpreterSettings.put(k, setting);
|
||||
}
|
||||
|
||||
this.interpreterBindings = info.interpreterBindings;
|
||||
this.interpreterBindings = infoSaving.interpreterBindings;
|
||||
|
||||
if (info.interpreterRepositories != null) {
|
||||
for (RemoteRepository repo : info.interpreterRepositories) {
|
||||
if (infoSaving.interpreterRepositories != null) {
|
||||
for (RemoteRepository repo : infoSaving.interpreterRepositories) {
|
||||
if (!depResolver.getRepos().contains(repo)) {
|
||||
this.interpreterRepositories.add(repo);
|
||||
}
|
||||
|
|
@ -407,6 +418,17 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> getEditorFromSettingByClassName(InterpreterSetting intpSetting,
|
||||
String className) {
|
||||
List<InterpreterInfo> intpInfos = intpSetting.getInterpreterInfos();
|
||||
for (InterpreterInfo intpInfo : intpInfos) {
|
||||
if (className.equals(intpInfo.getClassName())) {
|
||||
return intpInfo.getEditor();
|
||||
}
|
||||
}
|
||||
return ImmutableMap.of("language", (Object) "text");
|
||||
}
|
||||
|
||||
private void loadInterpreterDependencies(final InterpreterSetting setting) {
|
||||
|
||||
setting.setStatus(InterpreterSetting.Status.DOWNLOADING_DEPENDENCIES);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package org.apache.zeppelin.interpreter;
|
|||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Information of interpreters in this interpreter setting.
|
||||
* this will be serialized for conf/interpreter.json and REST api response.
|
||||
|
|
@ -27,11 +29,14 @@ public class InterpreterInfo {
|
|||
private String name;
|
||||
@SerializedName("class") private String className;
|
||||
private boolean defaultInterpreter = false;
|
||||
private Map<String, Object> editor;
|
||||
|
||||
InterpreterInfo(String className, String name, boolean defaultInterpreter) {
|
||||
InterpreterInfo(String className, String name, boolean defaultInterpreter,
|
||||
Map<String, Object> editor) {
|
||||
this.className = className;
|
||||
this.name = name;
|
||||
this.defaultInterpreter = defaultInterpreter;
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
@ -50,6 +55,14 @@ public class InterpreterInfo {
|
|||
return defaultInterpreter;
|
||||
}
|
||||
|
||||
public Map<String, Object> getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
public void setEditor(Map<String, Object> editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof InterpreterInfo)) {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -651,16 +653,35 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
}
|
||||
|
||||
public Interpreter getRepl(String name) {
|
||||
return factory.getInterpreter(id(), name);
|
||||
return factory.getInterpreter(getId(), name);
|
||||
}
|
||||
|
||||
public Map<String, Object> getEditorSetting(String replName) {
|
||||
Interpreter intp = getRepl(replName);
|
||||
Map<String, Object> editor = new HashMap<>();
|
||||
Map<String, Object> editor = Maps.newHashMap(
|
||||
ImmutableMap.<String, Object>builder()
|
||||
.put("language", "text").build());
|
||||
String defaultSettingName = factory.getDefaultInterpreterSetting(this.getId()).getName();
|
||||
String group = StringUtils.EMPTY;
|
||||
try {
|
||||
editor = intp.findRegisteredInterpreterByClassName(intp.getClassName()).getEditor();
|
||||
List<InterpreterSetting> intpSettings = factory.getInterpreterSettings(this.getId());
|
||||
for (InterpreterSetting intpSetting : intpSettings) {
|
||||
String[] replNameSplit = replName.split("\\.");
|
||||
if (replNameSplit.length == 2) {
|
||||
group = replNameSplit[0];
|
||||
}
|
||||
// when replName is 'name' of interpreter
|
||||
if (defaultSettingName.equals(intpSetting.getName())) {
|
||||
editor = factory.getEditorFromSettingByClassName(intpSetting, intp.getClassName());
|
||||
}
|
||||
// when replName is 'alias name' of interpreter or 'group' of interpreter
|
||||
if (replName.equals(intpSetting.getName()) || group.equals(intpSetting.getName())) {
|
||||
editor = factory.getEditorFromSettingByClassName(intpSetting, intp.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
editor.put("language", "text");
|
||||
logger.warn("Couldn't get interpreter editor language");
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,8 +166,8 @@ public class InterpreterFactoryTest {
|
|||
@Test
|
||||
public void testInterpreterAliases() throws IOException, RepositoryException {
|
||||
factory = new InterpreterFactory(conf, null, null, null, depResolver);
|
||||
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true);
|
||||
final InterpreterInfo info2 = new InterpreterInfo("className2", "name1", true);
|
||||
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null);
|
||||
final InterpreterInfo info2 = new InterpreterInfo("className2", "name1", true, null);
|
||||
factory.add("group1", new ArrayList<InterpreterInfo>(){{
|
||||
add(info1);
|
||||
}}, new ArrayList<Dependency>(), new InterpreterOption(true), new Properties(), "/path1");
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
|
||||
|
||||
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
|
||||
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver);
|
||||
factory = new InterpreterFactory(conf, new InterpreterOption(true), null, null, null, depResolver);
|
||||
|
||||
SearchService search = mock(SearchService.class);
|
||||
notebookRepo = new VFSNotebookRepo(conf);
|
||||
|
|
|
|||
Loading…
Reference in a new issue