Search in sources :

Example 1 with StringMap

use of com.google.gson.internal.StringMap in project zeppelin by apache.

the class InterpreterSettingManager method loadFromFile.

private void loadFromFile() {
    if (!Files.exists(interpreterBindingPath)) {
        // nothing to read
        return;
    }
    InterpreterInfoSaving infoSaving;
    try (BufferedReader json = Files.newBufferedReader(interpreterBindingPath, StandardCharsets.UTF_8)) {
        infoSaving = gson.fromJson(json, InterpreterInfoSaving.class);
        for (String k : infoSaving.interpreterSettings.keySet()) {
            InterpreterSetting setting = infoSaving.interpreterSettings.get(k);
            List<InterpreterInfo> infos = setting.getInterpreterInfos();
            // Convert json StringMap to Properties
            StringMap<String> p = (StringMap<String>) setting.getProperties();
            Properties properties = new Properties();
            for (String key : p.keySet()) {
                properties.put(key, p.get(key));
            }
            setting.setProperties(properties);
            // Always use separate interpreter process
            // While we decided to turn this feature on always (without providing
            // enable/disable option on GUI).
            // previously created setting should turn this feature on here.
            setting.getOption().setRemote(true);
            // Update transient information from InterpreterSettingRef
            InterpreterSetting interpreterSettingObject = interpreterSettingsRef.get(setting.getGroup());
            if (interpreterSettingObject == null) {
                logger.warn("can't get InterpreterSetting " + "Information From loaded Interpreter Setting Ref - {} ", setting.getGroup());
                continue;
            }
            String 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(interpreterGroupFactory);
            loadInterpreterDependencies(setting);
            interpreterSettings.put(k, setting);
        }
        interpreterBindings.putAll(infoSaving.interpreterBindings);
        if (infoSaving.interpreterRepositories != null) {
            for (RemoteRepository repo : infoSaving.interpreterRepositories) {
                if (!dependencyResolver.getRepos().contains(repo)) {
                    this.interpreterRepositories.add(repo);
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : StringMap(com.google.gson.internal.StringMap) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) Properties(java.util.Properties) BufferedReader(java.io.BufferedReader)

Aggregations

StringMap (com.google.gson.internal.StringMap)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)1