zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mina...@apache.org
Subject zeppelin git commit: [ZEPPELIN-905] Fix import notebook with error result
Date Thu, 23 Jun 2016 04:24:30 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/branch-0.6 0f72c90a7 -> dfe758f1f


[ZEPPELIN-905] Fix import notebook with error result

### What is this PR for?
This PR is fixing import/clone notebook with error result. This PR adds test based on #933.
> Note: This issue is one of the [blockers](https://issues.apache.org/jira/browse/ZEPPELIN-889)
of 0.6.0 release so should be merged into branch-0.6 before release.

### What type of PR is it?
Bug Fix

### What is the Jira issue?
[ZEPPELIN-905](https://issues.apache.org/jira/browse/ZEPPELIN-905)

### How should this be tested?
When you try to import or clone notebook with error result, it should work.

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Kevin Kim <sangwookim.me@gmail.com>
Author: Mina Lee <minalee@apache.org>

Closes #1043 from minahlee/ZEPPELIN-905 and squashes the following commits:

69b8c02 [Mina Lee] Add test for clone notebook with String type result
e7af919 [Kevin Kim] stylish code
7bf5d01 [Kevin Kim] log info -> warn, add message
d4f6699 [Kevin Kim] log exception
32949bc [Kevin Kim] trigger CI build
803e08a [Kevin Kim] revert implementation
c13293f [Kevin Kim] fix test, better implementation
1e45a9e [Kevin Kim] [ZEPPELIN-905] add test
a4188be [Kevin Kim] [ZEPPELIN-905] fix failed notebook import bug

(cherry picked from commit 50db17598686fa92925416df1458b3cb3838cd8f)
Signed-off-by: Mina Lee <minalee@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/dfe758f1
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/dfe758f1
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/dfe758f1

Branch: refs/heads/branch-0.6
Commit: dfe758f1f759fe91499c6b3d827b252774b1a83f
Parents: 0f72c90
Author: Kevin Kim <sangwookim.me@gmail.com>
Authored: Sat Jun 18 00:38:45 2016 -0700
Committer: Mina Lee <minalee@apache.org>
Committed: Wed Jun 22 21:24:23 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/zeppelin/scheduler/Job.java |  2 +-
 .../java/org/apache/zeppelin/notebook/Note.java | 16 ++++--
 .../apache/zeppelin/notebook/NotebookTest.java  | 52 +++++++++++++++++++-
 3 files changed, 63 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/dfe758f1/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
----------------------------------------------------------------------
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
index 00df966..2dc1719 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
@@ -255,7 +255,7 @@ public abstract class Job {
     return dateFinished;
   }
 
-  protected void setResult(Object result) {
+  public void setResult(Object result) {
     this.result = result;
   }
 }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/dfe758f1/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 60ee1a0..ad6e92d 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
@@ -207,17 +207,23 @@ public class Note implements Serializable, JobListener {
     Map<String, Object> config = new HashMap<>(srcParagraph.getConfig());
     Map<String, Object> param = new HashMap<>(srcParagraph.settings.getParams());
     Map<String, Input> form = new HashMap<>(srcParagraph.settings.getForms());
-    Gson gson = new Gson();
-    InterpreterResult result = gson.fromJson(
-        gson.toJson(srcParagraph.getReturn()),
-        InterpreterResult.class);
 
     newParagraph.setConfig(config);
     newParagraph.settings.setParams(param);
     newParagraph.settings.setForms(form);
     newParagraph.setText(srcParagraph.getText());
     newParagraph.setTitle(srcParagraph.getTitle());
-    newParagraph.setReturn(result, null);
+
+    try {
+      Gson gson = new Gson();
+      String resultJson = gson.toJson(srcParagraph.getReturn());
+      InterpreterResult result = gson.fromJson(resultJson, InterpreterResult.class);
+      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());
+    }
 
     synchronized (paragraphs) {
       paragraphs.add(newParagraph);

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/dfe758f1/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
----------------------------------------------------------------------
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 d4ca87d..575bb85 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
@@ -39,7 +39,6 @@ import org.apache.zeppelin.resource.LocalResourcePool;
 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.scheduler.SchedulerFactory;
 import org.apache.zeppelin.search.SearchService;
 import org.apache.zeppelin.user.Credentials;
@@ -324,6 +323,33 @@ public class NotebookTest implements JobListenerFactory{
   }
 
   @Test
+  public void testExportAndImportNote() throws IOException, CloneNotSupportedException,
+          InterruptedException {
+    Note note = notebook.createNote();
+    note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList());
+
+    final Paragraph p = note.addParagraph();
+    String simpleText = "hello world";
+    p.setText(simpleText);
+
+    note.runAll();
+    while (p.isTerminated() == false || p.getResult() == null) {
+      Thread.yield();
+    }
+
+    String exportedNoteJson = notebook.exportNote(note.getId());
+
+    Note importedNote = notebook.importNote(exportedNoteJson, "Title");
+
+    Paragraph p2 = importedNote.getParagraphs().get(0);
+
+    // Test
+    assertEquals(p.getId(), p2.getId());
+    assertEquals(p.text, p2.text);
+    assertEquals(p.getResult().message(), p2.getResult().message());
+  }
+
+  @Test
   public void testCloneNote() throws IOException, CloneNotSupportedException,
       InterruptedException {
     Note note = notebook.createNote(null);
@@ -346,6 +372,30 @@ public class NotebookTest implements JobListenerFactory{
   }
 
   @Test
+  public void testCloneNoteWithExceptionResult() throws IOException, CloneNotSupportedException,
+      InterruptedException {
+    Note note = notebook.createNote();
+    note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList());
+
+    final Paragraph p = note.addParagraph();
+    p.setText("hello world");
+    note.runAll();
+    while (p.isTerminated() == false || p.getResult() == null) {
+      Thread.yield();
+    }
+    // Force paragraph to have String type object
+    p.setResult("Exception");
+
+    Note cloneNote = notebook.cloneNote(note.getId(), "clone note with Exception result");
+    Paragraph cp = cloneNote.paragraphs.get(0);
+
+    // Keep same ParagraphID
+    assertEquals(cp.getId(), p.getId());
+    assertEquals(cp.text, p.text);
+    assertNull(cp.getResult());
+  }
+
+  @Test
   public void testResourceRemovealOnParagraphNoteRemove() throws IOException {
     Note note = notebook.createNote(null);
     note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList());


Mime
View raw message