use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class GitNotebookRepoTest method getRevisionTest.
@Test
public void getRevisionTest() throws IOException {
// initial checks
notebookRepo = new GitNotebookRepo(conf);
assertThat(notebookRepo.list(null)).isNotEmpty();
assertThat(containsNote(notebookRepo.list(null), TEST_NOTE_ID)).isTrue();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null)).isEmpty();
// add first checkpoint
Revision revision_1 = notebookRepo.checkpoint(TEST_NOTE_ID, "first commit", null);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(1);
int paragraphCount_1 = notebookRepo.get(TEST_NOTE_ID, null).getParagraphs().size();
// add paragraph and save
Note note = notebookRepo.get(TEST_NOTE_ID, null);
Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map<String, Object> config = p1.getConfig();
config.put("enabled", true);
p1.setConfig(config);
p1.setText("checkpoint test text");
notebookRepo.save(note, null);
// second checkpoint
notebookRepo.checkpoint(TEST_NOTE_ID, "second commit", null);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(2);
int paragraphCount_2 = notebookRepo.get(TEST_NOTE_ID, null).getParagraphs().size();
assertThat(paragraphCount_2).isEqualTo(paragraphCount_1 + 1);
// get note from revision 1
Note noteRevision_1 = notebookRepo.get(TEST_NOTE_ID, revision_1.id, null);
assertThat(noteRevision_1.getParagraphs().size()).isEqualTo(paragraphCount_1);
// get current note
note = notebookRepo.get(TEST_NOTE_ID, null);
assertThat(note.getParagraphs().size()).isEqualTo(paragraphCount_2);
// add one more paragraph and save
Paragraph p2 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
config.put("enabled", false);
p2.setConfig(config);
p2.setText("get revision when modified note test text");
notebookRepo.save(note, null);
note = notebookRepo.get(TEST_NOTE_ID, null);
int paragraphCount_3 = note.getParagraphs().size();
assertThat(paragraphCount_3).isEqualTo(paragraphCount_2 + 1);
// get revision 1 again
noteRevision_1 = notebookRepo.get(TEST_NOTE_ID, revision_1.id, null);
assertThat(noteRevision_1.getParagraphs().size()).isEqualTo(paragraphCount_1);
// check that note is unchanged
note = notebookRepo.get(TEST_NOTE_ID, null);
assertThat(note.getParagraphs().size()).isEqualTo(paragraphCount_3);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class GitNotebookRepoTest method showNotebookHistoryMultipleNotesTest.
@Test
public void showNotebookHistoryMultipleNotesTest() throws IOException {
//initial checks
notebookRepo = new GitNotebookRepo(conf);
assertThat(notebookRepo.list(null)).isNotEmpty();
assertThat(containsNote(notebookRepo.list(null), TEST_NOTE_ID)).isTrue();
assertThat(containsNote(notebookRepo.list(null), TEST_NOTE_ID2)).isTrue();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null)).isEmpty();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID2, null)).isEmpty();
//add commit to both notes
notebookRepo.checkpoint(TEST_NOTE_ID, "first commit, note1", null);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(1);
notebookRepo.checkpoint(TEST_NOTE_ID2, "first commit, note2", null);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID2, null).size()).isEqualTo(1);
//modify, save and checkpoint first note
Note note = notebookRepo.get(TEST_NOTE_ID, null);
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map<String, Object> config = p.getConfig();
config.put("enabled", true);
p.setConfig(config);
p.setText("%md note1 test text");
notebookRepo.save(note, null);
assertThat(notebookRepo.checkpoint(TEST_NOTE_ID, "second commit, note1", null)).isNotNull();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(2);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID2, null).size()).isEqualTo(1);
assertThat(notebookRepo.checkpoint(TEST_NOTE_ID2, "first commit, note2", null)).isEqualTo(Revision.EMPTY);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID2, null).size()).isEqualTo(1);
//modify, save and checkpoint second note
note = notebookRepo.get(TEST_NOTE_ID2, null);
p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
config = p.getConfig();
config.put("enabled", false);
p.setConfig(config);
p.setText("%md note2 test text");
notebookRepo.save(note, null);
assertThat(notebookRepo.checkpoint(TEST_NOTE_ID2, "second commit, note2", null)).isNotNull();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(2);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID2, null).size()).isEqualTo(2);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class GitNotebookRepoTest method getRevisionFailTest.
@Test
public void getRevisionFailTest() throws IOException {
// initial checks
notebookRepo = new GitNotebookRepo(conf);
assertThat(notebookRepo.list(null)).isNotEmpty();
assertThat(containsNote(notebookRepo.list(null), TEST_NOTE_ID)).isTrue();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null)).isEmpty();
// add first checkpoint
Revision revision_1 = notebookRepo.checkpoint(TEST_NOTE_ID, "first commit", null);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(1);
int paragraphCount_1 = notebookRepo.get(TEST_NOTE_ID, null).getParagraphs().size();
// get current note
Note note = notebookRepo.get(TEST_NOTE_ID, null);
assertThat(note.getParagraphs().size()).isEqualTo(paragraphCount_1);
// add one more paragraph and save
Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map<String, Object> config = p1.getConfig();
config.put("enabled", true);
p1.setConfig(config);
p1.setText("get revision when modified note test text");
notebookRepo.save(note, null);
int paragraphCount_2 = note.getParagraphs().size();
// get note from revision 1
Note noteRevision_1 = notebookRepo.get(TEST_NOTE_ID, revision_1.id, null);
assertThat(noteRevision_1.getParagraphs().size()).isEqualTo(paragraphCount_1);
// get current note
note = notebookRepo.get(TEST_NOTE_ID, null);
assertThat(note.getParagraphs().size()).isEqualTo(paragraphCount_2);
// test for absent revision
Revision absentRevision = new Revision("absentId", StringUtils.EMPTY, 0);
note = notebookRepo.get(TEST_NOTE_ID, absentRevision.id, null);
assertThat(note).isNull();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method onRemoteRunParagraph.
@Override
public void onRemoteRunParagraph(String noteId, String paragraphId) throws Exception {
Notebook notebookIns = notebook();
try {
if (notebookIns == null) {
throw new Exception("onRemoteRunParagraph notebook instance is null");
}
Note noteIns = notebookIns.getNote(noteId);
if (noteIns == null) {
throw new Exception(String.format("Can't found note id %s", noteId));
}
Paragraph paragraph = noteIns.getParagraph(paragraphId);
if (paragraph == null) {
throw new Exception(String.format("Can't found paragraph %s %s", noteId, paragraphId));
}
Set<String> userAndRoles = Sets.newHashSet();
userAndRoles.add(SecurityUtils.getPrincipal());
userAndRoles.addAll(SecurityUtils.getRoles());
if (!notebookIns.getNotebookAuthorization().hasWriteAuthorization(userAndRoles, noteId)) {
throw new ForbiddenException(String.format("can't execute note %s", noteId));
}
AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
paragraph.setAuthenticationInfo(subject);
noteIns.run(paragraphId);
} catch (Exception e) {
throw e;
}
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class InterpreterRestApiTest method testInterpreterRestart.
@Test
public void testInterpreterRestart() throws IOException, InterruptedException {
// when: create new note
Note note = ZeppelinServer.notebook.createNote(anonymous);
note.addParagraph(AuthenticationInfo.ANONYMOUS);
Paragraph p = note.getLastParagraph();
Map config = p.getConfig();
config.put("enabled", true);
// when: run markdown paragraph
p.setConfig(config);
p.setText("%md markdown");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
while (p.getStatus() != Status.FINISHED) {
Thread.sleep(100);
}
assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown"));
// when: restart interpreter
for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) {
if (setting.getName().equals("md")) {
// call restart interpreter API
PutMethod put = httpPut("/interpreter/setting/restart/" + setting.getId(), "");
assertThat("test interpreter restart:", put, isAllowed());
put.releaseConnection();
break;
}
}
// when: run markdown paragraph, again
p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
p.setConfig(config);
p.setText("%md markdown restarted");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
while (p.getStatus() != Status.FINISHED) {
Thread.sleep(100);
}
// then
assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown restarted"));
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Aggregations