use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class RecoveryTest method testRecovery.
@Test
public void testRecovery() throws Exception {
LOG.info("Test testRecovery");
String note1Id = null;
try {
note1Id = notebook.createNote("note1", anonymous);
notebook.processNote(note1Id, note1 -> {
// run python interpreter and create new variable `user`
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%python user='abc'");
return null;
});
CloseableHttpResponse post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertThat(post, isAllowed());
Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals("OK", resp.get("status"));
post.close();
notebook.processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
assertEquals(Job.Status.FINISHED, p1.getStatus());
TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous);
return null;
});
// shutdown zeppelin and restart it
shutDown();
startUp(RecoveryTest.class.getSimpleName(), false);
// run the paragraph again, but change the text to print variable `user`
Thread.sleep(10 * 1000);
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
p1 = note1.getParagraph(p1.getId());
p1.setText("%python print(user)");
return null;
});
post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertEquals("OK", resp.get("status"));
post.close();
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
assertEquals(Job.Status.FINISHED, p1.getStatus());
assertEquals("abc\n", p1.getReturn().message().get(0).getData());
return null;
});
} catch (Exception e) {
LOG.error(e.toString(), e);
throw e;
} finally {
if (null != note1Id) {
TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
}
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class RecoveryTest method testRecovery_Finished_Paragraph_python.
@Test
public void testRecovery_Finished_Paragraph_python() throws Exception {
LOG.info("Test testRecovery_Finished_Paragraph_python");
String note1Id = null;
try {
InterpreterSettingManager interpreterSettingManager = TestUtils.getInstance(InterpreterSettingManager.class);
InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("python");
interpreterSetting.setProperty("zeppelin.python.useIPython", "false");
interpreterSetting.setProperty("zeppelin.interpreter.result.cache", "100");
note1Id = TestUtils.getInstance(Notebook.class).createNote("note4", AuthenticationInfo.ANONYMOUS);
// run paragraph async, print 'hello' after 10 seconds
Paragraph p1 = TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
return note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
});
p1.setText("%python import time\n" + "for i in range(1, 10):\n" + " time.sleep(1)\n" + " print(i)");
CloseableHttpResponse post = httpPost("/notebook/job/" + note1Id + "/" + p1.getId(), "");
assertThat(post, isAllowed());
post.close();
// wait until paragraph is running
while (p1.getStatus() != Job.Status.RUNNING) {
Thread.sleep(1000);
}
// shutdown zeppelin and restart it
shutDown();
// sleep 15 seconds to make sure the paragraph is finished
Thread.sleep(15 * 1000);
startUp(RecoveryTest.class.getSimpleName(), false);
// sleep 10 seconds to make sure recovering is finished
Thread.sleep(10 * 1000);
assertEquals(Job.Status.FINISHED, p1.getStatus());
assertEquals("1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n" + "7\n" + "8\n" + "9\n", p1.getReturn().message().get(0).getData());
} catch (Exception e) {
LOG.error(e.toString(), e);
throw e;
} finally {
if (null != note1Id) {
TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
}
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class RecoveryTest method testRecovery_3.
@Test
public void testRecovery_3() throws Exception {
LOG.info("Test testRecovery_3");
String note1Id = null;
try {
note1Id = TestUtils.getInstance(Notebook.class).createNote("note3", AuthenticationInfo.ANONYMOUS);
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
// run python interpreter and create new variable `user`
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%python user='abc'");
return null;
});
CloseableHttpResponse post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertThat(post, isAllowed());
Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals("OK", resp.get("status"));
post.close();
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
assertEquals(Job.Status.FINISHED, p1.getStatus());
TestUtils.getInstance(Notebook.class).saveNote(note1, AuthenticationInfo.ANONYMOUS);
return null;
});
// shutdown zeppelin and restart it
shutDown();
StopInterpreter.main(new String[] {});
startUp(RecoveryTest.class.getSimpleName(), false);
Thread.sleep(5 * 1000);
// run the paragraph again, but change the text to print variable `user`.
// can not recover the python interpreter, because it has been shutdown.
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
p1.setText("%python print(user)");
return null;
});
post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertEquals("OK", resp.get("status"));
post.close();
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
assertEquals(Job.Status.ERROR, p1.getStatus());
return null;
});
} catch (Exception e) {
LOG.error(e.toString(), e);
throw e;
} finally {
if (null != note1Id) {
TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
}
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class ZeppelinRestApiTest method testRunParagraphWithParams.
@Test
public void testRunParagraphWithParams() throws Exception {
LOG.info("testRunParagraphWithParams");
String noteId = null;
try {
// Create note to run test.
noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testRunParagraphWithParams", anonymous);
// use write lock because name is overwritten
String paragraphId = 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("%spark\nval param = z.input(\"param\").toString\nprintln(param)");
TestUtils.getInstance(Notebook.class).saveNote(note, anonymous);
return paragraph.getId();
});
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
try {
note.runAll(anonymous, true, false, new HashMap<>());
} catch (Exception e) {
fail();
}
return null;
});
// Call Run paragraph REST API
CloseableHttpResponse postParagraph = httpPost("/notebook/job/" + noteId + "/" + paragraphId, "{\"params\": {\"param\": \"hello\", \"param2\": \"world\"}}");
assertThat("test paragraph run:", postParagraph, isAllowed());
postParagraph.close();
Thread.sleep(1000);
TestUtils.getInstance(Notebook.class).processNote(noteId, retrNote -> {
Paragraph retrParagraph = retrNote.getParagraph(paragraphId);
Map<String, Object> params = retrParagraph.settings.getParams();
assertEquals("hello", params.get("param"));
assertEquals("world", params.get("param2"));
return null;
});
} finally {
// cleanup
if (null != noteId) {
TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
}
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class ZeppelinRestApiTest method testDeleteNote.
private void testDeleteNote(String noteId) throws IOException {
CloseableHttpResponse delete = httpDelete(("/notebook/" + noteId));
LOG.info("testDeleteNote delete response\n" + EntityUtils.toString(delete.getEntity(), StandardCharsets.UTF_8));
assertThat("Test delete method:", delete, isAllowed());
delete.close();
// make sure note is deleted
if (!noteId.isEmpty()) {
TestUtils.getInstance(Notebook.class).processNote(noteId, deletedNote -> {
assertNull("Deleted note should be null", deletedNote);
return null;
});
}
}
Aggregations