-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ZEPPELIN-699] Add new synchronous paragraph run REST API #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,7 +567,7 @@ public Response getNoteParagraphJobStatus(@PathParam("notebookId") String notebo | |
| } | ||
|
|
||
| /** | ||
| * Run paragraph job REST API | ||
| * Run asynchronously paragraph job REST API | ||
| * | ||
| * @param message - JSON with params if user wants to update dynamic form's value | ||
| * null, empty string, empty json if user doesn't want to update | ||
|
|
@@ -580,7 +580,7 @@ public Response getNoteParagraphJobStatus(@PathParam("notebookId") String notebo | |
| public Response runParagraph(@PathParam("notebookId") String notebookId, | ||
| @PathParam("paragraphId") String paragraphId, String message) | ||
| throws IOException, IllegalArgumentException { | ||
| LOG.info("run paragraph job {} {} {}", notebookId, paragraphId, message); | ||
| LOG.info("run paragraph job asynchronously {} {} {}", notebookId, paragraphId, message); | ||
|
|
||
| Note note = notebook.getNote(notebookId); | ||
| if (note == null) { | ||
|
|
@@ -593,22 +593,60 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, | |
| } | ||
|
|
||
| // handle params if presented | ||
| if (!StringUtils.isEmpty(message)) { | ||
| RunParagraphWithParametersRequest request = | ||
| gson.fromJson(message, RunParagraphWithParametersRequest.class); | ||
| Map<String, Object> paramsForUpdating = request.getParams(); | ||
| if (paramsForUpdating != null) { | ||
| paragraph.settings.getParams().putAll(paramsForUpdating); | ||
| AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); | ||
| note.setLastReplName(paragraph.getId()); | ||
| note.persist(subject); | ||
| } | ||
| } | ||
| handleParagraphParams(message, note, paragraph); | ||
|
|
||
| note.run(paragraph.getId()); | ||
| return new JsonResponse<>(Status.OK).build(); | ||
| } | ||
|
|
||
| /** | ||
| * Run synchronously a paragraph REST API | ||
| * | ||
| * @param noteId - noteId | ||
| * @param paragraphId - paragraphId | ||
| * @param message - JSON with params if user wants to update dynamic form's value | ||
| * null, empty string, empty json if user doesn't want to update | ||
| * | ||
| * @return JSON with status.OK | ||
| * @throws IOException, IllegalArgumentException | ||
| */ | ||
| @POST | ||
| @Path("run/{notebookId}/{paragraphId}") | ||
| @ZeppelinApi | ||
| public Response runParagraphSynchronously(@PathParam("notebookId") String noteId, | ||
| @PathParam("paragraphId") String paragraphId, | ||
| String message) throws | ||
| IOException, IllegalArgumentException { | ||
| LOG.info("run paragraph synchronously {} {} {}", noteId, paragraphId, message); | ||
|
|
||
| Note note = notebook.getNote(noteId); | ||
| if (note == null) { | ||
| return new JsonResponse<>(Status.NOT_FOUND, "note not found.").build(); | ||
| } | ||
|
|
||
| Paragraph paragraph = note.getParagraph(paragraphId); | ||
| if (paragraph == null) { | ||
| return new JsonResponse<>(Status.NOT_FOUND, "paragraph not found.").build(); | ||
| } | ||
|
|
||
| // handle params if presented | ||
| handleParagraphParams(message, note, paragraph); | ||
|
|
||
| if (paragraph.getListener() == null) { | ||
| note.initializeJobListenerForParagraph(paragraph); | ||
| } | ||
|
|
||
| paragraph.run(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. paragraph supposed to not run in this way.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @doanduyhai do you plan to address this issue? |
||
|
|
||
| final InterpreterResult result = paragraph.getResult(); | ||
|
|
||
| if (result.code() == InterpreterResult.Code.SUCCESS) { | ||
| return new JsonResponse<>(Status.OK, result).build(); | ||
| } else { | ||
| return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, result).build(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of hardcoding to INTERNAL_SERVER_ERROR, is there a way to map result.code() ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the
Success case is handle in the In any case, since we return the complete Example: |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Stop(delete) paragraph job REST API | ||
| * | ||
|
|
@@ -800,4 +838,21 @@ public Response search(@QueryParam("q") String queryTerm) { | |
| return new JsonResponse<>(Status.OK, notebooksFound).build(); | ||
| } | ||
|
|
||
|
|
||
| private void handleParagraphParams(String message, Note note, Paragraph paragraph) | ||
| throws IOException { | ||
| // handle params if presented | ||
| if (!StringUtils.isEmpty(message)) { | ||
| RunParagraphWithParametersRequest request = | ||
| gson.fromJson(message, RunParagraphWithParametersRequest.class); | ||
| Map<String, Object> paramsForUpdating = request.getParams(); | ||
| if (paramsForUpdating != null) { | ||
| paragraph.settings.getParams().putAll(paramsForUpdating); | ||
| AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); | ||
| note.setLastReplName(paragraph.getId()); | ||
| note.persist(subject); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please fix the extra space for this and next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I'm referring to whitespaces in/around
<td> Fail code</td>,<td> 500 </td>or<td> sample JSON input (optional, only needed when if you want to update dynamic form's value) </td>- are they intentional?