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

zeppelin git commit: [Zeppelin-2964] Stop execution on schedule if the note has been moved to the trash

Repository: zeppelin
Updated Branches:
  refs/heads/master 851dcb1a3 -> dd1be03de


[Zeppelin-2964] Stop execution on schedule if the note has been moved to the trash

### What is this PR for?
When you put the note (or folder) in the trash, the note continues to run on schedule.
This PR fixes this. Now when you put the note into the trash, the task is removed, and when you restore the note, it runs again.

### What type of PR is it?
Improvement

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

### How should this be tested?
- Create a scheduled launch for the note.
- Put the note in the trash.
- Look through the logs.
- Note must stop running.
- Restore the note from the trash.
- Running on a schedule should continue again.

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

Author: tinkoff-dwh <ti...@gmail.com>

Closes #2697 from tinkoff-dwh/ZEPPELIN-2964 and squashes the following commits:

b12ae4c [tinkoff-dwh] [ZEPPELIN-2964] add if statement
3db4a8e [tinkoff-dwh] [ZEPPELIN-2964] restore cron together note/folder
3906b9e [tinkoff-dwh] [ZEPPELIN-2964] drop cron when note placed in the trash


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

Branch: refs/heads/master
Commit: dd1be03dee9428ade92b8fd47d148c2325179d19
Parents: 851dcb1
Author: tinkoff-dwh <ti...@gmail.com>
Authored: Tue Dec 5 15:23:43 2017 +0300
Committer: Felix Cheung <fe...@apache.org>
Committed: Thu Dec 28 00:40:06 2017 -0800

----------------------------------------------------------------------
 .../apache/zeppelin/socket/NotebookServer.java  | 31 ++++++++++++++++++++
 .../src/app/notebook/notebook-actionBar.html    |  2 +-
 .../org/apache/zeppelin/notebook/Notebook.java  |  2 +-
 3 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/dd1be03d/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 184735a..56aa50a 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
@@ -1108,6 +1108,13 @@ public class NotebookServer extends WebSocketServlet
     }
 
     Note note = notebook.getNote(noteId);
+
+    // drop cron
+    Map<String, Object> config = note.getConfig();
+    if (config.get("cron") != null) {
+      notebook.removeCron(note.getId());
+    }
+
     if (note != null && !note.isTrash()){
       fromMessage.put("name", Folder.TRASH_FOLDER_ID + "/" + note.getName());
       renameNote(conn, userAndRoles, notebook, fromMessage, "move");
@@ -1132,6 +1139,14 @@ public class NotebookServer extends WebSocketServlet
         trashFolderId += Folder.TRASH_FOLDER_CONFLICT_INFIX + formatter.print(currentDate);
       }
 
+      List<Note> noteList = folder.getNotesRecursively();
+      for (Note note: noteList) {
+        Map<String, Object> config = note.getConfig();
+        if (config.get("cron") != null) {
+          notebook.removeCron(note.getId());
+        }
+      }
+
       fromMessage.put("name", trashFolderId);
       renameFolder(conn, userAndRoles, notebook, fromMessage, "move");
     }
@@ -1147,6 +1162,13 @@ public class NotebookServer extends WebSocketServlet
     }
 
     Note note = notebook.getNote(noteId);
+
+    //restore cron
+    Map<String, Object> config = note.getConfig();
+    if (config.get("cron") != null) {
+      notebook.refreshCron(note.getId());
+    }
+
     if (note != null && note.isTrash()) {
       fromMessage.put("name", note.getName().replaceFirst(Folder.TRASH_FOLDER_ID + "/", ""));
       renameNote(conn, userAndRoles, notebook, fromMessage, "restore");
@@ -1166,6 +1188,15 @@ public class NotebookServer extends WebSocketServlet
     if (folder != null && folder.isTrash()) {
       String restoreName = folder.getId().replaceFirst(Folder.TRASH_FOLDER_ID + "/", "").trim();
 
+      //restore cron for each paragraph
+      List<Note> noteList = folder.getNotesRecursively();
+      for (Note note : noteList) {
+        Map<String, Object> config = note.getConfig();
+        if (config.get("cron") != null) {
+          notebook.refreshCron(note.getId());
+        }
+      }
+
       // if the folder had conflict when it had moved to trash before
       Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
       Matcher m = p.matcher(restoreName);

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/dd1be03d/zeppelin-web/src/app/notebook/notebook-actionBar.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/notebook-actionBar.html b/zeppelin-web/src/app/notebook/notebook-actionBar.html
index f1d1dd5..573be00 100644
--- a/zeppelin-web/src/app/notebook/notebook-actionBar.html
+++ b/zeppelin-web/src/app/notebook/notebook-actionBar.html
@@ -255,7 +255,7 @@ limitations under the License.
              data-toggle="dropdown"
              ng-class="{ 'btn-info' : note.config.cron, 'btn-danger' : note.info.cron, 'btn-default' : !note.config.cron}"
              tooltip-placement="bottom" uib-tooltip="Run scheduler"
-             ng-disabled="revisionView">
+             ng-disabled="revisionView || isTrash(note)">
           <span class="fa fa-clock-o"></span> {{getCronOptionNameFromValue(note.config.cron)}}
         </div>
         <ul class="dropdown-menu" role="menu" style="width:300px">

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/dd1be03d/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
----------------------------------------------------------------------
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 d68cd4b..ff0ac62 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
@@ -973,7 +973,7 @@ public class Notebook implements NoteEventListener {
     }
   }
 
-  private void removeCron(String id) {
+  public void removeCron(String id) {
     try {
       quartzSched.deleteJob(new JobKey(id, "note"));
     } catch (SchedulerException e) {