Repository: zeppelin Updated Branches: refs/heads/master 97e6293a5 -> 9d564b7fd
[MINOR] Removed InterpreterInfoSerializer and related codes ### What is this PR for? Simplifying InterpreterFactory and reduce classes ### What type of PR is it? [Refactoring] ### Todos * [x] - Remove InterpreterInfoSerializer * [x] - Add annotation for InterpreterInfo ### What is the Jira issue? N/A ### How should this be tested? ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Jongyoul Lee <[email protected]> Closes #1122 from jongyoul/minor-refactoring-gson-interpreterinfo and squashes the following commits: a7aeb53 [Jongyoul Lee] Cleaned codes ac08ce5 [Jongyoul Lee] Cleaned codes 9791989 [Jongyoul Lee] Removed InterpreterInfoSerializer and related codes Added annotation for InterpreterInfo Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/9d564b7f Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/9d564b7f Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/9d564b7f Branch: refs/heads/master Commit: 9d564b7fd357debf4e918559d4280df0fa2d2771 Parents: 97e6293 Author: Jongyoul Lee <[email protected]> Authored: Tue Jul 5 11:38:35 2016 +0900 Committer: Jongyoul Lee <[email protected]> Committed: Wed Jul 6 13:39:38 2016 +0900 ---------------------------------------------------------------------- .../apache/zeppelin/server/JsonResponse.java | 8 +-- .../interpreter/InterpreterFactory.java | 22 +++----- .../interpreter/InterpreterInfoSerializer.java | 58 -------------------- .../interpreter/InterpreterSetting.java | 36 ++++-------- 4 files changed, 18 insertions(+), 106 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d564b7f/zeppelin-server/src/main/java/org/apache/zeppelin/server/JsonResponse.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/server/JsonResponse.java b/zeppelin-server/src/main/java/org/apache/zeppelin/server/JsonResponse.java index 887d42a..8b5eed9 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/server/JsonResponse.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/server/JsonResponse.java @@ -22,12 +22,8 @@ import java.util.ArrayList; import javax.ws.rs.core.NewCookie; import javax.ws.rs.core.Response.ResponseBuilder; -import org.apache.zeppelin.interpreter.Interpreter; -import org.apache.zeppelin.interpreter.InterpreterInfoSerializer; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import org.apache.zeppelin.interpreter.InterpreterSetting; /** * Json response builder. @@ -99,9 +95,7 @@ public class JsonResponse<T> { @Override public String toString() { - GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter( - InterpreterSetting.InterpreterInfo.class, - new InterpreterInfoSerializer()); + GsonBuilder gsonBuilder = new GsonBuilder(); if (pretty) { gsonBuilder.setPrettyPrinting(); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d564b7f/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java ---------------------------------------------------------------------- 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 a691628..b53c2c6 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 @@ -89,7 +89,7 @@ public class InterpreterFactory implements InterpreterGroupFactory { private DependencyResolver depResolver; - private Map<String, String> env = new HashMap<String, String>(); + private Map<String, String> env = new HashMap<>(); private Interpreter devInterpreter; @@ -100,7 +100,7 @@ public class InterpreterFactory implements InterpreterGroupFactory { DependencyResolver depResolver) throws InterpreterException, IOException, RepositoryException { this(conf, new InterpreterOption(true), angularObjectRegistryListener, - remoteInterpreterProcessListener, appEventListener, depResolver); + remoteInterpreterProcessListener, appEventListener, depResolver); } @@ -124,8 +124,6 @@ public class InterpreterFactory implements InterpreterGroupFactory { GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); - builder.registerTypeAdapter( - InterpreterSetting.InterpreterInfo.class, new InterpreterInfoSerializer()); gson = builder.create(); init(); @@ -306,12 +304,6 @@ public class InterpreterFactory implements InterpreterGroupFactory { } private void loadFromFile() throws IOException { - GsonBuilder builder = new GsonBuilder(); - builder.setPrettyPrinting(); - builder.registerTypeAdapter( - InterpreterSetting.InterpreterInfo.class, new InterpreterInfoSerializer()); - Gson gson = builder.create(); - File settingFile = new File(conf.getInterpreterSettingPath()); if (!settingFile.exists()) { // nothing to read @@ -878,10 +870,10 @@ public class InterpreterFactory implements InterpreterGroupFactory { } private Interpreter connectToRemoteRepl(String noteId, - String className, - String host, - int port, - Properties property) { + 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( @@ -1151,7 +1143,7 @@ public class InterpreterFactory implements InterpreterGroupFactory { ZeppelinDevServer.DEFAULT_TEST_INTERPRETER_PORT, new Properties()); - LinkedList<Interpreter> intpList = new LinkedList<Interpreter>(); + LinkedList<Interpreter> intpList = new LinkedList<>(); intpList.add(devInterpreter); interpreterGroup.put("dev", intpList); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d564b7f/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfoSerializer.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfoSerializer.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfoSerializer.java deleted file mode 100644 index 5854983..0000000 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfoSerializer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zeppelin.interpreter; - -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - - -/** - * InterpreterInfo class serializer for gson - * - */ -public class InterpreterInfoSerializer - implements JsonSerializer<InterpreterSetting.InterpreterInfo>, - JsonDeserializer<InterpreterSetting.InterpreterInfo> { - - @Override - public JsonElement serialize(InterpreterSetting.InterpreterInfo interpreterInfo, Type type, - JsonSerializationContext context) { - JsonObject json = new JsonObject(); - json.addProperty("class", interpreterInfo.getClassName()); - json.addProperty("name", interpreterInfo.getName()); - return json; - } - - @Override - public InterpreterSetting.InterpreterInfo deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - JsonObject jsonObject = json.getAsJsonObject(); - String className = jsonObject.get("class").getAsString(); - String name = jsonObject.get("name").getAsString(); - - return new InterpreterSetting.InterpreterInfo(className, name); - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d564b7f/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java ---------------------------------------------------------------------- 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 2060714..cb6c752 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 @@ -18,12 +18,9 @@ package org.apache.zeppelin.interpreter; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.lang.NullArgumentException; +import com.google.gson.annotations.SerializedName; import org.apache.zeppelin.dep.Dependency; -import org.apache.zeppelin.display.AngularObjectRegistry; -import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.notebook.utility.IdHashes; /** @@ -41,17 +38,12 @@ public class InterpreterSetting { // use 'interpreterGroup' as a field name to keep backward compatibility of // conf/interpreter.json file format private List<InterpreterInfo> interpreterGroup; - private transient Map<String, InterpreterGroup> interpreterGroupRef = - new HashMap<String, InterpreterGroup>(); + private transient Map<String, InterpreterGroup> interpreterGroupRef = new HashMap<>(); private List<Dependency> dependencies; private InterpreterOption option; - public InterpreterSetting(String id, - String name, - String group, - List<InterpreterInfo> interpreterInfos, - Properties properties, - List<Dependency> dependencies, + public InterpreterSetting(String id, String name, String group, + List<InterpreterInfo> interpreterInfos, Properties properties, List<Dependency> dependencies, InterpreterOption option) { this.id = id; this.name = name; @@ -60,15 +52,10 @@ public class InterpreterSetting { this.properties = properties; this.dependencies = dependencies; this.option = option; - this.interpreterGroupFactory = interpreterGroupFactory; } - public InterpreterSetting(String name, - String group, - List<InterpreterInfo> interpreterInfos, - Properties properties, - List<Dependency> dependencies, - InterpreterOption option) { + public InterpreterSetting(String name, String group, List<InterpreterInfo> interpreterInfos, + Properties properties, List<Dependency> dependencies, InterpreterOption option) { this(generateId(), name, group, interpreterInfos, properties, dependencies, option); } @@ -78,6 +65,7 @@ public class InterpreterSetting { */ public static class InterpreterInfo { private final String name; + @SerializedName("class") private final String className; public InterpreterInfo(String className, String name) { @@ -148,7 +136,7 @@ public class InterpreterSetting { public Collection<InterpreterGroup> getAllInterpreterGroups() { synchronized (interpreterGroupRef) { - return new LinkedList<InterpreterGroup>(interpreterGroupRef.values()); + return new LinkedList<>(interpreterGroupRef.values()); } } @@ -167,7 +155,7 @@ public class InterpreterSetting { public void closeAndRmoveAllInterpreterGroups() { synchronized (interpreterGroupRef) { - HashSet<String> groupsToRemove = new HashSet<String>(interpreterGroupRef.keySet()); + HashSet<String> groupsToRemove = new HashSet<>(interpreterGroupRef.keySet()); for (String key : groupsToRemove) { closeAndRemoveInterpreterGroup(key); } @@ -184,7 +172,7 @@ public class InterpreterSetting { public List<Dependency> getDependencies() { if (dependencies == null) { - return new LinkedList<Dependency>(); + return new LinkedList<>(); } return dependencies; } @@ -209,10 +197,6 @@ public class InterpreterSetting { return interpreterGroup; } - public InterpreterGroupFactory getInterpreterGroupFactory() { - return interpreterGroupFactory; - } - public void setInterpreterGroupFactory(InterpreterGroupFactory interpreterGroupFactory) { this.interpreterGroupFactory = interpreterGroupFactory; }
