Savalek commented on a change in pull request #3281: [ZEPPELIN-3943] - Add button "stop notebook execution" URL: https://github.com/apache/zeppelin/pull/3281#discussion_r247873359
########## File path: zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java ########## @@ -340,27 +344,63 @@ public void runAllParagraphs(String noteId, return; } - note.setRunning(true); - try { - for (Map<String, Object> raw : paragraphs) { - String paragraphId = (String) raw.get("id"); - if (paragraphId == null) { - continue; - } - 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. - break; + synchronized (note) { + if (note.isRunning()) { + LOGGER.warn("Can't run note because it already is running"); + return; + } + note.setRunning(true); + } + + noteExecutor.execute(() -> { + try { + for (Map<String, Object> raw : paragraphs) { + String paragraphId = (String) raw.get("id"); + if (paragraphId == null) { + continue; + } + 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. + break; + } } + } catch (IOException e) { + LOGGER.error("Can't run paragraph", e); + } finally { + note.setRunning(false); } - } finally { - note.setRunning(false); + }); + + } + + + public void stopNoteExecution(String noteId, + ServiceContext context, + ServiceCallback<Note> callback) throws IOException { + if (!checkPermission(noteId, Permission.RUNNER, Message.OP.STOP_NOTE_EXECUTION, context, + callback)) { + return; } + + Note note = notebook.getNote(noteId); + if (note == null) { + callback.onFailure(new NoteNotFoundException(noteId), context); + return; + } + + for (Paragraph paragraph : note.getParagraphs()) { + if (paragraph.isRunning()) { + paragraph.abort(); Review comment: @felixcheung, i fixed it. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services