NotebookRestApi extends AbstractRestApi { @POST @Path("run/{noteId}/{paragraphId}") @ZeppelinApi public Response runParagraphSynchronously(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, @QueryParam("sessionId") String sessionId, String message) throws IOException, IllegalArgumentException { LOGGER.info("Run paragraph synchronously {} {} {}", noteId, paragraphId, message); Note note = notebook.getNote(noteId); checkIfNoteIsNotNull(note); Paragraph paragraph = note.getParagraph(paragraphId); checkIfParagraphIsNotNull(paragraph); Map<String, Object> params = new HashMap<>(); if (!StringUtils.isEmpty(message)) { ParametersRequest request = ParametersRequest.fromJson(message); params = request.getParams(); } if (notebookService.runParagraph(noteId, paragraphId, paragraph.getTitle(), paragraph.getText(), params, new HashMap<>(), sessionId, false, true, getServiceContext(), new RestServiceCallback<>())) { note = notebookService.getNote(noteId, getServiceContext(), new RestServiceCallback<>()); Paragraph p = note.getParagraph(paragraphId); InterpreterResult result = p.getReturn(); return new JsonResponse<>(Status.OK, result).build(); } else { return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, "Fail to run paragraph").build(); } } @Inject  NotebookRestApi(
      Notebook notebook,
      NotebookServer notebookServer,
      NotebookService notebookService,
      SearchService search,
      AuthorizationService authorizationService,
      ZeppelinConfiguration zConf,
      AuthenticationService authenticationService,
      JobManagerService jobManagerService,
      SchedulerService schedulerService); @GET @Path("{noteId}/permissions") @ZeppelinApi Response getNotePermissions(@PathParam("noteId") String noteId); @PUT @Path("{noteId}/permissions") @ZeppelinApi Response putNotePermissions(@PathParam("noteId") String noteId, String req); @GET @ZeppelinApi Response getNoteList(); @GET @Path("{noteId}") @ZeppelinApi Response getNote(@PathParam("noteId") String noteId); @GET @Path("export/{noteId}") @ZeppelinApi Response exportNote(@PathParam("noteId") String noteId); @POST @Path("import") @ZeppelinApi Response importNote(@QueryParam("notePath") String notePath, String noteJson); @POST @ZeppelinApi Response createNote(String message); @DELETE @Path("{noteId}") @ZeppelinApi Response deleteNote(@PathParam("noteId") String noteId); @POST @Path("{noteId}") @ZeppelinApi Response cloneNote(@PathParam("noteId") String noteId, String message); @PUT @Path("{noteId}/rename") @ZeppelinApi Response renameNote(@PathParam("noteId") String noteId,
                             String message); @POST @Path("{noteId}/paragraph") @ZeppelinApi Response insertParagraph(@PathParam("noteId") String noteId, String message); @GET @Path("{noteId}/paragraph/{paragraphId}") @ZeppelinApi Response getParagraph(@PathParam("noteId") String noteId,
                               @PathParam("paragraphId") String paragraphId); @PUT @Path("{noteId}/paragraph/{paragraphId}") @ZeppelinApi Response updateParagraph(@PathParam("noteId") String noteId,
                                  @PathParam("paragraphId") String paragraphId,
                                  String message); @PUT @Path("{noteId}/paragraph/{paragraphId}/config") @ZeppelinApi Response updateParagraphConfig(@PathParam("noteId") String noteId,
                                        @PathParam("paragraphId") String paragraphId,
                                        String message); @POST @Path("{noteId}/paragraph/{paragraphId}/move/{newIndex}") @ZeppelinApi Response moveParagraph(@PathParam("noteId") String noteId,
                                @PathParam("paragraphId") String paragraphId,
                                @PathParam("newIndex") String newIndex); @DELETE @Path("{noteId}/paragraph/{paragraphId}") @ZeppelinApi Response deleteParagraph(@PathParam("noteId") String noteId,
                                  @PathParam("paragraphId") String paragraphId); @POST @Path("{noteId}/paragraph/next") Response nextSessionParagraph(@PathParam("noteId") String noteId,
                                       @QueryParam("maxParagraph") int maxParagraph); @PUT @Path("{noteId}/clear") @ZeppelinApi Response clearAllParagraphOutput(@PathParam("noteId") String noteId); @POST @Path("job/{noteId}") @ZeppelinApi Response runNoteJobs(@PathParam("noteId") String noteId,
                              @QueryParam("blocking") Boolean blocking,
                              @QueryParam("isolated") Boolean isolated,
                              String message); @DELETE @Path("job/{noteId}") @ZeppelinApi Response stopNoteJobs(@PathParam("noteId") String noteId); @GET @Path("job/{noteId}") @ZeppelinApi Response getNoteJobStatus(@PathParam("noteId") String noteId); @GET @Path("job/{noteId}/{paragraphId}") @ZeppelinApi Response getNoteParagraphJobStatus(@PathParam("noteId") String noteId,
                                            @PathParam("paragraphId") String paragraphId); @POST @Path("job/{noteId}/{paragraphId}") @ZeppelinApi Response runParagraph(@PathParam("noteId") String noteId,
                               @PathParam("paragraphId") String paragraphId,
                               @QueryParam("sessionId") String sessionId,
                               String message); @POST @Path("run/{noteId}/{paragraphId}") @ZeppelinApi Response runParagraphSynchronously(@PathParam("noteId") String noteId,
                                            @PathParam("paragraphId") String paragraphId,
                                            @QueryParam("sessionId") String sessionId,
                                            String message); @DELETE @Path("job/{noteId}/{paragraphId}") @ZeppelinApi Response cancelParagraph(@PathParam("noteId") String noteId,
                                  @PathParam("paragraphId") String paragraphId); @POST @Path("cron/{noteId}") @ZeppelinApi Response registerCronJob(@PathParam("noteId") String noteId, String message); @DELETE @Path("cron/{noteId}") @ZeppelinApi Response removeCronJob(@PathParam("noteId") String noteId); @GET @Path("cron/{noteId}") @ZeppelinApi Response getCronJob(@PathParam("noteId") String noteId); @GET @Path("jobmanager/") @ZeppelinApi Response getJobListforNote(); @GET @Path("jobmanager/{lastUpdateUnixtime}/") @ZeppelinApi Response getUpdatedJobListforNote(@PathParam("lastUpdateUnixtime") long lastUpdateUnixTime); @GET @Path("search") @ZeppelinApi Response search(@QueryParam("q") String queryTerm);  }
@Test public void testRunParagraphSynchronously() throws IOException { LOG.info("Running testRunParagraphSynchronously"); Note note1 = null; try { note1 = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); String title = "title"; String text = "%sh\n sleep 1"; p.setTitle(title); p.setText(text); PostMethod post = httpPost("/notebook/run/" + note1.getId() + "/" + p.getId(), ""); assertThat(post, isAllowed()); Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); assertEquals(resp.get("status"), "OK"); post.releaseConnection(); assertNotEquals(p.getStatus(), Job.Status.READY); assertEquals(title, p.getTitle()); assertEquals(text, p.getText()); text = "%sh\n invalid_cmd"; p.setTitle(title); p.setText(text); post = httpPost("/notebook/run/" + note1.getId() + "/" + p.getId(), ""); assertEquals(200, post.getStatusCode()); resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); assertEquals("OK", resp.get("status")); StringMap stringMap = (StringMap) resp.get("body"); assertEquals("ERROR", stringMap.get("code")); List<StringMap> interpreterResults = (List<StringMap>) stringMap.get("msg"); assertTrue(interpreterResults.get(0).toString(), interpreterResults.get(0).get("data").toString().contains("invalid_cmd: command not found")); post.releaseConnection(); assertNotEquals(p.getStatus(), Job.Status.READY); assertEquals(title, p.getTitle()); assertEquals(text, p.getText()); } finally { if (null != note1) { TestUtils.getInstance(Notebook.class).removeNote(note1, anonymous); } } }