use of org.apache.zeppelin.rest.message.NoteJobStatus in project zeppelin by apache.
the class ZeppelinRestApiTest method testRegressionZEPPELIN_527.
@Test
public void testRegressionZEPPELIN_527() throws Exception {
String noteId = null;
try {
noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testRegressionZEPPELIN_527", anonymous);
// use write lock because name is overwritten
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
note.setName("note for run test");
Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)");
return null;
});
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
try {
note.runAll(AuthenticationInfo.ANONYMOUS, true, false, new HashMap<>());
TestUtils.getInstance(Notebook.class).saveNote(note, anonymous);
} catch (Exception e) {
fail();
}
return null;
});
CloseableHttpResponse getNoteJobs = httpGet("/notebook/job/" + noteId);
assertThat("test note jobs run:", getNoteJobs, isAllowed());
Map<String, Object> resp = gson.fromJson(EntityUtils.toString(getNoteJobs.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
}.getType());
NoteJobStatus noteJobStatus = NoteJobStatus.fromJson(gson.toJson(resp.get("body")));
assertNotNull(noteJobStatus.getParagraphJobStatusList().get(0).getStarted());
assertNotNull(noteJobStatus.getParagraphJobStatusList().get(0).getFinished());
getNoteJobs.close();
} finally {
// cleanup
if (null != noteId) {
TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
}
}
}
use of org.apache.zeppelin.rest.message.NoteJobStatus in project zeppelin by apache.
the class ZeppelinRestApiTest method testGetNoteJob.
@Test
public void testGetNoteJob() throws Exception {
LOG.info("testGetNoteJob");
String noteId = null;
try {
// Create note to run test.
noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testGetNoteJob", anonymous);
// use write lock because name is overwritten
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
assertNotNull("can't create new note", note);
note.setName("note for run test");
Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Map<String, Object> config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
paragraph.setText("%sh sleep 1");
paragraph.setAuthenticationInfo(anonymous);
TestUtils.getInstance(Notebook.class).saveNote(note, anonymous);
return null;
});
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
try {
note.runAll(anonymous, true, false, new HashMap<>());
} catch (Exception e) {
fail();
}
return null;
});
// assume that status of the paragraph is running
CloseableHttpResponse get = httpGet("/notebook/job/" + noteId);
assertThat("test get note job: ", get, isAllowed());
String responseBody = EntityUtils.toString(get.getEntity(), StandardCharsets.UTF_8);
get.close();
LOG.info("test get note job: \n" + responseBody);
Map<String, Object> resp = gson.fromJson(responseBody, new TypeToken<Map<String, Object>>() {
}.getType());
NoteJobStatus noteJobStatus = NoteJobStatus.fromJson(gson.toJson(resp.get("body")));
assertEquals(1, noteJobStatus.getParagraphJobStatusList().size());
int progress = Integer.parseInt(noteJobStatus.getParagraphJobStatusList().get(0).getProgress());
assertTrue(progress >= 0 && progress <= 100);
// wait until job is finished or timeout.
int timeout = 1;
boolean terminated = TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraph(0).isTerminated());
while (!terminated) {
Thread.sleep(100);
terminated = TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraph(0).isTerminated());
if (timeout++ > 10) {
LOG.info("testGetNoteJob timeout job.");
break;
}
}
} finally {
// cleanup
if (null != noteId) {
TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
}
}
}
Aggregations