From c4b016ecbe0c4494c1bda7e353cd4775096f26eb Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Tue, 5 Jul 2016 17:26:31 +0900 Subject: [PATCH 01/24] Refactored getInterpreter method not to use RegisteredInterpreter --- .../interpreter/InterpreterFactory.java | 106 +++++++++++------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index 3fed07f7c54..23341d3a083 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -17,6 +17,7 @@ package org.apache.zeppelin.interpreter; +import com.google.common.base.Preconditions; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -1001,8 +1002,53 @@ public InterpreterSetting getDefaultInterpreterSetting(String noteId) { return getDefaultInterpreterSetting(getInterpreterSettings(noteId)); } + + private InterpreterSetting getInterpreterSettingByGroup(List settings, + String group) { + Preconditions.checkNotNull(group, "group should be not null"); + + for (InterpreterSetting setting : settings) { + if (group.equals(setting.getGroup())) { + return setting; + } + } + return null; + } + + private String getInterpreterClassFromInterpreterSetting(InterpreterSetting setting, + String name) { + Preconditions.checkNotNull(name, "name should be not null"); + + for (InterpreterSetting.InterpreterInfo info : setting.getInterpreterInfos()) { + String infoName = info.getName(); + if (null != info.getName() && name.equals(infoName)) { + return info.getClassName(); + } + } + return null; + } + + private Interpreter getInterpreter(String noteId, InterpreterSetting setting, String name) { + Preconditions.checkNotNull(noteId, "noteId should be not null"); + Preconditions.checkNotNull(setting, "setting should be not null"); + Preconditions.checkNotNull(name, "name should be not null"); + + String className; + if (null != (className = getInterpreterClassFromInterpreterSetting(setting, name))) { + List interpreterGroup = createOrGetInterpreterList(noteId, setting); + for (Interpreter interpreter : interpreterGroup) { + if (className.equals(interpreter.getClassName())) { + return interpreter; + } + } + } + return null; + } + public Interpreter getInterpreter(String noteId, String replName) { List settings = getInterpreterSettings(noteId); + InterpreterSetting setting; + Interpreter interpreter; if (settings == null || settings.size() == 0) { return null; @@ -1020,61 +1066,43 @@ public Interpreter getInterpreter(String noteId, String replName) { } String[] replNameSplit = replName.split("\\."); - String group = null; - String name = null; if (replNameSplit.length == 2) { + String group = null; + String name = null; group = replNameSplit[0]; name = replNameSplit[1]; - Interpreter.RegisteredInterpreter registeredInterpreter = Interpreter.registeredInterpreters - .get(group + "." + name); - if (registeredInterpreter == null - || registeredInterpreter.getClassName() == null) { - throw new InterpreterException(replName + " interpreter not found"); - } - String interpreterClassName = registeredInterpreter.getClassName(); - - for (InterpreterSetting setting : settings) { - if (registeredInterpreter.getGroup().equals(setting.getGroup())) { - List intpGroup = createOrGetInterpreterList(noteId, setting); - for (Interpreter interpreter : intpGroup) { - if (interpreterClassName.equals(interpreter.getClassName())) { - return interpreter; - } - } + setting = getInterpreterSettingByGroup(settings, group); + + if (null != setting) { + interpreter = getInterpreter(noteId, setting, name); + + if (null != interpreter) { + return interpreter; } } + throw new InterpreterException(replName + " interpreter not found"); + } else { // first assume replName is 'name' of interpreter. ('groupName' is ommitted) // search 'name' from first (default) interpreter group - InterpreterSetting defaultSetting = getDefaultInterpreterSetting(settings); - Interpreter.RegisteredInterpreter registeredInterpreter = - Interpreter.registeredInterpreters.get(defaultSetting.getGroup() + "." + replName); - if (registeredInterpreter != null) { - List interpreters = createOrGetInterpreterList(noteId, defaultSetting); - for (Interpreter interpreter : interpreters) { - - RegisteredInterpreter intp = - Interpreter.findRegisteredInterpreterByClassName(interpreter.getClassName()); - if (intp == null) { - continue; - } + // TODO(jl): Handle with noteId to support defaultInterpreter per note. + setting = getDefaultInterpreterSetting(settings); - if (intp.getName().equals(replName)) { - return interpreter; - } - } + interpreter = getInterpreter(noteId, setting, replName); - throw new InterpreterException( - defaultSetting.getGroup() + "." + replName + " interpreter not found"); + if (null != interpreter) { + return interpreter; } // next, assume replName is 'group' of interpreter ('name' is ommitted) // search interpreter group and return first interpreter. - for (InterpreterSetting setting : settings) { - if (setting.getGroup().equals(replName)) { - List interpreters = createOrGetInterpreterList(noteId, setting); + setting = getInterpreterSettingByGroup(settings, replName); + + if (null != setting) { + List interpreters = createOrGetInterpreterList(noteId, setting); + if (null != interpreters) { return interpreters.get(0); } } From 5159a84843c464ab2ff1415924883b3b87116296 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Thu, 7 Jul 2016 19:40:35 +0900 Subject: [PATCH 02/24] Added feature for Interpreter aliases Extracted InterpreterInfo from InterpreterSetting --- .../zeppelin/rest/InterpreterRestApi.java | 11 +- .../InterpreterSettingListForNoteBind.java | 11 +- .../message/NewInterpreterSettingRequest.java | 5 + .../zeppelin/rest/AbstractTestRestApi.java | 12 - .../interpreter-create.html | 8 +- .../helium/HeliumApplicationFactory.java | 5 +- .../interpreter/InterpreterFactory.java | 313 +++++++++++------- .../zeppelin/interpreter/InterpreterInfo.java | 82 +++++ .../interpreter/InterpreterSetting.java | 80 +++-- .../interpreter/InterpreterFactoryTest.java | 32 +- 10 files changed, 376 insertions(+), 183 deletions(-) create mode 100644 zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfo.java diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index 9af0a60cd94..85d3172024d 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -97,8 +97,9 @@ public Response newSettings(String message) { NewInterpreterSettingRequest.class); Properties p = new Properties(); p.putAll(request.getProperties()); - InterpreterSetting interpreterSetting = interpreterFactory.add(request.getName(), + InterpreterSetting interpreterSetting = interpreterFactory.createNewSetting(request.getName(), request.getGroup(), + request.getRefGroup(), request.getDependencies(), request.getOption(), p); @@ -110,12 +111,6 @@ public Response newSettings(String message) { Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); - } catch (IOException | RepositoryException e) { - logger.error("Exception in InterpreterRestApi while creating ", e); - return new JsonResponse( - Status.INTERNAL_SERVER_ERROR, - e.getMessage(), - ExceptionUtils.getStackTrace(e)).build(); } } @@ -188,7 +183,7 @@ public Response restartSetting(@PathParam("settingId") String settingId) { @GET @ZeppelinApi public Response listInterpreter(String message) { - Map m = Interpreter.registeredInterpreters; + Map m = interpreterFactory.getAvailableInterpreterSettings(); return new JsonResponse(Status.OK, "", m).build(); } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java index e0ddacbbf92..6fd8ccf2ee9 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java @@ -19,8 +19,7 @@ import java.util.List; -import org.apache.zeppelin.interpreter.Interpreter; -import org.apache.zeppelin.interpreter.InterpreterSetting; +import org.apache.zeppelin.interpreter.InterpreterInfo; /** * InterpreterSetting information for binding @@ -30,11 +29,11 @@ public class InterpreterSettingListForNoteBind { String name; String group; private boolean selected; - private List interpreters; + private List interpreters; public InterpreterSettingListForNoteBind(String id, String name, String group, - List interpreters, + List interpreters, boolean selected) { super(); this.id = id; @@ -68,11 +67,11 @@ public void setGroup(String group) { this.group = group; } - public List getInterpreterNames() { + public List getInterpreterNames() { return interpreters; } - public void setInterpreterNames(List interpreters) { + public void setInterpreterNames(List interpreters) { this.interpreters = interpreters; } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java index a559fb53e87..d6a0f73b66d 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java @@ -30,6 +30,7 @@ public class NewInterpreterSettingRequest { String name; String group; + String refGroup; Map properties; List dependencies; @@ -47,6 +48,10 @@ public String getGroup() { return group; } + public String getRefGroup() { + return refGroup; + } + public Map getProperties() { return properties; } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java index f2d4c99ca49..fee19120b36 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java @@ -375,18 +375,6 @@ protected void describeMismatchSafely(String item, Description description) { }; } - //Create new Setting and return Setting ID - protected String createTempSetting(String tempName) - throws IOException, RepositoryException { - InterpreterSetting setting = ZeppelinServer.notebook.getInterpreterFactory() - .add(tempName, - "newGroup", - new LinkedList(), - new InterpreterOption(false), - new Properties()); - return setting.id(); - } - protected TypeSafeMatcher hasRootElementNamed(final String memberName) { return new TypeSafeMatcher() { @Override diff --git a/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html b/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html index 97e3103dbc4..70a4e73f0f5 100644 --- a/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html +++ b/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html @@ -24,10 +24,16 @@

Create new interpreter

pu-elastic-input-minwidth="180px" ng-model="newInterpreterSetting.name" /> +
+ Alias + +
+ Interpreter group
-
-
- Alias - -
- Interpreter group
-
diff --git a/zeppelin-web/src/app/interpreter/interpreter.controller.js b/zeppelin-web/src/app/interpreter/interpreter.controller.js index 5a90b79cd26..dbe26b33a8a 100644 --- a/zeppelin-web/src/app/interpreter/interpreter.controller.js +++ b/zeppelin-web/src/app/interpreter/interpreter.controller.js @@ -34,6 +34,7 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', var getAvailableInterpreters = function() { $http.get(baseUrlSrv.getRestApiBase() + '/interpreter').success(function(data, status, headers, config) { $scope.availableInterpreters = data.body; + console.log(data.body); }).error(function(data, status, headers, config) { console.log('Error %o %o', status, data.message); }); @@ -184,15 +185,14 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', }; $scope.newInterpreterGroupChange = function() { - var el = _.pluck(_.filter($scope.availableInterpreters, {'group': $scope.newInterpreterSetting.group}), + var el = _.pluck(_.filter($scope.availableInterpreters, {'name': $scope.newInterpreterSetting.refName}), 'properties'); - var properties = {}; for (var i = 0; i < el.length; i++) { var intpInfo = el[i]; for (var key in intpInfo) { properties[key] = { - value: intpInfo[key].defaultValue, + value: intpInfo[key], description: intpInfo[key].description }; } @@ -222,7 +222,7 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', $scope.addNewInterpreterSetting = function() { //user input validation on interpreter creation - if (!$scope.newInterpreterSetting.name.trim() || !$scope.newInterpreterSetting.group) { + if (!$scope.newInterpreterSetting.name.trim() || !$scope.newInterpreterSetting.refName) { BootstrapDialog.alert({ closable: true, title: 'Add interpreter', diff --git a/zeppelin-web/src/app/interpreter/interpreter.html b/zeppelin-web/src/app/interpreter/interpreter.html index af3b8446229..9e07019657b 100644 --- a/zeppelin-web/src/app/interpreter/interpreter.html +++ b/zeppelin-web/src/app/interpreter/interpreter.html @@ -87,7 +87,7 @@

Repositories

+ ng-repeat="setting in interpreterSettings | orderBy: 'name' | filter: searchInterpreter">
@@ -96,7 +96,7 @@

{{setting.name}} , - %{{setting.group}}{{setting.name}}.{{interpreter.name}} (default) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index 437ba3d6814..ad8ee465634 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -194,15 +194,17 @@ public boolean accept(Path entry) throws IOException { } // RegisteredInterpreters -> interpreterSettingRef + InterpreterInfo interpreterInfo; for (RegisteredInterpreter r : Interpreter.registeredInterpreters.values()) { - add(r.getName(), r.getGroup(), - new InterpreterInfo(r.getClassName(), r.getName(), r.isDefaultInterpreter()), - convertInterpreterProperties(r.getProperties()), r.getPath()); + interpreterInfo = + new InterpreterInfo(r.getClassName(), r.getName(), r.isDefaultInterpreter()); + add(r.getGroup(), interpreterInfo, convertInterpreterProperties(r.getProperties()), + r.getPath()); } for (String settingId : interpreterSettingsRef.keySet()) { InterpreterSetting setting = interpreterSettingsRef.get(settingId); - logger.info("InterpreterSetting group {} : id={}, name={}", setting.getGroup(), settingId, + logger.info("InterpreterSettingRef group {} : id={}, name={}", setting.getGroup(), settingId, setting.getName()); } @@ -211,24 +213,26 @@ public boolean accept(Path entry) throws IOException { // if no interpreter settings are loaded, create default set if (0 == interpreterSettings.size()) { Map temp = new HashMap<>(); + InterpreterSetting interpreterSetting; for (InterpreterSetting setting : interpreterSettingsRef.values()) { - setting.setRefGroup(setting.getGroup()); - temp.put(setting.getGroup(), setting); + interpreterSetting = createFromInterpreterSettingRef(setting); + temp.put(setting.getName(), interpreterSetting); } - InterpreterSetting interpreterSetting; for (String group : interpreterGroupOrderList) { if (null != (interpreterSetting = temp.remove(group))) { - interpreterSettings.put(interpreterSetting.id(), interpreterSetting); + interpreterSettings.put(interpreterSetting.getId(), interpreterSetting); } } for (InterpreterSetting setting : temp.values()) { - interpreterSettings.put(setting.id(), setting); + interpreterSettings.put(setting.getId(), setting); } + saveToFile(); } + for (String settingId : interpreterSettings.keySet()) { InterpreterSetting setting = interpreterSettings.get(settingId); logger.info("InterpreterSetting group {} : id={}, name={}", setting.getGroup(), settingId, @@ -236,6 +240,20 @@ public boolean accept(Path entry) throws IOException { } } + private InterpreterSetting createFromInterpreterSettingRef(String name) { + Preconditions.checkNotNull(name, "reference name should be not null"); + InterpreterSetting settingRef = interpreterSettingsRef.get(name); + return createFromInterpreterSettingRef(settingRef); + } + + private InterpreterSetting createFromInterpreterSettingRef(InterpreterSetting o) { + InterpreterSetting setting = new InterpreterSetting(o.getName(), o.getName(), + o.getInterpreterInfos(), o.getProperties(), o.getDependencies(), o.getOption(), + o.getPath()); + setting.setInterpreterGroupFactory(this); + return setting; + } + private Properties convertInterpreterProperties(Map p) { Properties properties = new Properties(); for (String key : p.keySet()) { @@ -298,8 +316,7 @@ private void registerInterpreters(List registeredInterpre } } - add(registeredInterpreter.getName(), registeredInterpreter.getGroup(), interpreterInfo, - properties, absolutePath); + add(registeredInterpreter.getGroup(), interpreterInfo, properties, absolutePath); } } @@ -338,17 +355,21 @@ private void loadFromFile() throws IOException { // previously created setting should turn this feature on here. setting.getOption().setRemote(true); - InterpreterSetting intpSetting = new InterpreterSetting(setting.id(), setting.getName(), - setting.getGroup(), setting.getRefGroup(), setting.getInterpreterInfos(), - setting.getProperties(), setting.getDependencies(), setting.getOption(), - setting.getPath()); - - if (null == setting.getRefGroup()) { - intpSetting.setRefGroup(setting.getGroup()); + /** + * Check whether it's old setting or not. If it's old, set the refName from group + */ + if (null == setting.getRefName()) { + setting.setRefName(setting.getGroup()); } - intpSetting.setInterpreterGroupFactory(this); - interpreterSettings.put(k, intpSetting); + /** + * Update transient information from InterpreterSettingRef + */ + // TODO(jl): Check if reference of setting is null + setting.setPath(interpreterSettingsRef.get(setting.getRefName()).getPath()); + + setting.setInterpreterGroupFactory(this); + interpreterSettings.put(k, setting); } this.interpreterBindings = info.interpreterBindings; @@ -365,7 +386,7 @@ private void loadFromFile() throws IOException { private void loadInterpreterDependencies(InterpreterSetting intSetting) throws IOException, RepositoryException { // dependencies to prevent library conflict - File localRepoDir = new File(conf.getInterpreterLocalRepoPath() + "/" + intSetting.id()); + File localRepoDir = new File(conf.getInterpreterLocalRepoPath() + "/" + intSetting.getId()); if (localRepoDir.exists()) { FileUtils.cleanDirectory(localRepoDir); } @@ -378,9 +399,9 @@ private void loadInterpreterDependencies(InterpreterSetting intSetting) if (d.getExclusions() != null) { depResolver.load(d.getGroupArtifactVersion(), d.getExclusions(), - new File(destDir, intSetting.id())); + new File(destDir, intSetting.getId())); } else { - depResolver.load(d.getGroupArtifactVersion(), new File(destDir, intSetting.id())); + depResolver.load(d.getGroupArtifactVersion(), new File(destDir, intSetting.getId())); } } } @@ -427,12 +448,12 @@ public List getDefaultInterpreterSettingList() { List sortedSettings = get(); for (InterpreterSetting setting : sortedSettings) { - if (defaultSettings.contains(setting.id())) { + if (defaultSettings.contains(setting.getId())) { continue; } if (!interpreterGroupCheck.containsKey(setting.getGroup())) { - defaultSettings.add(setting.id()); + defaultSettings.add(setting.getId()); interpreterGroupCheck.put(setting.getGroup(), true); } } @@ -452,44 +473,38 @@ public boolean findDefaultInterpreter(List infos) { return false; } - public InterpreterSetting createNewSetting(String name, String group, String refGroup, + public InterpreterSetting createNewSetting(String name, String refName, List dependencies, InterpreterOption option, Properties p) { - InterpreterSetting interpreterSetting = - new InterpreterSetting(interpreterSettingsRef.get(refGroup)); - interpreterSetting.regenerateId(); - interpreterSetting.setName(name); - interpreterSetting.setGroup(group); - interpreterSetting.setRefGroup(refGroup); - interpreterSetting.appendDependencies(dependencies); - interpreterSetting.setInterpreterOption(option); - interpreterSetting.updateProperties(p); - interpreterSetting.setInterpreterGroupFactory(this); - interpreterSettings.put(interpreterSetting.id(), interpreterSetting); - return interpreterSetting; + InterpreterSetting setting = createFromInterpreterSettingRef(refName); + setting.setName(name); + setting.setRefName(refName); + setting.appendDependencies(dependencies); + setting.setInterpreterOption(option); + setting.updateProperties(p); + setting.setInterpreterGroupFactory(this); + interpreterSettings.put(setting.getId(), setting); + return setting; } - private InterpreterSetting add(String name, String group, + private InterpreterSetting add(String refName, InterpreterInfo interpreterInfo, Properties properties, String path) throws InterpreterException, IOException, RepositoryException { ArrayList infos = new ArrayList<>(); infos.add(interpreterInfo); - return add(name, group, infos, new ArrayList(), defaultOption, properties, path); + return add(refName, infos, new ArrayList(), defaultOption, properties, path); } /** - * @param name user defined name - * @param group interpreter group name to instantiate + * @param refName user defined name * @param properties * @return * @throws InterpreterException * @throws IOException */ - public InterpreterSetting add(String name, String group, - ArrayList interpreterInfos, List dependencies, - InterpreterOption option, Properties properties, String path) + public InterpreterSetting add(String refName, ArrayList interpreterInfos, + List dependencies, InterpreterOption option, Properties properties, String path) throws InterpreterException, IOException, RepositoryException { - Preconditions.checkNotNull(name, "name should not be null"); - Preconditions.checkNotNull(group, "group should not be null"); + Preconditions.checkNotNull(refName, "name should not be null"); Preconditions.checkNotNull(interpreterInfos, "interpreterInfos should not be null"); Preconditions.checkNotNull(dependencies, "dependencies should not be null"); Preconditions.checkNotNull(option, "option should not be null"); @@ -499,8 +514,8 @@ public InterpreterSetting add(String name, String group, InterpreterSetting interpreterSetting; synchronized (interpreterSettingsRef) { - if (interpreterSettingsRef.containsKey(group)) { - interpreterSetting = interpreterSettingsRef.get(group); + if (interpreterSettingsRef.containsKey(refName)) { + interpreterSetting = interpreterSettingsRef.get(refName); // Append InterpreterInfo List infos = interpreterSetting.getInterpreterInfos(); @@ -533,9 +548,9 @@ public InterpreterSetting add(String name, String group, } } else { - interpreterSetting = new InterpreterSetting(name, group, interpreterInfos, properties, + interpreterSetting = new InterpreterSetting(refName, null, interpreterInfos, properties, dependencies, option, path); - interpreterSettingsRef.put(group, interpreterSetting); + interpreterSettingsRef.put(refName, interpreterSetting); } } @@ -625,7 +640,7 @@ public void createInterpretersForNote(InterpreterSetting interpreterSetting, Str List interpreterInfos = interpreterSetting.getInterpreterInfos(); InterpreterSetting refInterpreterSetting = - interpreterSettingsRef.get(interpreterSetting.getRefGroup()); + interpreterSettingsRef.get(interpreterSetting.getRefName()); String path = refInterpreterSetting.getPath(); Interpreter interpreter; for (InterpreterInfo info : interpreterInfos) { @@ -635,7 +650,7 @@ public void createInterpretersForNote(InterpreterSetting interpreterSetting, Str option.getPort(), properties); } else { interpreter = createRemoteRepl(path, key, info.getClassName(), - properties, interpreterSetting.id()); + properties, interpreterSetting.getId()); } } else { interpreter = createRepl(interpreterSetting.getPath(), info.getClassName(), properties); @@ -802,7 +817,7 @@ public void setPropertyAndRestart(String id, InterpreterOption option, Propertie intpsetting.closeAndRmoveAllInterpreterGroups(); intpsetting.setOption(option); - intpsetting.setProperties(properties); + intpsetting.updateProperties(properties); intpsetting.setDependencies(dependencies); loadInterpreterDependencies(intpsetting); @@ -1075,7 +1090,7 @@ private InterpreterSetting getInterpreterSettingByGroup(List Preconditions.checkNotNull(group, "group should be not null"); for (InterpreterSetting setting : settings) { - if (group.equals(setting.getGroup())) { + if (group.equals(setting.getName())) { return setting; } } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java index 1a8400c2053..f951d78a057 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java @@ -17,10 +17,18 @@ package org.apache.zeppelin.interpreter; -import java.util.*; - +import com.google.gson.annotations.SerializedName; import org.apache.zeppelin.dep.Dependency; -import org.apache.zeppelin.notebook.utility.IdHashes; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import static org.apache.zeppelin.notebook.utility.IdHashes.generateId; /** * Interpreter settings @@ -29,90 +37,69 @@ public class InterpreterSetting { private static final String SHARED_PROCESS = "shared_process"; private String id; private String name; - private String group; - private String refGroup = null; - private String description; + private String refName; // always be null in case of InterpreterSettingRef private Properties properties; - private transient InterpreterGroupFactory interpreterGroupFactory; - private transient String InterpreterPath; - // use 'interpreterGroup' as a field name to keep backward compatibility of - // conf/interpreter.json file format - private List interpreterGroup; + @SerializedName("interpreterGroup") + private List interpreterInfos; private transient Map interpreterGroupRef = new HashMap<>(); private List dependencies; private InterpreterOption option; private transient String path; - public InterpreterSetting(String id, String name, String group, String refGroup, + @Deprecated + private String group; + @Deprecated + private transient InterpreterGroupFactory interpreterGroupFactory; + + public InterpreterSetting() { + + } + + public InterpreterSetting(String id, String name, String refName, List interpreterInfos, Properties properties, List dependencies, InterpreterOption option, String path) { this.id = id; this.name = name; - this.group = group; - this.refGroup = refGroup; - this.interpreterGroup = interpreterInfos; + this.refName = refName; + this.interpreterInfos = interpreterInfos; this.properties = properties; this.dependencies = dependencies; this.option = option; this.path = path; } - public InterpreterSetting(String name, String group, List interpreterInfos, + public InterpreterSetting(String name, String refName, List interpreterInfos, Properties properties, List dependencies, InterpreterOption option, String path) { - this(generateId(), name, group, null, interpreterInfos, properties, dependencies, option, path); + this(generateId(), name, refName, interpreterInfos, properties, dependencies, option, path); } + /** + * Create interpreter from interpreterSettingRef + * @param o interpreterSetting from interpreterSettingRef + */ public InterpreterSetting(InterpreterSetting o) { - this(generateId(), o.getName(), o.getGroup(), o.getRefGroup(), o.getInterpreterInfos(), - o.getProperties(), o.getDependencies(), o.getOption(), o.getPath()); - this.refGroup = o.getRefGroup(); + this(generateId(), o.getName(), o.getRefName(), o.getInterpreterInfos(), o.getProperties(), + o.getDependencies(), o.getOption(), o.getPath()); } - public String id() { + public String getId() { return id; } - public void regenerateId() { - this.id = generateId(); - } - - private static String generateId() { - return IdHashes.encode(System.currentTimeMillis() + new Random().nextInt()); - } - public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String desc) { - this.description = desc; - } - - public void setGroup(String group) { - this.group = group; + public String getRefName() { + return refName; } + @Deprecated public String getGroup() { return group; } - public String getRefGroup() { - return refGroup; - } - - public void setRefGroup(String refGroup) { - this.refGroup = refGroup; - } - private String getInterpreterProcessKey(String noteId) { if (getOption().isExistingProcess) { return Constants.EXISTING_PROCESS; @@ -127,7 +114,7 @@ public InterpreterGroup getInterpreterGroup(String noteId) { String key = getInterpreterProcessKey(noteId); synchronized (interpreterGroupRef) { if (!interpreterGroupRef.containsKey(key)) { - String interpreterGroupId = id() + ":" + key; + String interpreterGroupId = getId() + ":" + key; InterpreterGroup intpGroup = interpreterGroupFactory.createInterpreterGroup(interpreterGroupId, getOption()); interpreterGroupRef.put(key, intpGroup); @@ -168,10 +155,6 @@ public Properties getProperties() { return properties; } - public void setProperties(Properties properties) { - this.properties = properties; - } - public List getDependencies() { if (dependencies == null) { return new LinkedList<>(); @@ -204,7 +187,7 @@ public void setPath(String path) { } public List getInterpreterInfos() { - return interpreterGroup; + return interpreterInfos; } public void setInterpreterGroupFactory(InterpreterGroupFactory interpreterGroupFactory) { @@ -226,4 +209,12 @@ public void setInterpreterOption(InterpreterOption interpreterOption) { public void updateProperties(Properties p) { this.properties.putAll(p); } + + public void setRefName(String refName) { + this.refName = refName; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index 70735209465..0157101c3d9 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -268,7 +268,7 @@ public void bindInterpretersToNote(String id, if (note != null) { List currentBindings = replFactory.getInterpreterSettings(id); for (InterpreterSetting setting : currentBindings) { - if (!interpreterSettingIds.contains(setting.id())) { + if (!interpreterSettingIds.contains(setting.getId())) { fireUnbindInterpreter(note, setting); } } @@ -696,7 +696,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { if (releaseResource) { for (InterpreterSetting setting : notebook.getInterpreterFactory().getInterpreterSettings(note.getId())) { - notebook.getInterpreterFactory().restart(setting.id()); + notebook.getInterpreterFactory().restart(setting.getId()); } } } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java index 11f9dcc9d2a..c185badb9a1 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java @@ -20,6 +20,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; +import java.util.Random; /** * Generate Tiny ID. @@ -68,4 +69,8 @@ public static String encode(Long value) { } return sb.toString(); } + + public static String generateId() { + return encode(System.currentTimeMillis() + new Random().nextInt()); + } } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java index 602f38425ed..4f6232493d4 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java @@ -24,7 +24,6 @@ import org.apache.zeppelin.interpreter.mock.MockInterpreter2; import org.apache.zeppelin.notebook.*; import org.apache.zeppelin.notebook.repo.VFSNotebookRepo; -import org.apache.zeppelin.scheduler.ExecutorFactory; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.SchedulerFactory; import org.apache.zeppelin.search.SearchService; @@ -37,8 +36,6 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.atomic.AtomicInteger; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -259,7 +256,7 @@ public void testUnloadOnInterpreterRestart() throws IOException { String mock1IntpSettingId = null; for (InterpreterSetting setting : notebook.getBindedInterpreterSettings(note1.id())) { if (setting.getName().equals("mock1")) { - mock1IntpSettingId = setting.id(); + mock1IntpSettingId = setting.getId(); break; } } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java index 8daee325877..7510d0ada92 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java @@ -79,6 +79,8 @@ public void testBasic() { } } +// mock1Setting = factory.createNewSetting("mock11", "mock1", new ArrayList(), new InterpreterOption(false), new Properties()); + InterpreterGroup interpreterGroup = mock1Setting.getInterpreterGroup("sharedProcess"); factory.createInterpretersForNote(mock1Setting, "sharedProcess", "session"); @@ -89,7 +91,7 @@ public void testBasic() { assertNull(factory.get("unknown")); // restart interpreter - factory.restart(mock1Setting.id()); + factory.restart(mock1Setting.getId()); assertNull(mock1Setting.getInterpreterGroup("sharedProcess").get("session")); } @@ -105,12 +107,12 @@ public void testExceptions() throws InterpreterException, IOException, Repositor List all = factory.getDefaultInterpreterSettingList(); // add setting with null option & properties expected nullArgumentException.class try { - factory.add("a mock", "mock2", new ArrayList(), new LinkedList(), new InterpreterOption(false), new Properties(), ""); + factory.add("mock2", new ArrayList(), new LinkedList(), new InterpreterOption(false), new Properties(), ""); } catch(NullArgumentException e) { assertEquals("Test null option" , e.getMessage(),new NullArgumentException("option").getMessage()); } try { - factory.add("a mock", "mock2", new ArrayList(), new LinkedList(), new InterpreterOption(false), new Properties(), ""); + factory.add("mock2", new ArrayList(), new LinkedList(), new InterpreterOption(false), new Properties(), ""); } catch (NullArgumentException e){ assertEquals("Test null properties" , e.getMessage(),new NullArgumentException("properties").getMessage()); } @@ -125,7 +127,7 @@ public void testSaveLoad() throws IOException, RepositoryException { // check if file saved assertTrue(new File(conf.getInterpreterSettingPath()).exists()); - factory.createNewSetting("newsetting", "new-mock1", "mock1", new LinkedList(), new InterpreterOption(false), new Properties()); + factory.createNewSetting("new-mock1", "mock1", new LinkedList(), new InterpreterOption(false), new Properties()); assertEquals(numInterpreters + 1, factory.get().size()); InterpreterFactory factory2 = new InterpreterFactory(conf, null, null, null, depResolver); @@ -137,19 +139,19 @@ 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); - factory.add("name", "group1", new ArrayList(){{ + factory.add("group1", new ArrayList(){{ add(info1); }}, new ArrayList(), new InterpreterOption(true), new Properties(), "/path1"); - factory.add("name", "group2", new ArrayList(){{ + factory.add("group2", new ArrayList(){{ add(info2); }}, new ArrayList(), new InterpreterOption(true), new Properties(), "/path2"); - final InterpreterSetting setting1 = factory.createNewSetting("test-name1", "test-group1", "group1", new ArrayList(), new InterpreterOption(true), new Properties()); - final InterpreterSetting setting2 = factory.createNewSetting("test-name2", "test-group2", "group1", new ArrayList(), new InterpreterOption(true), new Properties()); + final InterpreterSetting setting1 = factory.createNewSetting("test-group1", "group1", new ArrayList(), new InterpreterOption(true), new Properties()); + final InterpreterSetting setting2 = factory.createNewSetting("test-group2", "group1", new ArrayList(), new InterpreterOption(true), new Properties()); factory.setInterpreters("note", new ArrayList() {{ - add(setting1.id()); - add(setting2.id()); + add(setting1.getId()); + add(setting2.getId()); }}); assertEquals("className1", factory.getInterpreter("note", "test-group1").getClassName()); diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index 67902978abe..bfa97e05de3 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -532,7 +532,7 @@ public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedExc registry.add("o2", "object2", null, null); // restart interpreter - factory.restart(factory.getInterpreterSettings(note.getId()).get(0).id()); + factory.restart(factory.getInterpreterSettings(note.getId()).get(0).getId()); registry = factory.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess") .getAngularObjectRegistry(); @@ -608,7 +608,7 @@ public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedExc while (paragraphs.get(0).getStatus() != Status.FINISHED) Thread.yield(); - factory.restart(factory.getInterpreterSettings(note.getId()).get(0).id()); + factory.restart(factory.getInterpreterSettings(note.getId()).get(0).getId()); boolean isAborted = false; for (Paragraph p : paragraphs) { @@ -634,7 +634,7 @@ public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException { // restart interpreter with per note session enabled for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) { setting.getOption().setPerNoteSession(true); - notebook.getInterpreterFactory().restart(setting.id()); + notebook.getInterpreterFactory().restart(setting.getId()); } note1.run(p1.getId()); @@ -679,7 +679,7 @@ public void testPerSessionInterpreter() throws IOException { // restart interpreter with per note session enabled for (InterpreterSetting setting : notebook.getInterpreterFactory().getInterpreterSettings(note1.getId())) { setting.getOption().setPerNoteSession(true); - notebook.getInterpreterFactory().restart(setting.id()); + notebook.getInterpreterFactory().restart(setting.getId()); } // run per note session enabled @@ -705,7 +705,7 @@ public void testPerSessionInterpreterCloseOnUnbindInterpreterSetting() throws IO // restart interpreter with per note session enabled for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) { setting.getOption().setPerNoteSession(true); - notebook.getInterpreterFactory().restart(setting.id()); + notebook.getInterpreterFactory().restart(setting.getId()); } note1.run(p1.getId()); From 4ff493b32004101f273c7e2e14992c159b4bb9a0 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sun, 10 Jul 2016 22:55:31 +0900 Subject: [PATCH 06/24] Fixed test case --- .../java/org/apache/zeppelin/rest/InterpreterRestApiTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java index 60a07f94f81..8470a54211c 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java @@ -87,7 +87,7 @@ public void getSettings() throws IOException { @Test public void testSettingsCRUD() throws IOException { // Call Create Setting REST API - String jsonRequest = "{\"name\":\"md2\",\"group\":\"md2\",\"refGroup\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + + String jsonRequest = "{\"name\":\"md2\",\"refName\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[]," + "\"option\": { \"remote\": true, \"perNoteSession\": false }}"; From 240c8af5a26cd7530e57c3aae2bd3ec4c343db8a Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sun, 10 Jul 2016 22:57:00 +0900 Subject: [PATCH 07/24] Removed debugging message --- zeppelin-web/src/app/interpreter/interpreter.controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/zeppelin-web/src/app/interpreter/interpreter.controller.js b/zeppelin-web/src/app/interpreter/interpreter.controller.js index dbe26b33a8a..5e621d7620b 100644 --- a/zeppelin-web/src/app/interpreter/interpreter.controller.js +++ b/zeppelin-web/src/app/interpreter/interpreter.controller.js @@ -34,7 +34,6 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', var getAvailableInterpreters = function() { $http.get(baseUrlSrv.getRestApiBase() + '/interpreter').success(function(data, status, headers, config) { $scope.availableInterpreters = data.body; - console.log(data.body); }).error(function(data, status, headers, config) { console.log('Error %o %o', status, data.message); }); From c100f7695198a7cefe3af58146525c7410a1717a Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sun, 10 Jul 2016 23:10:01 +0900 Subject: [PATCH 08/24] Removed deprecated method --- .../interpreter/InterpreterFactory.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index ad8ee465634..db429e044f5 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -235,7 +235,7 @@ public boolean accept(Path entry) throws IOException { for (String settingId : interpreterSettings.keySet()) { InterpreterSetting setting = interpreterSettings.get(settingId); - logger.info("InterpreterSetting group {} : id={}, name={}", setting.getGroup(), settingId, + logger.info("InterpreterSetting group {} : id={}, name={}", setting.getRefName(), settingId, setting.getName()); } } @@ -321,11 +321,6 @@ private void registerInterpreters(List registeredInterpre } - private boolean validateRegisterInterpreter(RegisteredInterpreter registeredInterpreter) { - return null != registeredInterpreter.getGroup() && null != registeredInterpreter.getName() && - null != registeredInterpreter.getClassName(); - } - private void loadFromFile() throws IOException { File settingFile = new File(conf.getInterpreterSettingPath()); if (!settingFile.exists()) { @@ -452,9 +447,9 @@ public List getDefaultInterpreterSettingList() { continue; } - if (!interpreterGroupCheck.containsKey(setting.getGroup())) { + if (!interpreterGroupCheck.containsKey(setting.getName())) { defaultSettings.add(setting.getId()); - interpreterGroupCheck.put(setting.getGroup(), true); + interpreterGroupCheck.put(setting.getName(), true); } } return defaultSettings; @@ -608,7 +603,6 @@ public void removeInterpretersForNote(InterpreterSetting interpreterSetting, Str public void createInterpretersForNote(InterpreterSetting interpreterSetting, String noteId, String key) { InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(noteId); - String groupName = interpreterSetting.getGroup(); InterpreterOption option = interpreterSetting.getOption(); Properties properties = interpreterSetting.getProperties(); if (option.isExistingProcess) { @@ -639,9 +633,7 @@ public void createInterpretersForNote(InterpreterSetting interpreterSetting, Str logger.info("Create interpreter instance {} for note {}", interpreterSetting.getName(), noteId); List interpreterInfos = interpreterSetting.getInterpreterInfos(); - InterpreterSetting refInterpreterSetting = - interpreterSettingsRef.get(interpreterSetting.getRefName()); - String path = refInterpreterSetting.getPath(); + String path = interpreterSetting.getPath(); Interpreter interpreter; for (InterpreterInfo info : interpreterInfos) { if (option.isRemote()) { @@ -707,18 +699,18 @@ public List get() { synchronized (interpreterSettings) { List orderedSettings = new LinkedList<>(); - Map> groupNameInterpreterSettingMap = new HashMap<>(); + Map> nameInterpreterSettingMap = new HashMap<>(); for (InterpreterSetting interpreterSetting : interpreterSettings.values()) { - String groupName = interpreterSetting.getGroup(); - if (!groupNameInterpreterSettingMap.containsKey(groupName)) { - groupNameInterpreterSettingMap.put(groupName, new ArrayList()); + String name = interpreterSetting.getName(); + if (!nameInterpreterSettingMap.containsKey(name)) { + nameInterpreterSettingMap.put(name, new ArrayList()); } - groupNameInterpreterSettingMap.get(groupName).add(interpreterSetting); + nameInterpreterSettingMap.get(name).add(interpreterSetting); } for (String groupName : interpreterGroupOrderList) { List interpreterSettingList = - groupNameInterpreterSettingMap.remove(groupName); + nameInterpreterSettingMap.remove(groupName); if (null != interpreterSettingList) { for (InterpreterSetting interpreterSetting : interpreterSettingList) { orderedSettings.add(interpreterSetting); @@ -729,7 +721,7 @@ public List get() { List settings = new ArrayList<>(); for (List interpreterSettingList : - groupNameInterpreterSettingMap.values()) { + nameInterpreterSettingMap.values()) { for (InterpreterSetting interpreterSetting : interpreterSettingList) { settings.add(interpreterSetting); } From 634cc216964f81388f1c0ed93bc7f722db774671 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sun, 10 Jul 2016 23:21:03 +0900 Subject: [PATCH 09/24] Fixed usage of getGroup --- .../apache/zeppelin/rest/NotebookRestApi.java | 21 +++---------- .../InterpreterSettingListForNoteBind.java | 31 +------------------ .../zeppelin/rest/AbstractTestRestApi.java | 4 +-- .../rest/ZeppelinSparkClusterTest.java | 2 +- zeppelin-web/src/app/notebook/notebook.html | 2 +- .../interpreter/InterpreterFactory.java | 5 ++- .../org/apache/zeppelin/notebook/Note.java | 2 +- .../apache/zeppelin/notebook/Notebook.java | 2 +- .../apache/zeppelin/notebook/NoteTest.java | 6 ++-- 9 files changed, 17 insertions(+), 58 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java index e05621674a3..7033605dc57 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java @@ -183,18 +183,12 @@ public Response bind(@PathParam("noteId") String noteId, String req) throws IOEx @Path("interpreter/bind/{noteId}") @ZeppelinApi public Response bind(@PathParam("noteId") String noteId) { - List settingList - = new LinkedList(); + List settingList = new LinkedList<>(); List selectedSettings = notebook.getBindedInterpreterSettings(noteId); for (InterpreterSetting setting : selectedSettings) { - settingList.add(new InterpreterSettingListForNoteBind( - setting.getId(), - setting.getName(), - setting.getGroup(), - setting.getInterpreterInfos(), - true) - ); + settingList.add(new InterpreterSettingListForNoteBind(setting.getId(), setting.getName(), + setting.getInterpreterInfos(), true)); } List availableSettings = notebook.getInterpreterFactory().get(); @@ -208,13 +202,8 @@ public Response bind(@PathParam("noteId") String noteId) { } if (!selected) { - settingList.add(new InterpreterSettingListForNoteBind( - setting.getId(), - setting.getName(), - setting.getGroup(), - setting.getInterpreterInfos(), - false) - ); + settingList.add(new InterpreterSettingListForNoteBind(setting.getId(), setting.getName(), + setting.getInterpreterInfos(), false)); } } return new JsonResponse<>(Status.OK, "", settingList).build(); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java index 6fd8ccf2ee9..da5636843c8 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java @@ -27,18 +27,14 @@ public class InterpreterSettingListForNoteBind { String id; String name; - String group; private boolean selected; private List interpreters; public InterpreterSettingListForNoteBind(String id, String name, - String group, - List interpreters, - boolean selected) { + List interpreters, boolean selected) { super(); this.id = id; this.name = name; - this.group = group; this.interpreters = interpreters; this.selected = selected; } @@ -58,29 +54,4 @@ public String getName() { public void setName(String name) { this.name = name; } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } - - public List getInterpreterNames() { - return interpreters; - } - - public void setInterpreterNames(List interpreters) { - this.interpreters = interpreters; - } - - public boolean isSelected() { - return selected; - } - - public void setSelected(boolean selected) { - this.selected = selected; - } - } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java index 07c19e2b6a2..78de7738927 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java @@ -119,7 +119,7 @@ protected static void startUp() throws Exception { // assume first one is spark InterpreterSetting sparkIntpSetting = null; for(InterpreterSetting intpSetting : ZeppelinServer.notebook.getInterpreterFactory().get()) { - if (intpSetting.getGroup().equals("spark")) { + if (intpSetting.getName().equals("spark")) { sparkIntpSetting = intpSetting; } } @@ -137,7 +137,7 @@ protected static void startUp() throws Exception { // assume first one is spark InterpreterSetting sparkIntpSetting = null; for(InterpreterSetting intpSetting : ZeppelinServer.notebook.getInterpreterFactory().get()) { - if (intpSetting.getGroup().equals("spark")) { + if (intpSetting.getName().equals("spark")) { sparkIntpSetting = intpSetting; } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java index e7d13faf99d..24a1b906df9 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java @@ -198,7 +198,7 @@ public void pySparkDepLoaderTest() throws IOException { ZeppelinServer.notebook.getBindedInterpreterSettings(note.id()); for (InterpreterSetting setting : settings) { - if (setting.getGroup().equals("spark")) { + if (setting.getName().equals("spark")) { ZeppelinServer.notebook.getInterpreterFactory().restart(setting.getId()); break; } diff --git a/zeppelin-web/src/app/notebook/notebook.html b/zeppelin-web/src/app/notebook/notebook.html index f0e87a7250b..00fcacdffc3 100644 --- a/zeppelin-web/src/app/notebook/notebook.html +++ b/zeppelin-web/src/app/notebook/notebook.html @@ -40,7 +40,7 @@
Interpreter binding
, - %{{item.group}}{{item.name}}.{{intp.name}} (default) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index db429e044f5..33afbf89111 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -204,8 +204,7 @@ public boolean accept(Path entry) throws IOException { for (String settingId : interpreterSettingsRef.keySet()) { InterpreterSetting setting = interpreterSettingsRef.get(settingId); - logger.info("InterpreterSettingRef group {} : id={}, name={}", setting.getGroup(), settingId, - setting.getName()); + logger.info("InterpreterSettingRef name {}", setting.getName()); } loadFromFile(); @@ -490,7 +489,7 @@ private InterpreterSetting add(String refName, } /** - * @param refName user defined name + * @param refName user defined name * @param properties * @return * @throws InterpreterException diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index 285bcedbbe8..7af05ba6e7a 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -117,7 +117,7 @@ private void generateId() { private String getDefaultInterpreterName() { InterpreterSetting setting = factory.getDefaultInterpreterSetting(getId()); - return null != setting ? setting.getGroup() : StringUtils.EMPTY; + return null != setting ? setting.getName() : StringUtils.EMPTY; } void putDefaultReplName() { diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index 0157101c3d9..afc928ff6ac 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -644,7 +644,7 @@ public List> getJobListforNotebook(boolean needsReload, String interpreterGroupName = null; if (replFactory.getInterpreterSettings(note.getId()) != null && replFactory.getInterpreterSettings(note.getId()).size() >= 1) { - interpreterGroupName = replFactory.getInterpreterSettings(note.getId()).get(0).getGroup(); + interpreterGroupName = replFactory.getInterpreterSettings(note.getId()).get(0).getName(); } // not update and not running -> pass diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java index 9a737e69347..cff66adc78d 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java @@ -118,7 +118,7 @@ public void putDefaultReplNameIfInterpreterSettingAbsent() { @Test public void putDefaultReplNameIfInterpreterSettingPresent() { InterpreterSetting interpreterSetting = Mockito.mock(InterpreterSetting.class); - when(interpreterSetting.getGroup()).thenReturn("spark"); + when(interpreterSetting.getName()).thenReturn("spark"); when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(interpreterSetting); @@ -132,7 +132,7 @@ public void putDefaultReplNameIfInterpreterSettingPresent() { @Test public void addParagraphWithLastReplName() { InterpreterSetting interpreterSetting = Mockito.mock(InterpreterSetting.class); - when(interpreterSetting.getGroup()).thenReturn("spark"); + when(interpreterSetting.getName()).thenReturn("spark"); when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(interpreterSetting); @@ -147,7 +147,7 @@ public void addParagraphWithLastReplName() { @Test public void insertParagraphWithLastReplName() { InterpreterSetting interpreterSetting = Mockito.mock(InterpreterSetting.class); - when(interpreterSetting.getGroup()).thenReturn("spark"); + when(interpreterSetting.getName()).thenReturn("spark"); when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(interpreterSetting); From e5857919a5c6ff217b5dc59972e2b1275df2e52a Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sun, 10 Jul 2016 23:41:35 +0900 Subject: [PATCH 10/24] Fixed some style --- .../zeppelin/rest/InterpreterRestApi.java | 42 ++-- .../apache/zeppelin/rest/NotebookRestApi.java | 181 ++++++++++-------- .../InterpreterSettingListForNoteBind.java | 22 +-- .../interpreter/InterpreterFactory.java | 23 ++- .../org/apache/zeppelin/notebook/Note.java | 10 +- 5 files changed, 148 insertions(+), 130 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index 0f7fac64263..07e1d591654 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -17,38 +17,37 @@ package org.apache.zeppelin.rest; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - +import com.google.gson.Gson; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.zeppelin.annotation.ZeppelinApi; import org.apache.zeppelin.dep.Repository; -import org.apache.zeppelin.interpreter.*; +import org.apache.zeppelin.interpreter.InterpreterException; +import org.apache.zeppelin.interpreter.InterpreterFactory; +import org.apache.zeppelin.interpreter.InterpreterSetting; import org.apache.zeppelin.rest.message.NewInterpreterSettingRequest; import org.apache.zeppelin.rest.message.UpdateInterpreterSettingRequest; import org.apache.zeppelin.server.JsonResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; import org.sonatype.aether.RepositoryException; import org.sonatype.aether.repository.RemoteRepository; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Properties; + /** * Interpreter Rest API - * */ @Path("/interpreter") @Produces("application/json") @@ -69,6 +68,7 @@ public InterpreterRestApi(InterpreterFactory interpreterFactory) { /** * List all interpreter settings + * * @return */ @GET @@ -82,6 +82,7 @@ public Response listSettings() { /** * Add new interpreter setting + * * @param message * @return * @throws IOException @@ -184,6 +185,7 @@ public Response listInterpreter(String message) { /** * List of dependency resolving repositories + * * @return */ @GET @@ -197,6 +199,7 @@ public Response listRepositories() { /** * Add new repository + * * @param message * @return */ @@ -222,6 +225,7 @@ public Response addRepository(String message) { /** * Delete repository + * * @param repoId * @return */ diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java index 7033605dc57..742f8fe609c 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java @@ -18,7 +18,12 @@ package org.apache.zeppelin.rest; import java.io.IOException; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -31,6 +36,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import com.google.common.reflect.TypeToken; import org.apache.commons.lang3.StringUtils; import org.apache.zeppelin.annotation.ZeppelinApi; import org.apache.zeppelin.interpreter.InterpreterSetting; @@ -54,7 +60,6 @@ import com.google.common.collect.Sets; import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; /** * Rest api endpoint for the noteBook. @@ -69,7 +74,8 @@ public class NotebookRestApi { private SearchService notebookIndex; private NotebookAuthorization notebookAuthorization; - public NotebookRestApi() {} + public NotebookRestApi() { + } public NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchService search) { this.notebook = notebook; @@ -85,21 +91,19 @@ public NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchS @Path("{noteId}/permissions") @ZeppelinApi public Response getNotePermissions(@PathParam("noteId") String noteId) { - Note note = notebook.getNote(noteId); - HashMap> permissionsMap = new HashMap(); + HashMap> permissionsMap = new HashMap<>(); permissionsMap.put("owners", notebookAuthorization.getOwners(noteId)); permissionsMap.put("readers", notebookAuthorization.getReaders(noteId)); permissionsMap.put("writers", notebookAuthorization.getWriters(noteId)); return new JsonResponse<>(Status.OK, "", permissionsMap).build(); } - String ownerPermissionError(Set current, - Set allowed) throws IOException { + String ownerPermissionError(Set current, Set allowed) throws IOException { LOG.info("Cannot change permissions. Connection owners {}. Allowed owners {}", - current.toString(), allowed.toString()); + current.toString(), allowed.toString()); return "Insufficient privileges to change permissions.\n\n" + - "Allowed owners: " + allowed.toString() + "\n\n" + - "User belongs to: " + current.toString(); + "Allowed owners: " + allowed.toString() + "\n\n" + + "User belongs to: " + current.toString(); } /** @@ -111,24 +115,20 @@ String ownerPermissionError(Set current, public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException { HashMap permMap = gson.fromJson(req, - new TypeToken>(){}.getType()); + new TypeToken>() { + }.getType()); Note note = notebook.getNote(noteId); String principal = SecurityUtils.getPrincipal(); HashSet roles = SecurityUtils.getRoles(); - LOG.info("Set permissions {} {} {} {} {}", - noteId, - principal, - permMap.get("owners"), - permMap.get("readers"), - permMap.get("writers") - ); + LOG.info("Set permissions {} {} {} {} {}", noteId, principal, permMap.get("owners"), + permMap.get("readers"), permMap.get("writers")); - HashSet userAndRoles = new HashSet(); + HashSet userAndRoles = new HashSet<>(); userAndRoles.add(principal); userAndRoles.addAll(roles); if (!notebookAuthorization.isOwner(noteId, userAndRoles)) { return new JsonResponse<>(Status.FORBIDDEN, ownerPermissionError(userAndRoles, - notebookAuthorization.getOwners(noteId))).build(); + notebookAuthorization.getOwners(noteId))).build(); } HashSet readers = permMap.get("readers"); @@ -144,7 +144,7 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re } } // Set writers, if owners is empty -> set to user requesting the change - if ( writers != null && !writers.isEmpty()) { + if (writers != null && !writers.isEmpty()) { if (owners.isEmpty()) { owners = Sets.newHashSet(SecurityUtils.getPrincipal()); } @@ -153,10 +153,8 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re notebookAuthorization.setReaders(noteId, readers); notebookAuthorization.setWriters(noteId, writers); notebookAuthorization.setOwners(noteId, owners); - LOG.debug("After set permissions {} {} {}", - notebookAuthorization.getOwners(noteId), - notebookAuthorization.getReaders(noteId), - notebookAuthorization.getWriters(noteId)); + LOG.debug("After set permissions {} {} {}", notebookAuthorization.getOwners(noteId), + notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId)); AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); note.persist(subject); notebookServer.broadcastNote(note); @@ -165,13 +163,15 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re /** * bind a setting to note + * * @throws IOException */ @PUT @Path("interpreter/bind/{noteId}") @ZeppelinApi public Response bind(@PathParam("noteId") String noteId, String req) throws IOException { - List settingIdList = gson.fromJson(req, new TypeToken>(){}.getType()); + List settingIdList = gson.fromJson(req, new TypeToken>() { + }.getType()); notebook.bindInterpretersToNote(noteId, settingIdList); return new JsonResponse<>(Status.OK).build(); } @@ -215,7 +215,7 @@ public Response bind(@PathParam("noteId") String noteId) { public Response getNotebookList() throws IOException { AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); List> notesInfo = notebookServer.generateNotebooksInfo(false, subject); - return new JsonResponse<>(Status.OK, "", notesInfo ).build(); + return new JsonResponse<>(Status.OK, "", notesInfo).build(); } @GET @@ -232,7 +232,7 @@ public Response getNotebook(@PathParam("notebookId") String notebookId) throws I /** * export note REST API - * + * * @param * @return note JSON with status.OK * @throws IOException @@ -242,12 +242,12 @@ public Response getNotebook(@PathParam("notebookId") String notebookId) throws I @ZeppelinApi public Response exportNoteBook(@PathParam("id") String noteId) throws IOException { String exportJson = notebook.exportNote(noteId); - return new JsonResponse(Status.OK, "", exportJson).build(); + return new JsonResponse<>(Status.OK, "", exportJson).build(); } /** * import new note REST API - * + * * @param req - notebook Json * @return JSON with new note ID * @throws IOException @@ -260,9 +260,10 @@ public Response importNotebook(String req) throws IOException { Note newNote = notebook.importNote(req, null, subject); return new JsonResponse<>(Status.CREATED, "", newNote.getId()).build(); } - + /** * Create new note REST API + * * @param message - JSON with new note name * @return JSON with new note ID * @throws IOException @@ -271,9 +272,8 @@ public Response importNotebook(String req) throws IOException { @Path("/") @ZeppelinApi public Response createNote(String message) throws IOException { - LOG.info("Create new notebook by JSON {}" , message); - NewNotebookRequest request = gson.fromJson(message, - NewNotebookRequest.class); + LOG.info("Create new notebook by JSON {}", message); + NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.class); AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); Note note = notebook.createNote(subject); List initialParagraphs = request.getParagraphs(); @@ -294,11 +294,12 @@ public Response createNote(String message) throws IOException { note.persist(subject); notebookServer.broadcastNote(note); notebookServer.broadcastNoteList(subject); - return new JsonResponse<>(Status.CREATED, "", note.getId() ).build(); + return new JsonResponse<>(Status.CREATED, "", note.getId()).build(); } /** * Delete note REST API + * * @param * @return JSON with status.OK * @throws IOException @@ -319,9 +320,10 @@ public Response deleteNote(@PathParam("notebookId") String notebookId) throws IO notebookServer.broadcastNoteList(subject); return new JsonResponse<>(Status.OK, "").build(); } - + /** * Clone note REST API + * * @param * @return JSON with status.CREATED * @throws IOException, CloneNotSupportedException, IllegalArgumentException @@ -331,9 +333,8 @@ public Response deleteNote(@PathParam("notebookId") String notebookId) throws IO @ZeppelinApi public Response cloneNote(@PathParam("notebookId") String notebookId, String message) throws IOException, CloneNotSupportedException, IllegalArgumentException { - LOG.info("clone notebook by JSON {}" , message); - NewNotebookRequest request = gson.fromJson(message, - NewNotebookRequest.class); + LOG.info("clone notebook by JSON {}", message); + NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.class); String newNoteName = request.getName(); AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); Note newNote = notebook.cloneNote(notebookId, newNoteName, subject); @@ -344,6 +345,7 @@ public Response cloneNote(@PathParam("notebookId") String notebookId, String mes /** * Insert paragraph REST API + * * @param message - JSON containing paragraph's information * @return JSON with status.OK * @throws IOException @@ -357,7 +359,7 @@ public Response insertParagraph(@PathParam("notebookId") String notebookId, Stri Note note = notebook.getNote(notebookId); if (note == null) { - return new JsonResponse(Status.NOT_FOUND, "note not found.").build(); + return new JsonResponse<>(Status.NOT_FOUND, "note not found.").build(); } NewParagraphRequest request = gson.fromJson(message, NewParagraphRequest.class); @@ -375,11 +377,12 @@ public Response insertParagraph(@PathParam("notebookId") String notebookId, Stri AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); note.persist(subject); notebookServer.broadcastNote(note); - return new JsonResponse(Status.CREATED, "", p.getId()).build(); + return new JsonResponse<>(Status.CREATED, "", p.getId()).build(); } /** * Get paragraph REST API + * * @param * @return JSON with information of the paragraph * @throws IOException @@ -388,7 +391,7 @@ public Response insertParagraph(@PathParam("notebookId") String notebookId, Stri @Path("{notebookId}/paragraph/{paragraphId}") @ZeppelinApi public Response getParagraph(@PathParam("notebookId") String notebookId, - @PathParam("paragraphId") String paragraphId) throws IOException { + @PathParam("paragraphId") String paragraphId) throws IOException { LOG.info("get paragraph {} {}", notebookId, paragraphId); Note note = notebook.getNote(notebookId); @@ -401,11 +404,12 @@ public Response getParagraph(@PathParam("notebookId") String notebookId, return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build(); } - return new JsonResponse(Status.OK, "", p).build(); + return new JsonResponse<>(Status.OK, "", p).build(); } /** * Move paragraph REST API + * * @param newIndex - new index to move * @return JSON with status.OK * @throws IOException @@ -414,8 +418,8 @@ public Response getParagraph(@PathParam("notebookId") String notebookId, @Path("{notebookId}/paragraph/{paragraphId}/move/{newIndex}") @ZeppelinApi public Response moveParagraph(@PathParam("notebookId") String notebookId, - @PathParam("paragraphId") String paragraphId, - @PathParam("newIndex") String newIndex) throws IOException { + @PathParam("paragraphId") String paragraphId, @PathParam("newIndex") String newIndex) + throws IOException { LOG.info("move paragraph {} {} {}", notebookId, paragraphId, newIndex); Note note = notebook.getNote(notebookId); @@ -443,6 +447,7 @@ public Response moveParagraph(@PathParam("notebookId") String notebookId, /** * Delete paragraph REST API + * * @param * @return JSON with status.OK * @throws IOException @@ -451,7 +456,7 @@ public Response moveParagraph(@PathParam("notebookId") String notebookId, @Path("{notebookId}/paragraph/{paragraphId}") @ZeppelinApi public Response deleteParagraph(@PathParam("notebookId") String notebookId, - @PathParam("paragraphId") String paragraphId) throws IOException { + @PathParam("paragraphId") String paragraphId) throws IOException { LOG.info("delete paragraph {} {}", notebookId, paragraphId); Note note = notebook.getNote(notebookId); @@ -474,6 +479,7 @@ public Response deleteParagraph(@PathParam("notebookId") String notebookId, /** * Run notebook jobs REST API + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -481,20 +487,21 @@ public Response deleteParagraph(@PathParam("notebookId") String notebookId, @POST @Path("job/{notebookId}") @ZeppelinApi - public Response runNoteJobs(@PathParam("notebookId") String notebookId) throws - IOException, IllegalArgumentException { + public Response runNoteJobs(@PathParam("notebookId") String notebookId) + throws IOException, IllegalArgumentException { LOG.info("run notebook jobs {} ", notebookId); Note note = notebook.getNote(notebookId); if (note == null) { return new JsonResponse<>(Status.NOT_FOUND, "note not found.").build(); } - + note.runAll(); return new JsonResponse<>(Status.OK).build(); } /** * Stop(delete) notebook jobs REST API + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -502,8 +509,8 @@ public Response runNoteJobs(@PathParam("notebookId") String notebookId) throws @DELETE @Path("job/{notebookId}") @ZeppelinApi - public Response stopNoteJobs(@PathParam("notebookId") String notebookId) throws - IOException, IllegalArgumentException { + public Response stopNoteJobs(@PathParam("notebookId") String notebookId) + throws IOException, IllegalArgumentException { LOG.info("stop notebook jobs {} ", notebookId); Note note = notebook.getNote(notebookId); if (note == null) { @@ -517,9 +524,10 @@ public Response stopNoteJobs(@PathParam("notebookId") String notebookId) throws } return new JsonResponse<>(Status.OK).build(); } - + /** * Get notebook job status REST API + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -527,8 +535,8 @@ public Response stopNoteJobs(@PathParam("notebookId") String notebookId) throws @GET @Path("job/{notebookId}") @ZeppelinApi - public Response getNoteJobStatus(@PathParam("notebookId") String notebookId) throws - IOException, IllegalArgumentException { + public Response getNoteJobStatus(@PathParam("notebookId") String notebookId) + throws IOException, IllegalArgumentException { LOG.info("get notebook job status."); Note note = notebook.getNote(notebookId); if (note == null) { @@ -537,23 +545,21 @@ public Response getNoteJobStatus(@PathParam("notebookId") String notebookId) thr return new JsonResponse<>(Status.OK, null, note.generateParagraphsInfo()).build(); } - + /** * Run paragraph job REST API - * + * * @param message - JSON with params if user wants to update dynamic form's value * null, empty string, empty json if user doesn't want to update - * * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @POST @Path("job/{notebookId}/{paragraphId}") @ZeppelinApi - public Response runParagraph(@PathParam("notebookId") String notebookId, - @PathParam("paragraphId") String paragraphId, - String message) throws - IOException, IllegalArgumentException { + public Response runParagraph(@PathParam("notebookId") String notebookId, + @PathParam("paragraphId") String paragraphId, String message) + throws IOException, IllegalArgumentException { LOG.info("run paragraph job {} {} {}", notebookId, paragraphId, message); Note note = notebook.getNote(notebookId); @@ -585,6 +591,7 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, /** * Stop(delete) paragraph job REST API + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -592,9 +599,8 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, @DELETE @Path("job/{notebookId}/{paragraphId}") @ZeppelinApi - public Response stopParagraph(@PathParam("notebookId") String notebookId, - @PathParam("paragraphId") String paragraphId) throws - IOException, IllegalArgumentException { + public Response stopParagraph(@PathParam("notebookId") String notebookId, + @PathParam("paragraphId") String paragraphId) throws IOException, IllegalArgumentException { LOG.info("stop paragraph job {} ", notebookId); Note note = notebook.getNote(notebookId); if (note == null) { @@ -608,9 +614,10 @@ public Response stopParagraph(@PathParam("notebookId") String notebookId, p.abort(); return new JsonResponse<>(Status.OK).build(); } - + /** * Register cron job REST API + * * @param message - JSON with cron expressions. * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -618,18 +625,18 @@ public Response stopParagraph(@PathParam("notebookId") String notebookId, @POST @Path("cron/{notebookId}") @ZeppelinApi - public Response registerCronJob(@PathParam("notebookId") String notebookId, String message) throws - IOException, IllegalArgumentException { + public Response registerCronJob(@PathParam("notebookId") String notebookId, String message) + throws IOException, IllegalArgumentException { LOG.info("Register cron job note={} request cron msg={}", notebookId, message); CronRequest request = gson.fromJson(message, - CronRequest.class); - + CronRequest.class); + Note note = notebook.getNote(notebookId); if (note == null) { return new JsonResponse<>(Status.NOT_FOUND, "note not found.").build(); } - + if (!CronExpression.isValidExpression(request.getCronString())) { return new JsonResponse<>(Status.BAD_REQUEST, "wrong cron expressions.").build(); } @@ -638,12 +645,13 @@ public Response registerCronJob(@PathParam("notebookId") String notebookId, Stri config.put("cron", request.getCronString()); note.setConfig(config); notebook.refreshCron(note.id()); - + return new JsonResponse<>(Status.OK).build(); } - + /** * Remove cron job REST API + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -651,25 +659,26 @@ public Response registerCronJob(@PathParam("notebookId") String notebookId, Stri @DELETE @Path("cron/{notebookId}") @ZeppelinApi - public Response removeCronJob(@PathParam("notebookId") String notebookId) throws - IOException, IllegalArgumentException { + public Response removeCronJob(@PathParam("notebookId") String notebookId) + throws IOException, IllegalArgumentException { LOG.info("Remove cron job note {}", notebookId); Note note = notebook.getNote(notebookId); if (note == null) { return new JsonResponse<>(Status.NOT_FOUND, "note not found.").build(); } - + Map config = note.getConfig(); config.put("cron", null); note.setConfig(config); notebook.refreshCron(note.id()); - + return new JsonResponse<>(Status.OK).build(); - } - + } + /** * Get cron job REST API + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -677,20 +686,21 @@ public Response removeCronJob(@PathParam("notebookId") String notebookId) throws @GET @Path("cron/{notebookId}") @ZeppelinApi - public Response getCronJob(@PathParam("notebookId") String notebookId) throws - IOException, IllegalArgumentException { + public Response getCronJob(@PathParam("notebookId") String notebookId) + throws IOException, IllegalArgumentException { LOG.info("Get cron job note {}", notebookId); Note note = notebook.getNote(notebookId); if (note == null) { return new JsonResponse<>(Status.NOT_FOUND, "note not found.").build(); } - + return new JsonResponse<>(Status.OK, note.getConfig().get("cron")).build(); } /** * Get notebook jobs for job manager + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -713,6 +723,7 @@ public Response getJobListforNotebook() throws IOException, IllegalArgumentExcep /** * Get updated notebook jobs for job manager + * * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException @@ -721,8 +732,8 @@ public Response getJobListforNotebook() throws IOException, IllegalArgumentExcep @Path("jobmanager/{lastUpdateUnixtime}/") @ZeppelinApi public Response getUpdatedJobListforNotebook( - @PathParam("lastUpdateUnixtime") long lastUpdateUnixTime) throws - IOException, IllegalArgumentException { + @PathParam("lastUpdateUnixtime") long lastUpdateUnixTime) + throws IOException, IllegalArgumentException { LOG.info("Get updated notebook jobs lastUpdateTime {}", lastUpdateUnixTime); List> notebookJobs; @@ -754,8 +765,8 @@ public Response search(@QueryParam("q") String queryTerm) { String[] Id = notebooksFound.get(i).get("id").split("/", 2); String noteId = Id[0]; if (!notebookAuthorization.isOwner(noteId, userAndRoles) && - !notebookAuthorization.isReader(noteId, userAndRoles) && - !notebookAuthorization.isWriter(noteId, userAndRoles)) { + !notebookAuthorization.isReader(noteId, userAndRoles) && + !notebookAuthorization.isWriter(noteId, userAndRoles)) { notebooksFound.remove(i); i--; } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java index da5636843c8..9db1c8d2913 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java @@ -25,8 +25,8 @@ * InterpreterSetting information for binding */ public class InterpreterSettingListForNoteBind { - String id; - String name; + private String id; + private String name; private boolean selected; private List interpreters; @@ -38,20 +38,4 @@ public InterpreterSettingListForNoteBind(String id, String name, this.interpreters = interpreters; this.selected = selected; } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +} \ No newline at end of file diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index 33afbf89111..8b82bdcf4d8 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -20,7 +20,6 @@ import com.google.common.base.Preconditions; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import com.google.gson.reflect.TypeToken; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.ArrayUtils; @@ -46,7 +45,15 @@ import org.sonatype.aether.repository.Authentication; import org.sonatype.aether.repository.RemoteRepository; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Type; @@ -57,7 +64,17 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; /** * Manage interpreters. diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index 7af05ba6e7a..9f53d7b5e45 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -19,7 +19,12 @@ import java.io.IOException; import java.io.Serializable; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Random; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -30,7 +35,6 @@ import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.Input; -import org.apache.zeppelin.helium.HeliumApplicationFactory; import org.apache.zeppelin.interpreter.*; import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; @@ -39,10 +43,8 @@ import org.apache.zeppelin.resource.ResourcePoolUtils; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; -import org.apache.zeppelin.scheduler.JobListener; import org.apache.zeppelin.search.SearchService; -import com.google.common.base.Optional; import com.google.gson.Gson; import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; From 9b05ca272fe1ae91dcc1ee39915ab1b4a8a2448b Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Mon, 11 Jul 2016 00:12:00 +0900 Subject: [PATCH 11/24] Fixed some style --- .../rest/message/InterpreterSettingListForNoteBind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java index 9db1c8d2913..a805e677cfe 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java @@ -38,4 +38,4 @@ public InterpreterSettingListForNoteBind(String id, String name, this.interpreters = interpreters; this.selected = selected; } -} \ No newline at end of file +} From d59029b2373c23277abc841530a7603848294fb5 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Mon, 11 Jul 2016 10:47:43 +0900 Subject: [PATCH 12/24] Removed unused code Fixed the type of variables Adjusted diamond operator --- .../org/apache/zeppelin/notebook/Note.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index 9f53d7b5e45..f67ffa51593 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -24,7 +24,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -55,7 +54,7 @@ * Binded interpreters for a note */ public class Note implements Serializable, ParagraphJobListener { - static Logger logger = LoggerFactory.getLogger(Note.class); + private static final Logger logger = LoggerFactory.getLogger(Note.class); private static final long serialVersionUID = 7920699076577612429L; // threadpool for delayed persist of note @@ -73,8 +72,7 @@ public class Note implements Serializable, ParagraphJobListener { private AtomicReference lastReplName = new AtomicReference<>(StringUtils.EMPTY); private transient ZeppelinConfiguration conf = ZeppelinConfiguration.create(); - @SuppressWarnings("rawtypes") - Map> angularObjects = new HashMap<>(); + private Map> angularObjects = new HashMap<>(); private transient InterpreterFactory factory; private transient JobListenerFactory jobListenerFactory; @@ -114,7 +112,7 @@ public Note(NotebookRepo repo, InterpreterFactory factory, } private void generateId() { - id = IdHashes.encode(System.currentTimeMillis() + new Random().nextInt()); + id = IdHashes.generateId(); } private String getDefaultInterpreterName() { @@ -198,7 +196,6 @@ public void setCredentials(Credentials credentials) { } - @SuppressWarnings("rawtypes") public Map> getAngularObjects() { return angularObjects; } @@ -507,14 +504,14 @@ public boolean isTerminated() { public List completion(String paragraphId, String buffer, int cursor) { Paragraph p = getParagraph(paragraphId); p.setListener(jobListenerFactory.getParagraphJobListener(this)); - List completion = p.completion(buffer, cursor); + List completion = p.completion(buffer, cursor); return completion; } public List getParagraphs() { synchronized (paragraphs) { - return new LinkedList(paragraphs); + return new LinkedList<>(paragraphs); } } @@ -534,7 +531,7 @@ private void snapshotAngularObjectRegistry() { } private void removeAllAngularObjectInParagraph(String paragraphId) { - angularObjects = new HashMap>(); + angularObjects = new HashMap<>(); List settings = factory.getInterpreterSettings(getId()); if (settings == null || settings.size() == 0) { @@ -716,12 +713,6 @@ public void onOutputUpdate(Paragraph paragraph, InterpreterOutput out, String ou } } - - - public NoteEventListener getNoteEventListener() { - return noteEventListener; - } - public void setNoteEventListener(NoteEventListener noteEventListener) { this.noteEventListener = noteEventListener; } From cb7dde5d3289c02e0c598ddbdeb0f7a84d052b19 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 13 Jul 2016 10:26:20 +0900 Subject: [PATCH 13/24] Fixed wrong test to save to file after Zeppelin calls createNewSetting --- .../interpreter/InterpreterFactory.java | 214 ++++++++---------- .../interpreter/InterpreterFactoryTest.java | 2 +- 2 files changed, 98 insertions(+), 118 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index 8b82bdcf4d8..4f1b488f8b5 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -17,34 +17,6 @@ package org.apache.zeppelin.interpreter; -import com.google.common.base.Preconditions; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.NullArgumentException; -import org.apache.zeppelin.conf.ZeppelinConfiguration; -import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; -import org.apache.zeppelin.dep.Dependency; -import org.apache.zeppelin.dep.DependencyResolver; -import org.apache.zeppelin.display.AngularObjectRegistry; -import org.apache.zeppelin.display.AngularObjectRegistryListener; -import org.apache.zeppelin.helium.ApplicationEventListener; -import org.apache.zeppelin.interpreter.Interpreter.RegisteredInterpreter; -import org.apache.zeppelin.interpreter.dev.DevInterpreter; -import org.apache.zeppelin.interpreter.dev.ZeppelinDevServer; -import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; -import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; -import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener; -import org.apache.zeppelin.scheduler.Job; -import org.apache.zeppelin.scheduler.Job.Status; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonatype.aether.RepositoryException; -import org.sonatype.aether.repository.Authentication; -import org.sonatype.aether.repository.RemoteRepository; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -76,6 +48,35 @@ import java.util.Properties; import java.util.Set; +import com.google.common.base.Preconditions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.NullArgumentException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonatype.aether.RepositoryException; +import org.sonatype.aether.repository.Authentication; +import org.sonatype.aether.repository.RemoteRepository; + +import org.apache.zeppelin.conf.ZeppelinConfiguration; +import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; +import org.apache.zeppelin.dep.Dependency; +import org.apache.zeppelin.dep.DependencyResolver; +import org.apache.zeppelin.display.AngularObjectRegistry; +import org.apache.zeppelin.display.AngularObjectRegistryListener; +import org.apache.zeppelin.helium.ApplicationEventListener; +import org.apache.zeppelin.interpreter.Interpreter.RegisteredInterpreter; +import org.apache.zeppelin.interpreter.dev.DevInterpreter; +import org.apache.zeppelin.interpreter.dev.ZeppelinDevServer; +import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; +import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; +import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener; +import org.apache.zeppelin.scheduler.Job; +import org.apache.zeppelin.scheduler.Job.Status; + /** * Manage interpreters. */ @@ -88,8 +89,7 @@ public class InterpreterFactory implements InterpreterGroupFactory { Collections.synchronizedMap(new HashMap()); private ZeppelinConfiguration conf; - @Deprecated - private String[] interpreterClassList; + @Deprecated private String[] interpreterClassList; private String[] interpreterGroupOrderList; /** @@ -124,8 +124,7 @@ public class InterpreterFactory implements InterpreterGroupFactory { public InterpreterFactory(ZeppelinConfiguration conf, AngularObjectRegistryListener angularObjectRegistryListener, RemoteInterpreterProcessListener remoteInterpreterProcessListener, - ApplicationEventListener appEventListener, - DependencyResolver depResolver) + ApplicationEventListener appEventListener, DependencyResolver depResolver) throws InterpreterException, IOException, RepositoryException { this(conf, new InterpreterOption(true), angularObjectRegistryListener, remoteInterpreterProcessListener, appEventListener, depResolver); @@ -135,8 +134,7 @@ public InterpreterFactory(ZeppelinConfiguration conf, public InterpreterFactory(ZeppelinConfiguration conf, InterpreterOption defaultOption, AngularObjectRegistryListener angularObjectRegistryListener, RemoteInterpreterProcessListener remoteInterpreterProcessListener, - ApplicationEventListener appEventListener, - DependencyResolver depResolver) + ApplicationEventListener appEventListener, DependencyResolver depResolver) throws InterpreterException, IOException, RepositoryException { this.conf = conf; this.defaultOption = defaultOption; @@ -163,10 +161,9 @@ private void init() throws InterpreterException, IOException, RepositoryExceptio Path interpretersDir = Paths.get(conf.getInterpreterDir()); if (Files.exists(interpretersDir)) { - for (Path interpreterDir : Files.newDirectoryStream(interpretersDir, - new DirectoryStream.Filter() { - @Override - public boolean accept(Path entry) throws IOException { + for (Path interpreterDir : Files + .newDirectoryStream(interpretersDir, new DirectoryStream.Filter() { + @Override public boolean accept(Path entry) throws IOException { return Files.exists(entry) && Files.isDirectory(entry); } })) { @@ -188,10 +185,10 @@ public boolean accept(Path entry) throws IOException { Class.forName(className, true, ccl); Set interpreterKeys = Interpreter.registeredInterpreters.keySet(); for (String interpreterKey : interpreterKeys) { - if (className.equals( - Interpreter.registeredInterpreters.get(interpreterKey).getClassName())) { - Interpreter.registeredInterpreters.get(interpreterKey).setPath( - interpreterDirString); + if (className + .equals(Interpreter.registeredInterpreters.get(interpreterKey).getClassName())) { + Interpreter.registeredInterpreters.get(interpreterKey) + .setPath(interpreterDirString); logger.info("Interpreter " + interpreterKey + " found. class=" + className); cleanCl.put(interpreterDirString, ccl); } @@ -203,11 +200,11 @@ public boolean accept(Path entry) throws IOException { } } - for (RegisteredInterpreter registeredInterpreter : - Interpreter.registeredInterpreters.values()) { - logger.debug("Registered: {} -> {}. Properties: {}", - registeredInterpreter.getInterpreterKey(), registeredInterpreter.getClassName(), - registeredInterpreter.getProperties()); + for (RegisteredInterpreter registeredInterpreter : Interpreter.registeredInterpreters + .values()) { + logger + .debug("Registered: {} -> {}. Properties: {}", registeredInterpreter.getInterpreterKey(), + registeredInterpreter.getClassName(), registeredInterpreter.getProperties()); } // RegisteredInterpreters -> interpreterSettingRef @@ -263,9 +260,9 @@ private InterpreterSetting createFromInterpreterSettingRef(String name) { } private InterpreterSetting createFromInterpreterSettingRef(InterpreterSetting o) { - InterpreterSetting setting = new InterpreterSetting(o.getName(), o.getName(), - o.getInterpreterInfos(), o.getProperties(), o.getDependencies(), o.getOption(), - o.getPath()); + InterpreterSetting setting = + new InterpreterSetting(o.getName(), o.getName(), o.getInterpreterInfos(), o.getProperties(), + o.getDependencies(), o.getOption(), o.getPath()); setting.setInterpreterGroupFactory(this); return setting; } @@ -279,8 +276,7 @@ private Properties convertInterpreterProperties(Map } private void registerInterpreterFromResource(ClassLoader cl, String interpreterDir, - String interpreterJson) - throws IOException, RepositoryException { + String interpreterJson) throws IOException, RepositoryException { URL[] urls = recursiveBuildLibList(new File(interpreterDir)); ClassLoader tempClassLoader = new URLClassLoader(urls, cl); @@ -288,20 +284,20 @@ private void registerInterpreterFromResource(ClassLoader cl, String interpreterD if (null != inputStream) { logger.debug("Reading {} from resources in {}", interpreterJson, interpreterDir); - List registeredInterpreterList = getInterpreterListFromJson( - inputStream); + List registeredInterpreterList = + getInterpreterListFromJson(inputStream); registerInterpreters(registeredInterpreterList, interpreterDir); } } - private void registerInterpreterFromPath(String interpreterDir, - String interpreterJson) throws IOException, RepositoryException { + private void registerInterpreterFromPath(String interpreterDir, String interpreterJson) + throws IOException, RepositoryException { Path interpreterJsonPath = Paths.get(interpreterDir, interpreterJson); if (Files.exists(interpreterJsonPath)) { logger.debug("Reading {}", interpreterJsonPath); - List registeredInterpreterList = getInterpreterListFromJson( - interpreterJsonPath); + List registeredInterpreterList = + getInterpreterListFromJson(interpreterJsonPath); registerInterpreters(registeredInterpreterList, interpreterDir); } } @@ -321,8 +317,9 @@ private void registerInterpreters(List registeredInterpre String absolutePath) throws IOException, RepositoryException { for (RegisteredInterpreter registeredInterpreter : registeredInterpreters) { - InterpreterInfo interpreterInfo = new InterpreterInfo(registeredInterpreter.getClassName(), - registeredInterpreter.getName(), registeredInterpreter.isDefaultInterpreter()); + InterpreterInfo interpreterInfo = + new InterpreterInfo(registeredInterpreter.getClassName(), registeredInterpreter.getName(), + registeredInterpreter.isDefaultInterpreter()); Properties properties = new Properties(); Map p = registeredInterpreter.getProperties(); @@ -485,7 +482,7 @@ public boolean findDefaultInterpreter(List infos) { } public InterpreterSetting createNewSetting(String name, String refName, - List dependencies, InterpreterOption option, Properties p) { + List dependencies, InterpreterOption option, Properties p) throws IOException { InterpreterSetting setting = createFromInterpreterSettingRef(refName); setting.setName(name); setting.setRefName(refName); @@ -494,11 +491,12 @@ public InterpreterSetting createNewSetting(String name, String refName, setting.updateProperties(p); setting.setInterpreterGroupFactory(this); interpreterSettings.put(setting.getId(), setting); + saveToFile(); return setting; } - private InterpreterSetting add(String refName, - InterpreterInfo interpreterInfo, Properties properties, String path) + private InterpreterSetting add(String refName, InterpreterInfo interpreterInfo, + Properties properties, String path) throws InterpreterException, IOException, RepositoryException { ArrayList infos = new ArrayList<>(); infos.add(interpreterInfo); @@ -520,7 +518,7 @@ public InterpreterSetting add(String refName, ArrayList interpr Preconditions.checkNotNull(dependencies, "dependencies should not be null"); Preconditions.checkNotNull(option, "option should not be null"); Preconditions.checkNotNull(properties, "properties should not be null"); -// Preconditions.checkNotNull(path, "path should not be null"); + // Preconditions.checkNotNull(path, "path should not be null"); InterpreterSetting interpreterSetting; @@ -559,8 +557,9 @@ public InterpreterSetting add(String refName, ArrayList interpr } } else { - interpreterSetting = new InterpreterSetting(refName, null, interpreterInfos, properties, - dependencies, option, path); + interpreterSetting = + new InterpreterSetting(refName, null, interpreterInfos, properties, dependencies, + option, path); interpreterSettingsRef.put(refName, interpreterSetting); } } @@ -574,8 +573,7 @@ public InterpreterSetting add(String refName, ArrayList interpr return interpreterSetting; } - @Override - public InterpreterGroup createInterpreterGroup(String id, InterpreterOption option) + @Override public InterpreterGroup createInterpreterGroup(String id, InterpreterOption option) throws InterpreterException, NullArgumentException { //When called from REST API without option we receive NPE @@ -586,8 +584,8 @@ public InterpreterGroup createInterpreterGroup(String id, InterpreterOption opti InterpreterGroup interpreterGroup = new InterpreterGroup(id); if (option.isRemote()) { - angularObjectRegistry = new RemoteAngularObjectRegistry(id, angularObjectRegistryListener, - interpreterGroup); + angularObjectRegistry = + new RemoteAngularObjectRegistry(id, angularObjectRegistryListener, interpreterGroup); } else { angularObjectRegistry = new AngularObjectRegistry(id, angularObjectRegistryListener); @@ -610,8 +608,7 @@ public void removeInterpretersForNote(InterpreterSetting interpreterSetting, Str interpreterGroup.remove(noteId); interpreterGroup.notifyAll(); // notify createInterpreterForNote() } - logger.info("Interpreter instance {} for note {} is removed", - interpreterSetting.getName(), + logger.info("Interpreter instance {} for note {} is removed", interpreterSetting.getName(), noteId); } } @@ -654,11 +651,12 @@ public void createInterpretersForNote(InterpreterSetting interpreterSetting, Str for (InterpreterInfo info : interpreterInfos) { if (option.isRemote()) { if (option.isConnectExistingProcess()) { - interpreter = connectToRemoteRepl(noteId, info.getClassName(), option.getHost(), - option.getPort(), properties); + interpreter = + connectToRemoteRepl(noteId, info.getClassName(), option.getHost(), option.getPort(), + properties); } else { - interpreter = createRemoteRepl(path, key, info.getClassName(), - properties, interpreterSetting.getId()); + interpreter = createRemoteRepl(path, key, info.getClassName(), properties, + interpreterSetting.getId()); } } else { interpreter = createRepl(interpreterSetting.getPath(), info.getClassName(), properties); @@ -736,16 +734,14 @@ public List get() { List settings = new ArrayList<>(); - for (List interpreterSettingList : - nameInterpreterSettingMap.values()) { + for (List interpreterSettingList : nameInterpreterSettingMap.values()) { for (InterpreterSetting interpreterSetting : interpreterSettingList) { settings.add(interpreterSetting); } } Collections.sort(settings, new Comparator() { - @Override - public int compare(InterpreterSetting o1, InterpreterSetting o2) { + @Override public int compare(InterpreterSetting o1, InterpreterSetting o2) { return o1.getName().compareTo(o2.getName()); } }); @@ -788,7 +784,8 @@ private void putNoteInterpreterSettingBinding(String noteId, List settin public void removeNoteInterpreterSettingBinding(String noteId) { synchronized (interpreterSettings) { List settingIds = (interpreterBindings.containsKey(noteId) ? - interpreterBindings.remove(noteId) : Collections.emptyList()); + interpreterBindings.remove(noteId) : + Collections.emptyList()); for (String settingId : settingIds) { this.removeInterpretersForNote(get(settingId), noteId); } @@ -831,8 +828,7 @@ public void setPropertyAndRestart(String id, InterpreterOption option, Propertie loadInterpreterDependencies(intpsetting); saveToFile(); } else { - throw new InterpreterException("Interpreter setting id " + id - + " not found"); + throw new InterpreterException("Interpreter setting id " + id + " not found"); } } } @@ -847,8 +843,7 @@ public void restart(String id) { intpsetting.closeAndRmoveAllInterpreterGroups(); } else { - throw new InterpreterException("Interpreter setting id " + id - + " not found"); + throw new InterpreterException("Interpreter setting id " + id + " not found"); } } } @@ -898,8 +893,7 @@ public void run() { } } - private Interpreter createRepl(String dirName, String className, - Properties property) + private Interpreter createRepl(String dirName, String className, Properties property) throws InterpreterException { logger.info("Create repl {} from {}", className, dirName); @@ -911,7 +905,7 @@ private Interpreter createRepl(String dirName, String className, URLClassLoader ccl = cleanCl.get(dirName); if (ccl == null) { // classloader fallback - ccl = URLClassLoader.newInstance(new URL[]{}, oldcl); + ccl = URLClassLoader.newInstance(new URL[] {}, oldcl); } boolean separateCL = true; @@ -927,7 +921,7 @@ private Interpreter createRepl(String dirName, String className, URLClassLoader cl; if (separateCL == true) { - cl = URLClassLoader.newInstance(new URL[]{}, ccl); + cl = URLClassLoader.newInstance(new URL[] {}, ccl); } else { cl = ccl; } @@ -935,11 +929,10 @@ private Interpreter createRepl(String dirName, String className, Class replClass = (Class) cl.loadClass(className); Constructor constructor = - replClass.getConstructor(new Class[]{Properties.class}); + replClass.getConstructor(new Class[] {Properties.class}); Interpreter repl = constructor.newInstance(property); repl.setClassloaderUrls(ccl.getURLs()); - LazyOpenInterpreter intp = new LazyOpenInterpreter( - new ClassloaderInterpreter(repl, cl)); + LazyOpenInterpreter intp = new LazyOpenInterpreter(new ClassloaderInterpreter(repl, cl)); return intp; } catch (SecurityException e) { throw new InterpreterException(e); @@ -960,24 +953,13 @@ private Interpreter createRepl(String dirName, String className, } } - private Interpreter connectToRemoteRepl(String noteId, - String className, - String host, - int port, + private Interpreter connectToRemoteRepl(String noteId, String className, String host, int port, Properties property) { int connectTimeout = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT); int maxPoolSize = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_MAX_POOL_SIZE); LazyOpenInterpreter intp = new LazyOpenInterpreter( - new RemoteInterpreter( - property, - noteId, - className, - host, - port, - connectTimeout, - maxPoolSize, - remoteInterpreterProcessListener, - appEventListener)); + new RemoteInterpreter(property, noteId, className, host, port, connectTimeout, maxPoolSize, + remoteInterpreterProcessListener, appEventListener)); return intp; } @@ -990,10 +972,10 @@ private Interpreter createRemoteRepl(String interpreterPath, String noteId, Stri updatePropertiesFromRegisteredInterpreter(property, className); - RemoteInterpreter remoteInterpreter = new RemoteInterpreter( - property, noteId, className, conf.getInterpreterRemoteRunnerPath(), - interpreterPath, localRepoPath, connectTimeout, - maxPoolSize, remoteInterpreterProcessListener, appEventListener); + RemoteInterpreter remoteInterpreter = + new RemoteInterpreter(property, noteId, className, conf.getInterpreterRemoteRunnerPath(), + interpreterPath, localRepoPath, connectTimeout, maxPoolSize, + remoteInterpreterProcessListener, appEventListener); remoteInterpreter.setEnv(env); return new LazyOpenInterpreter(remoteInterpreter); @@ -1001,8 +983,8 @@ private Interpreter createRemoteRepl(String interpreterPath, String noteId, Stri private Properties updatePropertiesFromRegisteredInterpreter(Properties properties, String className) { - RegisteredInterpreter registeredInterpreter = Interpreter.findRegisteredInterpreterByClassName( - className); + RegisteredInterpreter registeredInterpreter = + Interpreter.findRegisteredInterpreterByClassName(className); if (null != registeredInterpreter) { Map defaultProperties = registeredInterpreter.getProperties(); for (String key : defaultProperties.keySet()) { @@ -1221,7 +1203,7 @@ private URL[] recursiveBuildLibList(File path) throws MalformedURLException { } return urls; } else { - return new URL[]{path.toURI().toURL()}; + return new URL[] {path.toURI().toURL()}; } } @@ -1256,10 +1238,8 @@ public Interpreter getDevInterpreter() { InterpreterGroup interpreterGroup = createInterpreterGroup("dev", option); - devInterpreter = connectToRemoteRepl("dev", DevInterpreter.class.getName(), - "localhost", - ZeppelinDevServer.DEFAULT_TEST_INTERPRETER_PORT, - new Properties()); + devInterpreter = connectToRemoteRepl("dev", DevInterpreter.class.getName(), "localhost", + ZeppelinDevServer.DEFAULT_TEST_INTERPRETER_PORT, new Properties()); LinkedList intpList = new LinkedList<>(); intpList.add(devInterpreter); diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java index 7510d0ada92..e28416491ee 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java @@ -131,7 +131,7 @@ public void testSaveLoad() throws IOException, RepositoryException { assertEquals(numInterpreters + 1, factory.get().size()); InterpreterFactory factory2 = new InterpreterFactory(conf, null, null, null, depResolver); - assertEquals(numInterpreters, factory2.get().size()); + assertEquals(numInterpreters + 1, factory2.get().size()); } @Test From dde2232fb70d8c1a9221b06db3108dedb21d86c7 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 13 Jul 2016 10:29:55 +0900 Subject: [PATCH 14/24] Added catching IOE from caller of createNewSetting --- .../main/java/org/apache/zeppelin/rest/InterpreterRestApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index 07e1d591654..925c45f9598 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -101,7 +101,7 @@ public Response newSettings(String message) { request.getRefName(), request.getDependencies(), request.getOption(), p); logger.info("new setting created with {}", interpreterSetting.getId()); return new JsonResponse(Status.CREATED, "", interpreterSetting).build(); - } catch (InterpreterException e) { + } catch (InterpreterException | IOException e) { logger.error("Exception in InterpreterRestApi while creating ", e); return new JsonResponse( Status.NOT_FOUND, From ca208894dcdbb16996af60085d2950136ae4ddeb Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 13 Jul 2016 11:11:47 +0900 Subject: [PATCH 15/24] Changed setting.group to setting.name Removed meaningless super constructor --- .../rest/message/InterpreterSettingListForNoteBind.java | 1 - zeppelin-web/src/app/notebook/notebook.controller.js | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java index a805e677cfe..6ec5a54a3ac 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/InterpreterSettingListForNoteBind.java @@ -32,7 +32,6 @@ public class InterpreterSettingListForNoteBind { public InterpreterSettingListForNoteBind(String id, String name, List interpreters, boolean selected) { - super(); this.id = id; this.name = name; this.interpreters = interpreters; diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js index 97b35f0be00..d26b076c052 100644 --- a/zeppelin-web/src/app/notebook/notebook.controller.js +++ b/zeppelin-web/src/app/notebook/notebook.controller.js @@ -553,7 +553,9 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro var getInterpreterBindings = function(callback) { $http.get(baseUrlSrv.getRestApiBase() + '/notebook/interpreter/bind/' + $scope.note.id). success(function(data, status, headers, config) { + console.log("success", angular.copy(data.body)); $scope.interpreterBindings = data.body; + console.log("bindings", $scope.interpreterBindings); $scope.interpreterBindingsOrig = angular.copy($scope.interpreterBindings); // to check dirty if (callback) { callback(); @@ -571,6 +573,8 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro var key; var setting; + console.log("callback", $scope.interpreterBindings); + for (key in $scope.interpreterBindings) { setting = $scope.interpreterBindings[key]; if (setting.selected) { @@ -584,9 +588,9 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro var selectedIntp = {}; for (key in $scope.interpreterBindings) { setting = $scope.interpreterBindings[key]; - if (!selectedIntp[setting.group]) { + if (!selectedIntp[setting.name]) { setting.selected = true; - selectedIntp[setting.group] = true; + selectedIntp[setting.name] = true; } } $scope.showSetting = true; From 334634a0564a9d40f4dd12a5b0444cbe2520a022 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 13 Jul 2016 11:18:17 +0900 Subject: [PATCH 16/24] Fixed the description of parameter of add method --- .../apache/zeppelin/interpreter/InterpreterFactory.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index 4f1b488f8b5..8918241bc9f 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -93,8 +93,8 @@ public class InterpreterFactory implements InterpreterGroupFactory { private String[] interpreterGroupOrderList; /** - * This is only references with default group, name and properties - * key: InterpreterSetting.group + * This is only references with default settings, name and properties + * key: InterpreterSetting.name */ private Map interpreterSettingsRef = new HashMap<>(); @@ -504,7 +504,7 @@ private InterpreterSetting add(String refName, InterpreterInfo interpreterInfo, } /** - * @param refName user defined name + * @param refName InterpreterSetting reference name * @param properties * @return * @throws InterpreterException @@ -518,7 +518,6 @@ public InterpreterSetting add(String refName, ArrayList interpr Preconditions.checkNotNull(dependencies, "dependencies should not be null"); Preconditions.checkNotNull(option, "option should not be null"); Preconditions.checkNotNull(properties, "properties should not be null"); - // Preconditions.checkNotNull(path, "path should not be null"); InterpreterSetting interpreterSetting; From 5bb15a087b187c101bf8d7ded9a7916656f142ac Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 13 Jul 2016 12:15:23 +0900 Subject: [PATCH 17/24] Removed some console.log added for debugging --- zeppelin-web/src/app/notebook/notebook.controller.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js index d26b076c052..9513e7df60f 100644 --- a/zeppelin-web/src/app/notebook/notebook.controller.js +++ b/zeppelin-web/src/app/notebook/notebook.controller.js @@ -553,9 +553,7 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro var getInterpreterBindings = function(callback) { $http.get(baseUrlSrv.getRestApiBase() + '/notebook/interpreter/bind/' + $scope.note.id). success(function(data, status, headers, config) { - console.log("success", angular.copy(data.body)); $scope.interpreterBindings = data.body; - console.log("bindings", $scope.interpreterBindings); $scope.interpreterBindingsOrig = angular.copy($scope.interpreterBindings); // to check dirty if (callback) { callback(); @@ -573,8 +571,6 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro var key; var setting; - console.log("callback", $scope.interpreterBindings); - for (key in $scope.interpreterBindings) { setting = $scope.interpreterBindings[key]; if (setting.selected) { From fac0b864048898a7062a3b96dcb9197aa106a627 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 13 Jul 2016 13:55:39 +0900 Subject: [PATCH 18/24] Reformatted files related to this PR without test classes --- .../zeppelin/rest/InterpreterRestApi.java | 130 ++++++-------- .../apache/zeppelin/rest/NotebookRestApi.java | 75 ++++---- .../interpreter/InterpreterFactory.java | 6 +- .../zeppelin/interpreter/InterpreterInfo.java | 25 +-- .../interpreter/InterpreterSetting.java | 37 ++-- .../org/apache/zeppelin/notebook/Note.java | 101 +++++------ .../apache/zeppelin/notebook/Notebook.java | 170 ++++++++---------- .../zeppelin/notebook/utility/IdHashes.java | 8 +- 8 files changed, 249 insertions(+), 303 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index 925c45f9598..6e837aba05d 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -17,8 +17,27 @@ package org.apache.zeppelin.rest; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + import com.google.gson.Gson; import org.apache.commons.lang.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonatype.aether.RepositoryException; +import org.sonatype.aether.repository.RemoteRepository; + import org.apache.zeppelin.annotation.ZeppelinApi; import org.apache.zeppelin.dep.Repository; import org.apache.zeppelin.interpreter.InterpreterException; @@ -27,24 +46,6 @@ import org.apache.zeppelin.rest.message.NewInterpreterSettingRequest; import org.apache.zeppelin.rest.message.UpdateInterpreterSettingRequest; import org.apache.zeppelin.server.JsonResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonatype.aether.RepositoryException; -import org.sonatype.aether.repository.RemoteRepository; - -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Properties; /** * Interpreter Rest API @@ -52,61 +53,51 @@ @Path("/interpreter") @Produces("application/json") public class InterpreterRestApi { - Logger logger = LoggerFactory.getLogger(InterpreterRestApi.class); + private static final Logger logger = LoggerFactory.getLogger(InterpreterRestApi.class); private InterpreterFactory interpreterFactory; Gson gson = new Gson(); - public InterpreterRestApi() { - - } - public InterpreterRestApi(InterpreterFactory interpreterFactory) { this.interpreterFactory = interpreterFactory; } /** * List all interpreter settings - * - * @return */ @GET @Path("setting") @ZeppelinApi public Response listSettings() { - List interpreterSettings = null; + List interpreterSettings; interpreterSettings = interpreterFactory.get(); - return new JsonResponse(Status.OK, "", interpreterSettings).build(); + return new JsonResponse<>(Status.OK, "", interpreterSettings).build(); } /** * Add new interpreter setting * - * @param message - * @return - * @throws IOException - * @throws InterpreterException + * @param message NewInterpreterSettingRequest */ @POST @Path("setting") @ZeppelinApi public Response newSettings(String message) { try { - NewInterpreterSettingRequest request = gson.fromJson(message, - NewInterpreterSettingRequest.class); + NewInterpreterSettingRequest request = + gson.fromJson(message, NewInterpreterSettingRequest.class); Properties p = new Properties(); p.putAll(request.getProperties()); - InterpreterSetting interpreterSetting = interpreterFactory.createNewSetting(request.getName(), - request.getRefName(), request.getDependencies(), request.getOption(), p); + InterpreterSetting interpreterSetting = interpreterFactory + .createNewSetting(request.getName(), request.getRefName(), request.getDependencies(), + request.getOption(), p); logger.info("new setting created with {}", interpreterSetting.getId()); - return new JsonResponse(Status.CREATED, "", interpreterSetting).build(); + return new JsonResponse<>(Status.CREATED, "", interpreterSetting).build(); } catch (InterpreterException | IOException e) { logger.error("Exception in InterpreterRestApi while creating ", e); - return new JsonResponse( - Status.NOT_FOUND, - e.getMessage(), - ExceptionUtils.getStackTrace(e)).build(); + return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)) + .build(); } } @@ -117,26 +108,25 @@ public Response updateSetting(String message, @PathParam("settingId") String set logger.info("Update interpreterSetting {}", settingId); try { - UpdateInterpreterSettingRequest request = gson.fromJson(message, - UpdateInterpreterSettingRequest.class); - interpreterFactory.setPropertyAndRestart(settingId, - request.getOption(), - request.getProperties(), - request.getDependencies()); + UpdateInterpreterSettingRequest request = + gson.fromJson(message, UpdateInterpreterSettingRequest.class); + interpreterFactory + .setPropertyAndRestart(settingId, request.getOption(), request.getProperties(), + request.getDependencies()); } catch (InterpreterException e) { logger.error("Exception in InterpreterRestApi while updateSetting ", e); - return new JsonResponse( - Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); + return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)) + .build(); } catch (IOException | RepositoryException e) { logger.error("Exception in InterpreterRestApi while updateSetting ", e); - return new JsonResponse( - Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); + return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), + ExceptionUtils.getStackTrace(e)).build(); } InterpreterSetting setting = interpreterFactory.get(settingId); if (setting == null) { - return new JsonResponse(Status.NOT_FOUND, "", settingId).build(); + return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build(); } - return new JsonResponse(Status.OK, "", setting).build(); + return new JsonResponse<>(Status.OK, "", setting).build(); } /** @@ -163,14 +153,14 @@ public Response restartSetting(@PathParam("settingId") String settingId) { interpreterFactory.restart(settingId); } catch (InterpreterException e) { logger.error("Exception in InterpreterRestApi while restartSetting ", e); - return new JsonResponse( - Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); + return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)) + .build(); } InterpreterSetting setting = interpreterFactory.get(settingId); if (setting == null) { - return new JsonResponse(Status.NOT_FOUND, "", settingId).build(); + return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build(); } - return new JsonResponse(Status.OK, "", setting).build(); + return new JsonResponse<>(Status.OK, "", setting).build(); } /** @@ -180,28 +170,24 @@ public Response restartSetting(@PathParam("settingId") String settingId) { @ZeppelinApi public Response listInterpreter(String message) { Map m = interpreterFactory.getAvailableInterpreterSettings(); - return new JsonResponse(Status.OK, "", m).build(); + return new JsonResponse<>(Status.OK, "", m).build(); } /** * List of dependency resolving repositories - * - * @return */ @GET @Path("repository") @ZeppelinApi public Response listRepositories() { - List interpreterRepositories = null; - interpreterRepositories = interpreterFactory.getRepositories(); - return new JsonResponse(Status.OK, "", interpreterRepositories).build(); + List interpreterRepositories = interpreterFactory.getRepositories(); + return new JsonResponse<>(Status.OK, "", interpreterRepositories).build(); } /** * Add new repository * - * @param message - * @return + * @param message Repository */ @POST @Path("repository") @@ -209,16 +195,13 @@ public Response listRepositories() { public Response addRepository(String message) { try { Repository request = gson.fromJson(message, Repository.class); - interpreterFactory.addRepository( - request.getId(), - request.getUrl(), - request.isSnapshot(), + interpreterFactory.addRepository(request.getId(), request.getUrl(), request.isSnapshot(), request.getAuthentication()); logger.info("New repository {} added", request.getId()); } catch (Exception e) { logger.error("Exception in InterpreterRestApi while adding repository ", e); - return new JsonResponse( - Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); + return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), + ExceptionUtils.getStackTrace(e)).build(); } return new JsonResponse(Status.CREATED).build(); } @@ -226,8 +209,7 @@ public Response addRepository(String message) { /** * Delete repository * - * @param repoId - * @return + * @param repoId ID of repository */ @DELETE @Path("repository/{repoId}") @@ -238,8 +220,8 @@ public Response removeRepository(@PathParam("repoId") String repoId) { interpreterFactory.removeRepository(repoId); } catch (Exception e) { logger.error("Exception in InterpreterRestApi while removing repository ", e); - return new JsonResponse( - Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build(); + return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), + ExceptionUtils.getStackTrace(e)).build(); } return new JsonResponse(Status.OK).build(); } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java index 742f8fe609c..08924d2451d 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Set; - import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -36,8 +35,14 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; import org.apache.commons.lang3.StringUtils; +import org.quartz.CronExpression; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.zeppelin.annotation.ZeppelinApi; import org.apache.zeppelin.interpreter.InterpreterSetting; import org.apache.zeppelin.notebook.Note; @@ -54,12 +59,6 @@ import org.apache.zeppelin.socket.NotebookServer; import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.utils.SecurityUtils; -import org.quartz.CronExpression; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Sets; -import com.google.gson.Gson; /** * Rest api endpoint for the noteBook. @@ -74,9 +73,6 @@ public class NotebookRestApi { private SearchService notebookIndex; private NotebookAuthorization notebookAuthorization; - public NotebookRestApi() { - } - public NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchService search) { this.notebook = notebook; this.notebookServer = notebookServer; @@ -98,7 +94,7 @@ public Response getNotePermissions(@PathParam("noteId") String noteId) { return new JsonResponse<>(Status.OK, "", permissionsMap).build(); } - String ownerPermissionError(Set current, Set allowed) throws IOException { + private String ownerPermissionError(Set current, Set allowed) throws IOException { LOG.info("Cannot change permissions. Connection owners {}. Allowed owners {}", current.toString(), allowed.toString()); return "Insufficient privileges to change permissions.\n\n" + @@ -114,8 +110,12 @@ String ownerPermissionError(Set current, Set allowed) throws IOE @ZeppelinApi public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException { - HashMap permMap = gson.fromJson(req, - new TypeToken>() { + /** + * TODO(jl): Fixed the type of HashSet + * https://issues.apache.org/jira/browse/ZEPPELIN-1162 + */ + HashMap permMap = + gson.fromJson(req, new TypeToken>() { }.getType()); Note note = notebook.getNote(noteId); String principal = SecurityUtils.getPrincipal(); @@ -127,8 +127,8 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re userAndRoles.add(principal); userAndRoles.addAll(roles); if (!notebookAuthorization.isOwner(noteId, userAndRoles)) { - return new JsonResponse<>(Status.FORBIDDEN, ownerPermissionError(userAndRoles, - notebookAuthorization.getOwners(noteId))).build(); + return new JsonResponse<>(Status.FORBIDDEN, + ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId))).build(); } HashSet readers = permMap.get("readers"); @@ -233,7 +233,7 @@ public Response getNotebook(@PathParam("notebookId") String notebookId) throws I /** * export note REST API * - * @param + * @param noteId ID of Note * @return note JSON with status.OK * @throws IOException */ @@ -300,7 +300,7 @@ public Response createNote(String message) throws IOException { /** * Delete note REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException */ @@ -324,15 +324,15 @@ public Response deleteNote(@PathParam("notebookId") String notebookId) throws IO /** * Clone note REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.CREATED * @throws IOException, CloneNotSupportedException, IllegalArgumentException */ @POST @Path("{notebookId}") @ZeppelinApi - public Response cloneNote(@PathParam("notebookId") String notebookId, String message) throws - IOException, CloneNotSupportedException, IllegalArgumentException { + public Response cloneNote(@PathParam("notebookId") String notebookId, String message) + throws IOException, CloneNotSupportedException, IllegalArgumentException { LOG.info("clone notebook by JSON {}", message); NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.class); String newNoteName = request.getName(); @@ -383,7 +383,7 @@ public Response insertParagraph(@PathParam("notebookId") String notebookId, Stri /** * Get paragraph REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with information of the paragraph * @throws IOException */ @@ -448,7 +448,7 @@ public Response moveParagraph(@PathParam("notebookId") String notebookId, /** * Delete paragraph REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException */ @@ -480,7 +480,7 @@ public Response deleteParagraph(@PathParam("notebookId") String notebookId, /** * Run notebook jobs REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -502,7 +502,7 @@ public Response runNoteJobs(@PathParam("notebookId") String notebookId) /** * Stop(delete) notebook jobs REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -528,7 +528,7 @@ public Response stopNoteJobs(@PathParam("notebookId") String notebookId) /** * Get notebook job status REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -574,8 +574,8 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, // handle params if presented if (!StringUtils.isEmpty(message)) { - RunParagraphWithParametersRequest request = gson.fromJson(message, - RunParagraphWithParametersRequest.class); + RunParagraphWithParametersRequest request = + gson.fromJson(message, RunParagraphWithParametersRequest.class); Map paramsForUpdating = request.getParams(); if (paramsForUpdating != null) { paragraph.settings.getParams().putAll(paramsForUpdating); @@ -592,7 +592,8 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, /** * Stop(delete) paragraph job REST API * - * @param + * @param notebookId ID of Notebook + * @param paragraphId ID of Paragraph * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -601,6 +602,10 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, @ZeppelinApi public Response stopParagraph(@PathParam("notebookId") String notebookId, @PathParam("paragraphId") String paragraphId) throws IOException, IllegalArgumentException { + /** + * TODO(jl): Fixed notebookId to noteId + * https://issues.apache.org/jira/browse/ZEPPELIN-1163 + */ LOG.info("stop paragraph job {} ", notebookId); Note note = notebook.getNote(notebookId); if (note == null) { @@ -627,10 +632,10 @@ public Response stopParagraph(@PathParam("notebookId") String notebookId, @ZeppelinApi public Response registerCronJob(@PathParam("notebookId") String notebookId, String message) throws IOException, IllegalArgumentException { + // TODO(jl): Fixed notebookId to noteId LOG.info("Register cron job note={} request cron msg={}", notebookId, message); - CronRequest request = gson.fromJson(message, - CronRequest.class); + CronRequest request = gson.fromJson(message, CronRequest.class); Note note = notebook.getNote(notebookId); if (note == null) { @@ -652,7 +657,7 @@ public Response registerCronJob(@PathParam("notebookId") String notebookId, Stri /** * Remove cron job REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -661,6 +666,7 @@ public Response registerCronJob(@PathParam("notebookId") String notebookId, Stri @ZeppelinApi public Response removeCronJob(@PathParam("notebookId") String notebookId) throws IOException, IllegalArgumentException { + // TODO(jl): Fixed notebookId to noteId LOG.info("Remove cron job note {}", notebookId); Note note = notebook.getNote(notebookId); @@ -679,7 +685,7 @@ public Response removeCronJob(@PathParam("notebookId") String notebookId) /** * Get cron job REST API * - * @param + * @param notebookId ID of Notebook * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -688,6 +694,7 @@ public Response removeCronJob(@PathParam("notebookId") String notebookId) @ZeppelinApi public Response getCronJob(@PathParam("notebookId") String notebookId) throws IOException, IllegalArgumentException { + // TODO(jl): Fixed notebookId to noteId LOG.info("Get cron job note {}", notebookId); Note note = notebook.getNote(notebookId); @@ -701,7 +708,6 @@ public Response getCronJob(@PathParam("notebookId") String notebookId) /** * Get notebook jobs for job manager * - * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -724,7 +730,6 @@ public Response getJobListforNotebook() throws IOException, IllegalArgumentExcep /** * Get updated notebook jobs for job manager * - * @param * @return JSON with status.OK * @throws IOException, IllegalArgumentException */ @@ -757,7 +762,7 @@ public Response search(@QueryParam("q") String queryTerm) { LOG.info("Searching notebooks for: {}", queryTerm); String principal = SecurityUtils.getPrincipal(); HashSet roles = SecurityUtils.getRoles(); - HashSet userAndRoles = new HashSet(); + HashSet userAndRoles = new HashSet<>(); userAndRoles.add(principal); userAndRoles.addAll(roles); List> notebooksFound = notebookIndex.query(queryTerm); diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java index 8918241bc9f..750370fa905 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java @@ -468,12 +468,12 @@ public List getDefaultInterpreterSettingList() { return defaultSettings; } - public List getRegisteredInterpreterList() { + List getRegisteredInterpreterList() { return new ArrayList<>(Interpreter.registeredInterpreters.values()); } - public boolean findDefaultInterpreter(List infos) { + private boolean findDefaultInterpreter(List infos) { for (InterpreterInfo interpreterInfo : infos) { if (interpreterInfo.isDefaultInterpreter()) return true; @@ -1230,7 +1230,7 @@ public void setEnv(Map env) { } - public Interpreter getDevInterpreter() { + private Interpreter getDevInterpreter() { if (devInterpreter == null) { InterpreterOption option = new InterpreterOption(); option.setRemote(true); diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfo.java index 61d7d931621..c104b9d7eea 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfo.java @@ -25,15 +25,10 @@ */ public class InterpreterInfo { private String name; - @SerializedName("class") - private String className; + @SerializedName("class") private String className; private boolean defaultInterpreter = false; - public InterpreterInfo(String className, String name) { - this(className, name, false); - } - - public InterpreterInfo(String className, String name, boolean defaultInterpreter) { + InterpreterInfo(String className, String name, boolean defaultInterpreter) { this.className = className; this.name = name; this.defaultInterpreter = defaultInterpreter; @@ -51,18 +46,10 @@ public void setName(String name) { this.name = name; } - public void setClassName(String className) { - this.className = className; - } - - public boolean isDefaultInterpreter() { + boolean isDefaultInterpreter() { return defaultInterpreter; } - public void setDefaultInterpreter(boolean defaultInterpreter) { - this.defaultInterpreter = defaultInterpreter; - } - @Override public boolean equals(Object obj) { if (!(obj instanceof InterpreterInfo)) { @@ -72,9 +59,9 @@ public boolean equals(Object obj) { boolean sameName = null == getName() ? null == other.getName() : getName().equals(other.getName()); - boolean sameClassName = - null == getClassName() ? null == other.getClassName() : - getClassName().equals(other.getClassName()); + boolean sameClassName = null == getClassName() ? + null == other.getClassName() : + getClassName().equals(other.getClassName()); boolean sameIsDefaultInterpreter = defaultInterpreter == other.isDefaultInterpreter(); return sameName && sameClassName && sameIsDefaultInterpreter; diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java index f951d78a057..0e749905278 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java @@ -17,9 +17,6 @@ package org.apache.zeppelin.interpreter; -import com.google.gson.annotations.SerializedName; -import org.apache.zeppelin.dep.Dependency; - import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -28,6 +25,10 @@ import java.util.Map; import java.util.Properties; +import com.google.gson.annotations.SerializedName; + +import org.apache.zeppelin.dep.Dependency; + import static org.apache.zeppelin.notebook.utility.IdHashes.generateId; /** @@ -40,17 +41,14 @@ public class InterpreterSetting { private String refName; // always be null in case of InterpreterSettingRef private Properties properties; - @SerializedName("interpreterGroup") - private List interpreterInfos; - private transient Map interpreterGroupRef = new HashMap<>(); + @SerializedName("interpreterGroup") private List interpreterInfos; + private final transient Map interpreterGroupRef = new HashMap<>(); private List dependencies; private InterpreterOption option; private transient String path; - @Deprecated - private String group; - @Deprecated - private transient InterpreterGroupFactory interpreterGroupFactory; + @Deprecated private String group; + @Deprecated private transient InterpreterGroupFactory interpreterGroupFactory; public InterpreterSetting() { @@ -76,6 +74,7 @@ public InterpreterSetting(String name, String refName, List int /** * Create interpreter from interpreterSettingRef + * * @param o interpreterSetting from interpreterSettingRef */ public InterpreterSetting(InterpreterSetting o) { @@ -91,7 +90,7 @@ public String getName() { return name; } - public String getRefName() { + String getRefName() { return refName; } @@ -129,7 +128,7 @@ public Collection getAllInterpreterGroups() { } } - public void closeAndRemoveInterpreterGroup(String noteId) { + void closeAndRemoveInterpreterGroup(String noteId) { String key = getInterpreterProcessKey(noteId); InterpreterGroup groupToRemove; synchronized (interpreterGroupRef) { @@ -142,7 +141,7 @@ public void closeAndRemoveInterpreterGroup(String noteId) { } } - public void closeAndRmoveAllInterpreterGroups() { + void closeAndRmoveAllInterpreterGroups() { synchronized (interpreterGroupRef) { HashSet groupsToRemove = new HashSet<>(interpreterGroupRef.keySet()); for (String key : groupsToRemove) { @@ -190,11 +189,11 @@ public List getInterpreterInfos() { return interpreterInfos; } - public void setInterpreterGroupFactory(InterpreterGroupFactory interpreterGroupFactory) { + void setInterpreterGroupFactory(InterpreterGroupFactory interpreterGroupFactory) { this.interpreterGroupFactory = interpreterGroupFactory; } - public void appendDependencies(List dependencies) { + void appendDependencies(List dependencies) { for (Dependency dependency : dependencies) { if (!this.dependencies.contains(dependency)) { this.dependencies.add(dependency); @@ -202,19 +201,19 @@ public void appendDependencies(List dependencies) { } } - public void setInterpreterOption(InterpreterOption interpreterOption) { + void setInterpreterOption(InterpreterOption interpreterOption) { this.option = interpreterOption; } - public void updateProperties(Properties p) { + void updateProperties(Properties p) { this.properties.putAll(p); } - public void setRefName(String refName) { + void setRefName(String refName) { this.refName = refName; } - public void setName(String name) { + void setName(String name) { this.name = name; } } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index f67ffa51593..d9ff4e6d8a5 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -29,12 +29,22 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import com.google.gson.Gson; import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.Input; -import org.apache.zeppelin.interpreter.*; +import org.apache.zeppelin.interpreter.Interpreter; +import org.apache.zeppelin.interpreter.InterpreterException; +import org.apache.zeppelin.interpreter.InterpreterFactory; +import org.apache.zeppelin.interpreter.InterpreterGroup; +import org.apache.zeppelin.interpreter.InterpreterOutput; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.InterpreterSetting; import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.notebook.repo.NotebookRepo; @@ -43,12 +53,8 @@ import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.search.SearchService; - -import com.google.gson.Gson; import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Binded interpreters for a note @@ -59,7 +65,8 @@ public class Note implements Serializable, ParagraphJobListener { // threadpool for delayed persist of note private static final ScheduledThreadPoolExecutor delayedPersistThreadPool = - new ScheduledThreadPoolExecutor(0); + new ScheduledThreadPoolExecutor(0); + static { delayedPersistThreadPool.setRemoveOnCancelPolicy(true); } @@ -84,24 +91,24 @@ public class Note implements Serializable, ParagraphJobListener { /** * note configurations. - * + *

* - looknfeel - cron */ private Map config = new HashMap<>(); /** * note information. - * + *

* - cron : cron expression validity. */ private Map info = new HashMap<>(); - public Note() {} + public Note() { + } - public Note(NotebookRepo repo, InterpreterFactory factory, - JobListenerFactory jlFactory, SearchService noteIndex, Credentials credentials, - NoteEventListener noteEventListener) { + public Note(NotebookRepo repo, InterpreterFactory factory, JobListenerFactory jlFactory, + SearchService noteIndex, Credentials credentials, NoteEventListener noteEventListener) { this.repo = repo; this.factory = factory; this.jobListenerFactory = jlFactory; @@ -138,10 +145,10 @@ public String getName() { return name; } - private String normalizeNoteName(String name){ + private String normalizeNoteName(String name) { name = name.trim(); name = name.replace("\\", "/"); - while (name.indexOf("///") >= 0) { + while (name.contains("///")) { name = name.replaceAll("///", "/"); } name = name.replaceAll("//", "/"); @@ -158,7 +165,7 @@ public void setName(String name) { this.name = name; } - public void setInterpreterFactory(InterpreterFactory factory) { + void setInterpreterFactory(InterpreterFactory factory) { this.factory = factory; synchronized (paragraphs) { for (Paragraph p : paragraphs) { @@ -167,19 +174,11 @@ public void setInterpreterFactory(InterpreterFactory factory) { } } - public JobListenerFactory getJobListenerFactory() { - return jobListenerFactory; - } - - public void setJobListenerFactory(JobListenerFactory jobListenerFactory) { + void setJobListenerFactory(JobListenerFactory jobListenerFactory) { this.jobListenerFactory = jobListenerFactory; } - public NotebookRepo getNotebookRepo() { - return repo; - } - - public void setNotebookRepo(NotebookRepo repo) { + void setNotebookRepo(NotebookRepo repo) { this.repo = repo; } @@ -189,14 +188,14 @@ public void setIndex(SearchService index) { public Credentials getCredentials() { return credentials; - }; + } public void setCredentials(Credentials credentials) { this.credentials = credentials; } - public Map> getAngularObjects() { + Map> getAngularObjects() { return angularObjects; } @@ -219,9 +218,9 @@ public Paragraph addParagraph() { /** * Clone paragraph and add it to note. * - * @param srcParagraph + * @param srcParagraph source paragraph */ - public void addCloneParagraph(Paragraph srcParagraph) { + void addCloneParagraph(Paragraph srcParagraph) { // Keep paragraph original ID final Paragraph newParagraph = new Paragraph(srcParagraph.getId(), this, this, factory); @@ -243,8 +242,8 @@ public void addCloneParagraph(Paragraph srcParagraph) { newParagraph.setReturn(result, null); } catch (Exception e) { // 'result' part of Note consists of exception, instead of actual interpreter results - logger.warn("Paragraph " + srcParagraph.getId() + " has a result with exception. " - + e.getMessage()); + logger.warn( + "Paragraph " + srcParagraph.getId() + " has a result with exception. " + e.getMessage()); } synchronized (paragraphs) { @@ -258,7 +257,7 @@ public void addCloneParagraph(Paragraph srcParagraph) { /** * Insert paragraph in given index. * - * @param index + * @param index index of paragraphs */ public Paragraph insertParagraph(int index) { Paragraph p = new Paragraph(this, this, factory); @@ -291,7 +290,7 @@ private String getInterpreterName(String replName) { /** * Remove paragraph by id. * - * @param paragraphId + * @param paragraphId ID of paragraph * @return a paragraph that was deleted, or null otherwise */ public Paragraph removeParagraph(String paragraphId) { @@ -318,13 +317,12 @@ public Paragraph removeParagraph(String paragraphId) { /** * Clear paragraph output by id. * - * @param paragraphId - * @return + * @param paragraphId ID of paragraph + * @return Paragraph */ public Paragraph clearParagraphOutput(String paragraphId) { synchronized (paragraphs) { - for (int i = 0; i < paragraphs.size(); i++) { - Paragraph p = paragraphs.get(i); + for (Paragraph p : paragraphs) { if (p.getId().equals(paragraphId)) { p.setReturn(null, null); return p; @@ -337,8 +335,8 @@ public Paragraph clearParagraphOutput(String paragraphId) { /** * Move paragraph into the new index (order from 0 ~ n-1). * - * @param paragraphId - * @param index new index + * @param paragraphId ID of paragraph + * @param index new index */ public void moveParagraph(String paragraphId, int index) { moveParagraph(paragraphId, index, false); @@ -347,8 +345,8 @@ public void moveParagraph(String paragraphId, int index) { /** * Move paragraph into the new index (order from 0 ~ n-1). * - * @param paragraphId - * @param index new index + * @param paragraphId ID of paragraph + * @param index new index * @param throwWhenIndexIsOutOfBound whether throw IndexOutOfBoundException * when index is out of bound */ @@ -412,7 +410,7 @@ public Paragraph getLastParagraph() { } } - public List> generateParagraphsInfo (){ + public List> generateParagraphsInfo() { List> paragraphsInfo = new LinkedList<>(); synchronized (paragraphs) { for (Paragraph p : paragraphs) { @@ -462,7 +460,7 @@ public void runAll() { /** * Run a single paragraph. * - * @param paragraphId + * @param paragraphId ID of paragraph */ public void run(String paragraphId) { Paragraph p = getParagraph(paragraphId); @@ -487,9 +485,8 @@ public void run(String paragraphId) { /** * Check whether all paragraphs belongs to this note has terminated - * @return */ - public boolean isTerminated() { + boolean isTerminated() { synchronized (paragraphs) { for (Paragraph p : paragraphs) { if (!p.isTerminated()) { @@ -504,9 +501,8 @@ public boolean isTerminated() { public List completion(String paragraphId, String buffer, int cursor) { Paragraph p = getParagraph(paragraphId); p.setListener(jobListenerFactory.getParagraphJobListener(this)); - List completion = p.completion(buffer, cursor); - return completion; + return p.completion(buffer, cursor); } public List getParagraphs() { @@ -550,8 +546,8 @@ private void removeAllAngularObjectInParagraph(String paragraphId) { List appStates = getParagraph(paragraphId).getAllApplicationStates(); if (appStates != null) { for (ApplicationState app : appStates) { - ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess( - id, app.getId()); + ((RemoteAngularObjectRegistry) registry) + .removeAllAndNotifyRemoteProcess(id, app.getId()); } } } else { @@ -587,13 +583,12 @@ public void setLastReplName(String paragraphId) { /** * Persist this note with maximum delay. - * @param maxDelaySec */ public void persist(int maxDelaySec, AuthenticationInfo subject) { startDelayedPersistTimer(maxDelaySec, subject); } - public void unpersist(AuthenticationInfo subject) throws IOException { + void unpersist(AuthenticationInfo subject) throws IOException { repo.remove(id(), subject); } @@ -650,7 +645,7 @@ public void setInfo(Map info) { this.info = info; } - public String getLastReplName() { + String getLastReplName() { return lastReplName.get(); } @@ -713,7 +708,7 @@ public void onOutputUpdate(Paragraph paragraph, InterpreterOutput out, String ou } } - public void setNoteEventListener(NoteEventListener noteEventListener) { + void setNoteEventListener(NoteEventListener noteEventListener) { this.noteEventListener = noteEventListener; } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index afc928ff6ac..bfe525005e0 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -30,6 +30,22 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.stream.JsonReader; +import org.quartz.CronScheduleBuilder; +import org.quartz.CronTrigger; +import org.quartz.JobBuilder; +import org.quartz.JobDetail; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.JobKey; +import org.quartz.SchedulerException; +import org.quartz.TriggerBuilder; +import org.quartz.impl.StdSchedulerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; import org.apache.zeppelin.display.AngularObject; @@ -46,34 +62,21 @@ import org.apache.zeppelin.search.SearchService; import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; -import org.quartz.CronScheduleBuilder; -import org.quartz.CronTrigger; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.JobKey; -import org.quartz.SchedulerException; -import org.quartz.TriggerBuilder; -import org.quartz.impl.StdSchedulerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.stream.JsonReader; /** * Collection of Notes. */ public class Notebook implements NoteEventListener { - static Logger logger = LoggerFactory.getLogger(Notebook.class); + private static final Logger logger = LoggerFactory.getLogger(Notebook.class); @SuppressWarnings("unused") @Deprecated //TODO(bzz): remove unused private SchedulerFactory schedulerFactory; private InterpreterFactory replFactory; - /** Keep the order. */ - Map notes = new LinkedHashMap(); + /** + * Keep the order. + */ + private final Map notes = new LinkedHashMap<>(); private ZeppelinConfiguration conf; private StdSchedulerFactory quertzSchedFact; private org.quartz.Scheduler quartzSched; @@ -88,23 +91,15 @@ public class Notebook implements NoteEventListener { /** * Main constructor \w manual Dependency Injection * - * @param conf - * @param notebookRepo - * @param schedulerFactory - * @param replFactory - * @param jobListenerFactory - * @param notebookIndex - (nullable) for indexing all notebooks on creating. - * @param notebookAuthorization - * + * @param notebookIndex - (nullable) for indexing all notebooks on creating. * @throws IOException * @throws SchedulerException */ public Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo, - SchedulerFactory schedulerFactory, - InterpreterFactory replFactory, JobListenerFactory jobListenerFactory, - SearchService notebookIndex, - NotebookAuthorization notebookAuthorization, - Credentials credentials) throws IOException, SchedulerException { + SchedulerFactory schedulerFactory, InterpreterFactory replFactory, + JobListenerFactory jobListenerFactory, SearchService notebookIndex, + NotebookAuthorization notebookAuthorization, Credentials credentials) + throws IOException, SchedulerException { this.conf = conf; this.notebookRepo = notebookRepo; this.schedulerFactory = schedulerFactory; @@ -132,7 +127,6 @@ public Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo, /** * Create new note. * - * @return * @throws IOException */ public Note createNote(AuthenticationInfo subject) throws IOException { @@ -149,18 +143,12 @@ public Note createNote(AuthenticationInfo subject) throws IOException { /** * Create new note. * - * @return * @throws IOException */ public Note createNote(List interpreterIds, AuthenticationInfo subject) throws IOException { - Note note = new Note( - notebookRepo, - replFactory, - jobListenerFactory, - notebookIndex, - credentials, - this); + Note note = + new Note(notebookRepo, replFactory, jobListenerFactory, notebookIndex, credentials, this); synchronized (notes) { notes.put(note.id(), note); } @@ -174,9 +162,10 @@ public Note createNote(List interpreterIds, AuthenticationInfo subject) fireNoteCreateEvent(note); return note; } - + /** * Export existing note. + * * @param noteId - the note ID to clone * @return Note JSON * @throws IOException, IllegalArgumentException @@ -194,8 +183,9 @@ public String exportNote(String noteId) throws IOException, IllegalArgumentExcep /** * import JSON as a new note. + * * @param sourceJson - the note JSON to import - * @param noteName - the name of the new note + * @param noteName - the name of the new note * @return notebook ID * @throws IOException */ @@ -204,8 +194,8 @@ public Note importNote(String sourceJson, String noteName, AuthenticationInfo su GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); - Gson gson = gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()) - .create(); + Gson gson = + gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create(); JsonReader reader = new JsonReader(new StringReader(sourceJson)); reader.setLenient(true); Note newNote; @@ -232,13 +222,14 @@ public Note importNote(String sourceJson, String noteName, AuthenticationInfo su /** * Clone existing note. + * * @param sourceNoteID - the note ID to clone - * @param newNoteName - the name of the new note + * @param newNoteName - the name of the new note * @return noteId * @throws IOException, CloneNotSupportedException, IllegalArgumentException */ - public Note cloneNote(String sourceNoteID, String newNoteName, AuthenticationInfo subject) throws - IOException, CloneNotSupportedException, IllegalArgumentException { + public Note cloneNote(String sourceNoteID, String newNoteName, AuthenticationInfo subject) + throws IOException, CloneNotSupportedException, IllegalArgumentException { Note sourceNote = getNote(sourceNoteID); if (sourceNote == null) { @@ -262,8 +253,8 @@ public Note cloneNote(String sourceNoteID, String newNoteName, AuthenticationInf return newNote; } - public void bindInterpretersToNote(String id, - List interpreterSettingIds) throws IOException { + public void bindInterpretersToNote(String id, List interpreterSettingIds) + throws IOException { Note note = getNote(id); if (note != null) { List currentBindings = replFactory.getInterpreterSettings(id); @@ -279,12 +270,12 @@ public void bindInterpretersToNote(String id, } } - public List getBindedInterpreterSettingsIds(String id) { + List getBindedInterpreterSettingsIds(String id) { Note note = getNote(id); if (note != null) { return getInterpreterFactory().getInterpreters(note.getId()); } else { - return new LinkedList(); + return new LinkedList<>(); } } @@ -293,7 +284,7 @@ public List getBindedInterpreterSettings(String id) { if (note != null) { return replFactory.getInterpreterSettings(note.getId()); } else { - return new LinkedList(); + return new LinkedList<>(); } } @@ -325,8 +316,8 @@ public void removeNote(String id, AuthenticationInfo subject) { List appStates = p.getAllApplicationStates(); if (appStates != null) { for (ApplicationState app : appStates) { - ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess( - id, app.getId()); + ((RemoteAngularObjectRegistry) registry) + .removeAllAndNotifyRemoteProcess(id, app.getId()); } } } @@ -393,8 +384,7 @@ private Note loadNoteFromRepo(String id, AuthenticationInfo subject) { Date lastUpdatedDate = new Date(0); for (Paragraph p : note.getParagraphs()) { p.setNote(note); - if (p.getDateFinished() != null && - lastUpdatedDate.before(p.getDateFinished())) { + if (p.getDateFinished() != null && lastUpdatedDate.before(p.getDateFinished())) { lastUpdatedDate = p.getDateFinished(); } } @@ -456,7 +446,6 @@ private void loadAllNotes() throws IOException { * Reload all notes from repository after clearing `notes` * to reflect the changes of added/deleted/modified notebooks on file system level. * - * @return * @throws IOException */ public void reloadAllNotes(AuthenticationInfo subject) throws IOException { @@ -477,34 +466,34 @@ public void reloadAllNotes(AuthenticationInfo subject) throws IOException { } } - @SuppressWarnings("rawtypes") - class SnapshotAngularObject { + private class SnapshotAngularObject { String intpGroupId; AngularObject angularObject; Date lastUpdate; - public SnapshotAngularObject(String intpGroupId, - AngularObject angularObject, Date lastUpdate) { + SnapshotAngularObject(String intpGroupId, AngularObject angularObject, Date lastUpdate) { super(); this.intpGroupId = intpGroupId; this.angularObject = angularObject; this.lastUpdate = lastUpdate; } - public String getIntpGroupId() { + String getIntpGroupId() { return intpGroupId; } - public AngularObject getAngularObject() { + + AngularObject getAngularObject() { return angularObject; } - public Date getLastUpdate() { + + Date getLastUpdate() { return lastUpdate; } } public List getAllNotes() { synchronized (notes) { - List noteList = new ArrayList(notes.values()); + List noteList = new ArrayList<>(notes.values()); Collections.sort(noteList, new Comparator() { @Override public int compare(Note note1, Note note2) { @@ -523,14 +512,6 @@ public int compare(Note note1, Note note2) { } } - public JobListenerFactory getJobListenerFactory() { - return jobListenerFactory; - } - - public void setJobListenerFactory(JobListenerFactory jobListenerFactory) { - this.jobListenerFactory = jobListenerFactory; - } - private Map getParagraphForJobManagerItem(Paragraph paragraph) { Map paragraphItem = new HashMap<>(); @@ -553,16 +534,16 @@ private Map getParagraphForJobManagerItem(Paragraph paragraph) { private long getUnixTimeLastRunParagraph(Paragraph paragraph) { - Date lastRunningDate = null; - long lastRunningUnixTime = 0; + Date lastRunningDate; + long lastRunningUnixTime; Date paragaraphDate = paragraph.getDateStarted(); // diff started time <-> finishied time if (paragaraphDate == null) { paragaraphDate = paragraph.getDateFinished(); } else { - if (paragraph.getDateFinished() != null && - paragraph.getDateFinished().after(paragaraphDate)) { + if (paragraph.getDateFinished() != null && paragraph.getDateFinished() + .after(paragaraphDate)) { paragaraphDate = paragraph.getDateFinished(); } } @@ -612,11 +593,10 @@ public List> getJobListforNotebook(boolean needsReload, } // set notebook type ( cron or normal ) - if (note.getConfig().containsKey(CRON_TYPE_NOTEBOOK_KEYWORD) == true && - !note.getConfig().get(CRON_TYPE_NOTEBOOK_KEYWORD).equals("")) { + if (note.getConfig().containsKey(CRON_TYPE_NOTEBOOK_KEYWORD) && !note.getConfig() + .get(CRON_TYPE_NOTEBOOK_KEYWORD).equals("")) { info.put("notebookType", "cron"); - } - else { + } else { info.put("notebookType", "normal"); } @@ -624,7 +604,7 @@ public List> getJobListforNotebook(boolean needsReload, List> paragraphsInfo = new LinkedList<>(); for (Paragraph paragraph : note.getParagraphs()) { // check paragraph's status. - if (paragraph.getStatus().isRunning() == true) { + if (paragraph.getStatus().isRunning()) { isNotebookRunning = true; isUpdateNotebook = true; } @@ -642,13 +622,13 @@ public List> getJobListforNotebook(boolean needsReload, // set interpreter bind type String interpreterGroupName = null; - if (replFactory.getInterpreterSettings(note.getId()) != null && - replFactory.getInterpreterSettings(note.getId()).size() >= 1) { + if (replFactory.getInterpreterSettings(note.getId()) != null + && replFactory.getInterpreterSettings(note.getId()).size() >= 1) { interpreterGroupName = replFactory.getInterpreterSettings(note.getId()).get(0).getName(); } // not update and not running -> pass - if (isUpdateNotebook == false && isNotebookRunning == false) { + if (!isUpdateNotebook && !isNotebookRunning) { continue; } @@ -666,7 +646,7 @@ public List> getJobListforNotebook(boolean needsReload, /** * Cron task for the note. */ - public static class CronJob implements org.quartz.Job { + private static class CronJob implements org.quartz.Job { public static Notebook notebook; @Override @@ -675,7 +655,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { String noteId = context.getJobDetail().getJobDataMap().getString("noteId"); Note note = notebook.getNote(noteId); note.runAll(); - + while (!note.isTerminated()) { try { Thread.sleep(1000); @@ -683,7 +663,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { logger.error(e.toString(), e); } } - + boolean releaseResource = false; try { Map config = note.getConfig(); @@ -694,11 +674,11 @@ public void execute(JobExecutionContext context) throws JobExecutionException { logger.error(e.getMessage(), e); } if (releaseResource) { - for (InterpreterSetting setting : - notebook.getInterpreterFactory().getInterpreterSettings(note.getId())) { + for (InterpreterSetting setting : notebook.getInterpreterFactory() + .getInterpreterSettings(note.getId())) { notebook.getInterpreterFactory().restart(setting.getId()); } - } + } } } @@ -723,17 +703,15 @@ public void refreshCron(String id) { JobDetail newJob = JobBuilder.newJob(CronJob.class).withIdentity(id, "note").usingJobData("noteId", id) - .build(); + .build(); Map info = note.getInfo(); info.put("cron", null); CronTrigger trigger = null; try { - trigger = - TriggerBuilder.newTrigger().withIdentity("trigger_" + id, "note") - .withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(id, "note") - .build(); + trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + id, "note") + .withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(id, "note").build(); } catch (Exception e) { logger.error("Error", e); info.put("cron", e.getMessage()); diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java index c185badb9a1..ee5be671153 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/utility/IdHashes.java @@ -26,9 +26,9 @@ * Generate Tiny ID. */ public class IdHashes { - public static final char[] DICTIONARY = new char[] {'1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', - 'V', 'W', 'X', 'Y', 'Z'}; + private static final char[] DICTIONARY = + new char[] {'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; /** * encodes the given string into the base of the dictionary provided in the constructor. @@ -36,7 +36,7 @@ public class IdHashes { * @param value the number to encode. * @return the encoded string. */ - public static String encode(Long value) { + private static String encode(Long value) { List result = new ArrayList(); BigInteger base = new BigInteger("" + DICTIONARY.length); From 5e508642b094368b9372b0f7f687923e1b537d56 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Thu, 14 Jul 2016 19:55:03 +0900 Subject: [PATCH 19/24] Reverted refName to group --- .../zeppelin/rest/InterpreterRestApi.java | 2 +- .../message/NewInterpreterSettingRequest.java | 14 +++--- .../zeppelin/rest/InterpreterRestApiTest.java | 2 +- .../interpreter-create.html | 2 +- .../app/interpreter/interpreter.controller.js | 4 +- .../interpreter/InterpreterFactory.java | 49 +++++++++---------- .../interpreter/InterpreterSetting.java | 24 ++++----- .../org/apache/zeppelin/notebook/Note.java | 7 +-- 8 files changed, 45 insertions(+), 59 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index 6e837aba05d..13c06e399bb 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -90,7 +90,7 @@ public Response newSettings(String message) { Properties p = new Properties(); p.putAll(request.getProperties()); InterpreterSetting interpreterSetting = interpreterFactory - .createNewSetting(request.getName(), request.getRefName(), request.getDependencies(), + .createNewSetting(request.getName(), request.getGroup(), request.getDependencies(), request.getOption(), p); logger.info("new setting created with {}", interpreterSetting.getId()); return new JsonResponse<>(Status.CREATED, "", interpreterSetting).build(); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java index 1d453ab01c6..7e3a4147233 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/NewInterpreterSettingRequest.java @@ -27,12 +27,12 @@ * NewInterpreterSetting rest api request message */ public class NewInterpreterSettingRequest { - String name; - String refName; + private String name; + private String group; - Map properties; - List dependencies; - InterpreterOption option; + private Map properties; + private List dependencies; + private InterpreterOption option; public NewInterpreterSettingRequest() { @@ -42,8 +42,8 @@ public String getName() { return name; } - public String getRefName() { - return refName; + public String getGroup() { + return group; } public Map getProperties() { diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java index 8470a54211c..e92432fefaa 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java @@ -87,7 +87,7 @@ public void getSettings() throws IOException { @Test public void testSettingsCRUD() throws IOException { // Call Create Setting REST API - String jsonRequest = "{\"name\":\"md2\",\"refName\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + + String jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," + "\"dependencies\":[]," + "\"option\": { \"remote\": true, \"perNoteSession\": false }}"; diff --git a/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html b/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html index 3e34f9af004..599248b2e56 100644 --- a/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html +++ b/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html @@ -27,7 +27,7 @@

Create new interpreter

Interpreter group
-