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 2020/03/03 09:58:14 UTC

[zeppelin] branch master updated: [ZEPPELIN-4661]. Fail to run whole note

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 1617fe5  [ZEPPELIN-4661]. Fail to run whole note
1617fe5 is described below

commit 1617fe5d652ff4eed3fe5a53c56b467e18f0c7e4
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Sun Mar 1 21:53:18 2020 +0800

    [ZEPPELIN-4661]. Fail to run whole note
    
    ### What is this PR for?
    
    This is to fix the regression issue caused by ZEPPELIN-4661. The root cause is that in the frontend we use `paragraph` to represent the script text while in the backend we use `text`, so that converting between frontend data to backend class `Paragraph` will cause this kind of error.
    
    ### What type of PR is it?
    [Bug Fix ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-4661
    
    ### How should this be tested?
    * CI pass 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 #3672 from zjffdu/ZEPPELIN-4661 and squashes the following commits:
    
    c0e6446a3 [Jeff Zhang] [ZEPPELIN-4661]. Fail to run whole note
---
 .../apache/zeppelin/service/NotebookService.java   | 55 +++++++++++++---------
 .../zeppelin/service/NotebookServiceTest.java      | 15 +-----
 2 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java b/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
index 99ed6bb..f7b3ab6 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
@@ -86,7 +86,6 @@ public class NotebookService {
   private Notebook notebook;
   private AuthorizationService authorizationService;
   private SchedulerService schedulerService;
-  private Gson gson = new Gson();
 
   @Inject
   public NotebookService(
@@ -293,6 +292,7 @@ public class NotebookService {
                               ServiceContext context,
                               ServiceCallback<Paragraph> callback) throws IOException {
 
+    LOGGER.info("Start to run paragraph: " + paragraphId + " of note: " + noteId);
     if (!checkPermission(noteId, Permission.RUNNER, Message.OP.RUN_PARAGRAPH, context, callback)) {
       return false;
     }
@@ -355,16 +355,16 @@ public class NotebookService {
    * When list of paragraphs provided from argument is null, list of paragraphs stored in the Note will be used.
    *
    * @param noteId
-   * @param paragraphs list of paragraphs to run. List of paragraph stored in the Note will be used when null.
+   * @param paragraphs list of paragraphs to run (passed from frontend). Run note directly when it is null.
    * @param context
    * @param callback
    * @return true when all paragraphs successfully run. false when any paragraph fails.
    * @throws IOException
    */
   public boolean runAllParagraphs(String noteId,
-                               List<Map<String, Object>> paragraphs,
-                               ServiceContext context,
-                               ServiceCallback<Paragraph> callback) throws IOException {
+                                  List<Map<String, Object>> paragraphs,
+                                  ServiceContext context,
+                                  ServiceCallback<Paragraph> callback) throws IOException {
     if (!checkPermission(noteId, Permission.RUNNER, Message.OP.RUN_ALL_PARAGRAPHS, context,
         callback)) {
       return false;
@@ -376,25 +376,38 @@ public class NotebookService {
       return false;
     }
 
-    if (paragraphs == null) {
-      paragraphs = gson.fromJson(gson.toJson(note.getParagraphs()), new TypeToken<List>(){}.getType());
-    }
-
     note.setRunning(true);
     try {
-      for (Map<String, Object> raw : paragraphs) {
-        String paragraphId = (String) raw.get("id");
-        if (paragraphId == null) {
-          continue;
+      if (paragraphs != null) {
+        // run note via the data passed from frontend
+        for (Map<String, Object> raw : paragraphs) {
+          String paragraphId = (String) raw.get("id");
+          if (paragraphId == null) {
+            LOGGER.warn("No id found in paragraph json: " + raw);
+            continue;
+          }
+          try {
+            String text = (String) raw.get("paragraph");
+            String title = (String) raw.get("title");
+            Map<String, Object> params = (Map<String, Object>) raw.get("params");
+            Map<String, Object> config = (Map<String, Object>) raw.get("config");
+
+            if (!runParagraph(noteId, paragraphId, title, text, params, config, false, true,
+                    context, callback)) {
+              // stop execution when one paragraph fails.
+              return false;
+            }
+          } catch (Exception e) {
+            throw new IOException("Fail to run paragraph json: " + raw);
+          }
         }
-        String text = (String) raw.get("text");
-        String title = (String) raw.get("title");
-        Map<String, Object> params = (Map<String, Object>) raw.get("params");
-        Map<String, Object> config = (Map<String, Object>) raw.get("config");
-
-        if (!runParagraph(noteId, paragraphId, title, text, params, config, false, true,
-                context, callback)) {
-          // stop execution when one paragraph fails.
+      } else {
+        try {
+          // run note directly when parameter `paragraphs` is null.
+          note.runAll(context.getAutheInfo(), true);
+          return true;
+        } catch (Exception e) {
+          LOGGER.warn("Fail to run note: " + note.getName(), e);
           return false;
         }
       }
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
index e56b58a..9fefd57 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
@@ -359,23 +359,12 @@ public class NotebookServiceTest {
     verify(callback).onSuccess(p, context);
     assertEquals(2, p.getConfig().size());
 
-    // run all paragraphs
-    reset(callback);
-    String textBefore = p.getText();
-    notebookService.runAllParagraphs(
-            note1.getId(),
-            gson.fromJson(gson.toJson(note1.getParagraphs()), new TypeToken<List>(){}.getType()),
-            context, callback);
-    verify(callback, times(2)).onSuccess(any(), any());
-    assertEquals(textBefore, p.getText());
-
     // run all paragraphs, with null paragraph list provided
     reset(callback);
-    notebookService.runAllParagraphs(
+    assertTrue(notebookService.runAllParagraphs(
             note1.getId(),
             null,
-            context, callback);
-    verify(callback, times(2)).onSuccess(any(), any());
+            context, callback));
 
     reset(callback);
     runStatus = notebookService.runParagraph(note1.getId(), p.getId(), "my_title", "invalid_code",