Skip to content

Commit

Permalink
[Zeppelin-2964] Stop execution on schedule if the note has been moved…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>

Closes apache#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
  • Loading branch information
tinkoff-dwh authored and Felix Cheung committed Dec 28, 2017
1 parent 851dcb1 commit dd1be03
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,13 @@ private void moveNoteToTrash(NotebookSocket conn, HashSet<String> userAndRoles,
}

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");
Expand All @@ -1132,6 +1139,14 @@ private void moveFolderToTrash(NotebookSocket conn, HashSet<String> userAndRoles
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");
}
Expand All @@ -1147,6 +1162,13 @@ private void restoreNote(NotebookSocket conn, HashSet<String> userAndRoles,
}

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");
Expand All @@ -1166,6 +1188,15 @@ private void restoreFolder(NotebookSocket conn, HashSet<String> userAndRoles,
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);
Expand Down
2 changes: 1 addition & 1 deletion zeppelin-web/src/app/notebook/notebook-actionBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ <h3>
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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ public void refreshCron(String id) {
}
}

private void removeCron(String id) {
public void removeCron(String id) {
try {
quartzSched.deleteJob(new JobKey(id, "note"));
} catch (SchedulerException e) {
Expand Down

0 comments on commit dd1be03

Please sign in to comment.