You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mi...@apache.org on 2016/06/23 04:24:18 UTC
zeppelin git commit: [ZEPPELIN-905] Fix import notebook with error
result
Repository: zeppelin
Updated Branches:
refs/heads/master 85d70579f -> 50db17598
[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 <sa...@gmail.com>
Author: Mina Lee <mi...@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
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/50db1759
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/50db1759
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/50db1759
Branch: refs/heads/master
Commit: 50db17598686fa92925416df1458b3cb3838cd8f
Parents: 85d7057
Author: Kevin Kim <sa...@gmail.com>
Authored: Sat Jun 18 00:38:45 2016 -0700
Committer: Mina Lee <mi...@apache.org>
Committed: Wed Jun 22 21:24:12 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/50db1759/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/50db1759/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 7108bb3..b6c8b29 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
@@ -222,17 +222,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/50db1759/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());