Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AB316200CCA for ; Wed, 19 Jul 2017 09:28:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A7CE91685A9; Wed, 19 Jul 2017 07:28:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A0B841685B0 for ; Wed, 19 Jul 2017 09:28:06 +0200 (CEST) Received: (qmail 83198 invoked by uid 500); 19 Jul 2017 07:28:05 -0000 Mailing-List: contact commits-help@zeppelin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zeppelin.apache.org Delivered-To: mailing list commits@zeppelin.apache.org Received: (qmail 83189 invoked by uid 99); 19 Jul 2017 07:28:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Jul 2017 07:28:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CB159E5E44; Wed, 19 Jul 2017 07:28:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zjffdu@apache.org To: commits@zeppelin.apache.org Message-Id: <661f6e14d73141c38064e7bd2a629797@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: zeppelin git commit: [ZEPPELIN-2758]. NumberFormatException on importing notebook Date: Wed, 19 Jul 2017 07:28:04 +0000 (UTC) archived-at: Wed, 19 Jul 2017 07:28:07 -0000 Repository: zeppelin Updated Branches: refs/heads/master 87705a932 -> 3dd25c24e [ZEPPELIN-2758]. NumberFormatException on importing notebook ### What is this PR for? This is due to the custom TypeAdapter for Paragraph. I don't know why we introduce it. To me it is not necessary. So I remove this in this PR. And the spark UI still can be accessed in frontend. ### What type of PR is it? [Bug Fix] ### Todos * [ ] - Task ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-2758 ### How should this be tested? Unit test is updated and manually 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: Jeff Zhang Closes #2485 from zjffdu/ZEPPELIN-2758 and squashes the following commits: 74f8488 [Jeff Zhang] reset runtimeInfos b51d566 [Jeff Zhang] [ZEPPELIN-2758]. NumberFormatException on importing notebook Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/3dd25c24 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/3dd25c24 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/3dd25c24 Branch: refs/heads/master Commit: 3dd25c24e42538dfc0bfb2d7967c6a928624daea Parents: 87705a9 Author: Jeff Zhang Authored: Sat Jul 15 14:21:15 2017 +0800 Committer: Jeff Zhang Committed: Wed Jul 19 15:27:54 2017 +0800 ---------------------------------------------------------------------- .../json/NotebookTypeAdapterFactory.java | 85 -------------------- .../apache/zeppelin/socket/NotebookServer.java | 15 +--- .../zeppelin/socket/NotebookServerTest.java | 3 +- .../java/org/apache/zeppelin/notebook/Note.java | 23 ++---- .../org/apache/zeppelin/notebook/Paragraph.java | 6 ++ .../json/NotebookTypeAdapterFactory.java | 82 ------------------- 6 files changed, 17 insertions(+), 197 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3dd25c24/zeppelin-server/src/main/java/org/apache/zeppelin/json/NotebookTypeAdapterFactory.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/json/NotebookTypeAdapterFactory.java b/zeppelin-server/src/main/java/org/apache/zeppelin/json/NotebookTypeAdapterFactory.java deleted file mode 100644 index a22c03b..0000000 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/json/NotebookTypeAdapterFactory.java +++ /dev/null @@ -1,85 +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.json; - -import java.io.IOException; - -import org.apache.zeppelin.socket.NotebookServer; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - -/** - * Custom adapter type factory - * Modify the jsonObject before serailaization/deserialization - * Check sample implementation at {@link NotebookServer} - * @param the type whose json is to be customized for serialization/deserialization - */ -public class NotebookTypeAdapterFactory implements TypeAdapterFactory { - private final Class customizedClass; - - public NotebookTypeAdapterFactory(Class customizedClass) { - this.customizedClass = customizedClass; - } - - @SuppressWarnings("unchecked") - // we use a runtime check to guarantee that 'C' and 'T' are equal - public final TypeAdapter create(Gson gson, TypeToken type) { - return type.getRawType() == customizedClass ? (TypeAdapter) customizeTypeAdapter(gson, - (TypeToken) type) : null; - } - - private TypeAdapter customizeTypeAdapter(Gson gson, TypeToken type) { - final TypeAdapter delegate = gson.getDelegateAdapter(this, type); - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - return new TypeAdapter() { - @Override - public void write(JsonWriter out, C value) throws IOException { - JsonElement tree = delegate.toJsonTree(value); - beforeWrite(value, tree); - elementAdapter.write(out, tree); - } - - @Override - public C read(JsonReader in) throws IOException { - JsonElement tree = elementAdapter.read(in); - afterRead(tree); - return delegate.fromJsonTree(tree); - } - }; - } - - /** - * Override this to change {@code toSerialize} before it is written to the - * outgoing JSON stream. - */ - protected void beforeWrite(C source, JsonElement toSerialize) { - } - - /** - * Override this to change {@code deserialized} before it parsed into the - * application type. - */ - protected void afterRead(JsonElement deserialized) { - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3dd25c24/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index c3b18e0..14e4983 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -50,7 +50,6 @@ import org.apache.zeppelin.interpreter.InterpreterSetting; import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.apache.zeppelin.json.NotebookTypeAdapterFactory; import org.apache.zeppelin.notebook.JobListenerFactory; import org.apache.zeppelin.notebook.Folder; import org.apache.zeppelin.notebook.Note; @@ -117,19 +116,7 @@ public class NotebookServer extends WebSocketServlet private static final Logger LOG = LoggerFactory.getLogger(NotebookServer.class); private static Gson gson = new GsonBuilder() - .registerTypeAdapterFactory(new NotebookTypeAdapterFactory(Paragraph.class) { - @Override - protected void beforeWrite(Paragraph source, JsonElement toSerialize) { - Map runtimeInfos = source.getRuntimeInfos(); - if (runtimeInfos != null) { - JsonElement jsonTree = gson.toJsonTree(runtimeInfos); - if (toSerialize instanceof JsonObject) { - JsonObject jsonObj = (JsonObject) toSerialize; - jsonObj.add("runtimeInfos", jsonTree); - } - } - } - }).setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") + .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") .registerTypeAdapter(Date.class, new NotebookImportDeserializer()) .setPrettyPrinting() .registerTypeAdapterFactory(Input.TypeAdapterFactory).create(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3dd25c24/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java index 3a0749f..8da36a6 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java @@ -155,7 +155,8 @@ public class NotebookServerTest extends AbstractTestRestApi { public void testImportNotebook() throws IOException { String msg = "{\"op\":\"IMPORT_NOTE\",\"data\":" + "{\"note\":{\"paragraphs\": [{\"text\": \"Test " + - "paragraphs import\",\"config\":{},\"settings\":{}}]," + + "paragraphs import\"," + "\"progressUpdateIntervalMs\":500," + + "\"config\":{},\"settings\":{}}]," + "\"name\": \"Test Zeppelin notebook import\",\"config\": " + "{}}}}"; Message messageReceived = notebookServer.deserializeMessage(msg); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3dd25c24/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java ---------------------------------------------------------------------- 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 ecbd4da..ff5931c 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 @@ -39,7 +39,6 @@ import org.apache.zeppelin.display.Input; import org.apache.zeppelin.interpreter.*; import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.apache.zeppelin.notebook.json.NotebookTypeAdapterFactory; import org.apache.zeppelin.notebook.repo.NotebookRepo; import org.apache.zeppelin.notebook.utility.IdHashes; import org.apache.zeppelin.resource.ResourcePoolUtils; @@ -62,21 +61,8 @@ public class Note implements ParagraphJobListener, JsonSerializable { private static final long serialVersionUID = 7920699076577612429L; private static Gson gson = new GsonBuilder() .setPrettyPrinting() - .registerTypeAdapterFactory(new NotebookTypeAdapterFactory(Paragraph.class) { - @Override - protected void beforeWrite(Paragraph source, JsonElement toSerialize) { - Map runtimeInfos = source.getRuntimeInfos(); - if (runtimeInfos != null) { - JsonElement jsonTree = gson.toJsonTree(runtimeInfos); - if (toSerialize instanceof JsonObject) { - JsonObject jsonObj = (JsonObject) toSerialize; - jsonObj.add("runtimeInfos", jsonTree); - } - } - } - }).setDateFormat("yyyy-MM-dd HH:mm:ss.SSS") + .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS") .registerTypeAdapter(Date.class, new NotebookImportDeserializer()) - .setPrettyPrinting() .registerTypeAdapterFactory(Input.TypeAdapterFactory).create(); // threadpool for delayed persist of note @@ -920,9 +906,16 @@ public class Note implements ParagraphJobListener, JsonSerializable { public static Note fromJson(String json) { Note note = gson.fromJson(json, Note.class); convertOldInput(note); + note.resetRuntimeInfos(); return note; } + public void resetRuntimeInfos() { + for (Paragraph p : paragraphs) { + p.clearRuntimeInfos(); + } + } + private static void convertOldInput(Note note) { for (Paragraph p : note.paragraphs) { p.settings.convertOldInput(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3dd25c24/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java index be88a1b..ac3d19f 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java @@ -753,6 +753,12 @@ public class Paragraph extends Job implements Cloneable, JsonSerializable { } } + public void clearRuntimeInfos() { + if (this.runtimeInfos != null) { + this.runtimeInfos.clear(); + } + } + public Map getRuntimeInfos() { return runtimeInfos; } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3dd25c24/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/json/NotebookTypeAdapterFactory.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/json/NotebookTypeAdapterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/json/NotebookTypeAdapterFactory.java deleted file mode 100644 index 2ed7df0..0000000 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/json/NotebookTypeAdapterFactory.java +++ /dev/null @@ -1,82 +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.notebook.json; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - -import java.io.IOException; - -/** - * Custom adapter type factory - * Modify the jsonObject before serailaization/deserialization - * @param the type whose json is to be customized for serialization/deserialization - */ -public class NotebookTypeAdapterFactory implements TypeAdapterFactory { - private final Class customizedClass; - - public NotebookTypeAdapterFactory(Class customizedClass) { - this.customizedClass = customizedClass; - } - - @SuppressWarnings("unchecked") - // we use a runtime check to guarantee that 'C' and 'T' are equal - public final TypeAdapter create(Gson gson, TypeToken type) { - return type.getRawType() == customizedClass ? (TypeAdapter) customizeTypeAdapter(gson, - (TypeToken) type) : null; - } - - private TypeAdapter customizeTypeAdapter(Gson gson, TypeToken type) { - final TypeAdapter delegate = gson.getDelegateAdapter(this, type); - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - return new TypeAdapter() { - @Override - public void write(JsonWriter out, C value) throws IOException { - JsonElement tree = delegate.toJsonTree(value); - beforeWrite(value, tree); - elementAdapter.write(out, tree); - } - - @Override - public C read(JsonReader in) throws IOException { - JsonElement tree = elementAdapter.read(in); - afterRead(tree); - return delegate.fromJsonTree(tree); - } - }; - } - - /** - * Override this to change {@code toSerialize} before it is written to the - * outgoing JSON stream. - */ - protected void beforeWrite(C source, JsonElement toSerialize) { - } - - /** - * Override this to change {@code deserialized} before it parsed into the - * application type. - */ - protected void afterRead(JsonElement deserialized) { - } -}