You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2017/07/19 07:28:04 UTC

zeppelin git commit: [ZEPPELIN-2758]. NumberFormatException on importing notebook

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 <zj...@apache.org>

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 <zj...@apache.org>
Authored: Sat Jul 15 14:21:15 2017 +0800
Committer: Jeff Zhang <zj...@apache.org>
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 <C> the type whose json is to be customized for serialization/deserialization
- */
-public class NotebookTypeAdapterFactory<C> implements TypeAdapterFactory {
-  private final Class<C> customizedClass;
-
-  public NotebookTypeAdapterFactory(Class<C> customizedClass) {
-    this.customizedClass = customizedClass;
-  }
-
-  @SuppressWarnings("unchecked")
-  // we use a runtime check to guarantee that 'C' and 'T' are equal
-  public final <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
-    return type.getRawType() == customizedClass ? (TypeAdapter<T>) customizeTypeAdapter(gson,
-        (TypeToken<C>) type) : null;
-  }
-
-  private TypeAdapter<C> customizeTypeAdapter(Gson gson, TypeToken<C> type) {
-    final TypeAdapter<C> delegate = gson.getDelegateAdapter(this, type);
-    final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
-    return new TypeAdapter<C>() {
-      @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>(Paragraph.class) {
-        @Override
-        protected void beforeWrite(Paragraph source, JsonElement toSerialize) {
-          Map<String, ParagraphRuntimeInfo> 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>(Paragraph.class) {
-        @Override
-        protected void beforeWrite(Paragraph source, JsonElement toSerialize) {
-          Map<String, ParagraphRuntimeInfo> 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<String, ParagraphRuntimeInfo> 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 <C> the type whose json is to be customized for serialization/deserialization
- */
-public class NotebookTypeAdapterFactory<C> implements TypeAdapterFactory {
-  private final Class<C> customizedClass;
-
-  public NotebookTypeAdapterFactory(Class<C> customizedClass) {
-    this.customizedClass = customizedClass;
-  }
-
-  @SuppressWarnings("unchecked")
-  // we use a runtime check to guarantee that 'C' and 'T' are equal
-  public final <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
-    return type.getRawType() == customizedClass ? (TypeAdapter<T>) customizeTypeAdapter(gson,
-        (TypeToken<C>) type) : null;
-  }
-
-  private TypeAdapter<C> customizeTypeAdapter(Gson gson, TypeToken<C> type) {
-    final TypeAdapter<C> delegate = gson.getDelegateAdapter(this, type);
-    final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
-    return new TypeAdapter<C>() {
-      @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) {
-  }
-}