This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/master by this push:
     new b451b20  [ZEPPELIN-4961]. Allow import note to set new notepath
b451b20 is described below

commit b451b200d9f58f3e43bc15254bed32029cb4117d
Author: Jeff Zhang <[email protected]>
AuthorDate: Mon Jul 20 16:07:53 2020 +0800

    [ZEPPELIN-4961]. Allow import note to set new notepath
    
    ### What is this PR for?
    
    This is to allow user to import note with a parameter to specifiy a new 
note path.
    
    ### What type of PR is it?
    [Refactoring]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/browse/ZEPPELIN-4961
    
    ### How should this be tested?
    * CI pass
    
    ### 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 <[email protected]>
    
    Closes #3868 from zjffdu/ZEPPELIN-4961 and squashes the following commits:
    
    cdf463b44 [Jeff Zhang] [ZEPPELIN-4961]. Allow import note to set new 
notepath
---
 .../java/org/apache/zeppelin/rest/NotebookRestApi.java     | 13 +++++++++----
 .../apache/zeppelin/rest/message/ParagraphJobStatus.java   | 10 ++++++++++
 .../java/org/apache/zeppelin/notebook/NoteManager.java     | 10 +++++-----
 .../main/java/org/apache/zeppelin/notebook/Notebook.java   | 14 +++++++++++++-
 4 files changed, 37 insertions(+), 10 deletions(-)

diff --git 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
index 13c1b99..e6dcfee 100644
--- 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
+++ 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
@@ -40,6 +40,7 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.zeppelin.annotation.ZeppelinApi;
 import org.apache.zeppelin.conf.ZeppelinConfiguration;
 import org.apache.zeppelin.interpreter.InterpreterResult;
@@ -361,10 +362,14 @@ public class NotebookRestApi extends AbstractRestApi {
   @POST
   @Path("import")
   @ZeppelinApi
-  public Response importNote(String noteJson) throws IOException {
-    Note note = notebookService.importNote(null, noteJson, getServiceContext(),
-        new RestServiceCallback());
-    return new JsonResponse<>(Status.OK, "", note.getId()).build();
+  public Response importNote(@QueryParam("notePath") String notePath, String 
noteJson) throws IOException {
+    try {
+      Note note = notebookService.importNote(notePath, noteJson, 
getServiceContext(),
+              new RestServiceCallback());
+      return new JsonResponse<>(Status.OK, "", note.getId()).build();
+    } catch (IOException e) {
+      return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, 
e.getMessage()).build();
+    }
   }
 
   /**
diff --git 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/ParagraphJobStatus.java
 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/ParagraphJobStatus.java
index 8249524..c9caf62 100644
--- 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/ParagraphJobStatus.java
+++ 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/ParagraphJobStatus.java
@@ -17,11 +17,14 @@
 
 package org.apache.zeppelin.rest.message;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.zeppelin.notebook.Paragraph;
+import org.apache.zeppelin.scheduler.Job;
 
 public class ParagraphJobStatus {
   private String id;
   private String status;
+  private String errorMessage;
   private String started;
   private String finished;
   private String progress;
@@ -39,6 +42,13 @@ public class ParagraphJobStatus {
       this.progress = String.valueOf(p.progress());
     } else if (p.isTerminated()){
       this.progress = String.valueOf(100);
+      if (p.getStatus() == Job.Status.ERROR) {
+        if (!StringUtils.isBlank(p.getErrorMessage())) {
+          this.errorMessage = p.getErrorMessage();
+        } else {
+          this.errorMessage = p.getReturn().toString();
+        }
+      }
     } else {
       this.progress = String.valueOf(0);
     }
diff --git 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
index ca50618..d487de7 100644
--- 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
+++ 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
@@ -282,13 +282,13 @@ public class NoteManager {
    * @return return null if not found on NotebookRepo.
    * @throws IOException
    */
-  public Note getNote(String noteId, boolean forceLoad) throws IOException {
+  public Note getNote(String noteId, boolean reload) throws IOException {
     String notePath = this.notesInfo.get(noteId);
     if (notePath == null) {
       return null;
     }
     NoteNode noteNode = getNoteNode(notePath);
-    return noteNode.getNote(forceLoad);
+    return noteNode.getNote(reload);
   }
 
   /**
@@ -535,7 +535,7 @@ public class NoteManager {
     }
 
     public synchronized Note getNote() throws IOException {
-        return getNote(true);
+        return getNote(false);
     }
 
     /**
@@ -544,8 +544,8 @@ public class NoteManager {
      * @return
      * @throws IOException
      */
-    public synchronized Note getNote(boolean forceLoad) throws IOException {
-      if (!note.isLoaded() && forceLoad) {
+    public synchronized Note getNote(boolean reload) throws IOException {
+      if (!note.isLoaded() || reload) {
         note = notebookRepo.get(note.getId(), note.getPath(), 
AuthenticationInfo.ANONYMOUS);
         if (parent.toString().equals("/")) {
           note.setPath("/" + note.getName());
diff --git 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
index 25685a3..3ccb10d 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
@@ -301,6 +301,7 @@ public class Notebook {
     for (Paragraph p : paragraphs) {
       newNote.addCloneParagraph(p, subject);
     }
+    noteManager.saveNote(newNote, subject);
     return newNote;
   }
 
@@ -342,7 +343,18 @@ public class Notebook {
    * @throws IOException when fail to get it from NotebookRepo.
    */
   public Note getNote(String noteId) throws IOException {
-    Note note = noteManager.getNote(noteId);
+    return getNote(noteId, false);
+  }
+
+  /**
+   * Get note from NotebookRepo and also initialize it with other properties 
that is not
+   * persistent in NotebookRepo, such as paragraphJobListener.
+   * @param noteId
+   * @return null if note not found.
+   * @throws IOException when fail to get it from NotebookRepo.
+   */
+  public Note getNote(String noteId, boolean reload) throws IOException {
+    Note note = noteManager.getNote(noteId, reload);
     if (note == null) {
       return null;
     }

Reply via email to