use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookRestApiTest method testRunParagraphJob.
@Test
public void testRunParagraphJob() throws IOException {
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
note1.addParagraph(AuthenticationInfo.ANONYMOUS);
Paragraph p = note1.addParagraph(AuthenticationInfo.ANONYMOUS);
// run blank paragraph
PostMethod post = httpPost("/notebook/job/" + 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();
assertEquals(p.getStatus(), Job.Status.FINISHED);
// run non-blank paragraph
p.setText("test");
post = httpPost("/notebook/job/" + note1.getId() + "/" + p.getId(), "");
assertThat(post, isAllowed());
resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
assertNotEquals(p.getStatus(), Job.Status.READY);
//cleanup
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class ZeppelinRestApiTest method testJobs.
@Test
public void testJobs() throws InterruptedException, IOException {
// create a note and a paragraph
Note note = ZeppelinServer.notebook.createNote(anonymous);
note.setName("note for run test");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
paragraph.setText("%md This is test paragraph.");
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
note.runAll();
// wait until job is finished or timeout.
int timeout = 1;
while (!paragraph.isTerminated()) {
Thread.sleep(1000);
if (timeout++ > 10) {
LOG.info("testNoteJobs timeout job.");
break;
}
}
String jsonRequest = "{\"cron\":\"* * * * * ?\" }";
// right cron expression but not exist note.
PostMethod postCron = httpPost("/notebook/cron/notexistnote", jsonRequest);
assertThat("", postCron, isNotFound());
postCron.releaseConnection();
// right cron expression.
postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest);
assertThat("", postCron, isAllowed());
postCron.releaseConnection();
Thread.sleep(1000);
// wrong cron expression.
jsonRequest = "{\"cron\":\"a * * * * ?\" }";
postCron = httpPost("/notebook/cron/" + note.getId(), jsonRequest);
assertThat("", postCron, isBadRequest());
postCron.releaseConnection();
Thread.sleep(1000);
// remove cron job.
DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId());
assertThat("", deleteCron, isAllowed());
deleteCron.releaseConnection();
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class ZeppelinRestApiTest method testDeleteParagraph.
@Test
public void testDeleteParagraph() throws IOException {
Note note = ZeppelinServer.notebook.createNote(anonymous);
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
p.setTitle("title1");
p.setText("text1");
note.persist(anonymous);
DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId());
assertThat("Test delete method: ", delete, isAllowed());
delete.releaseConnection();
Note retrNote = ZeppelinServer.notebook.getNote(note.getId());
Paragraph retrParagrah = retrNote.getParagraph(p.getId());
assertNull("paragraph should be deleted", retrParagrah);
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class ZeppelinRestApiTest method testGetNoteJob.
@Test
public void testGetNoteJob() throws IOException, InterruptedException {
LOG.info("testGetNoteJob");
// Create note to run test.
Note note = ZeppelinServer.notebook.createNote(anonymous);
assertNotNull("can't create new note", note);
note.setName("note for run test");
Paragraph paragraph = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);
paragraph.setText("%sh sleep 1");
paragraph.setAuthenticationInfo(anonymous);
note.persist(anonymous);
String noteId = note.getId();
note.runAll();
// wait until paragraph gets started
while (!paragraph.getStatus().isRunning()) {
Thread.sleep(100);
}
// assume that status of the paragraph is running
GetMethod get = httpGet("/notebook/job/" + noteId);
assertThat("test get note job: ", get, isAllowed());
String responseBody = get.getResponseBodyAsString();
get.releaseConnection();
LOG.info("test get note job: \n" + responseBody);
Map<String, Object> resp = gson.fromJson(responseBody, new TypeToken<Map<String, Object>>() {
}.getType());
List<Map<String, Object>> paragraphs = (List<Map<String, Object>>) resp.get("body");
assertEquals(1, paragraphs.size());
assertTrue(paragraphs.get(0).containsKey("progress"));
int progress = Integer.parseInt((String) paragraphs.get(0).get("progress"));
assertTrue(progress >= 0 && progress <= 100);
// wait until job is finished or timeout.
int timeout = 1;
while (!paragraph.isTerminated()) {
Thread.sleep(100);
if (timeout++ > 10) {
LOG.info("testGetNoteJob timeout job.");
break;
}
}
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class ZeppelinRestApiTest method testGetParagraph.
@Test
public void testGetParagraph() throws IOException {
Note note = ZeppelinServer.notebook.createNote(anonymous);
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
p.setTitle("hello");
p.setText("world");
note.persist(anonymous);
GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p.getId());
LOG.info("testGetParagraph response\n" + get.getResponseBodyAsString());
assertThat("Test get method: ", get, isAllowed());
get.releaseConnection();
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
assertNotNull(resp);
assertEquals("OK", resp.get("status"));
Map<String, Object> body = (Map<String, Object>) resp.get("body");
assertEquals(p.getId(), body.get("id"));
assertEquals("hello", body.get("title"));
assertEquals("world", body.get("text"));
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Aggregations