use of org.apache.zeppelin.notebook.repo.NotebookRepo.Revision in project zeppelin by apache.
the class NotebookServer method checkpointNote.
private void checkpointNote(NotebookSocket conn, Notebook notebook, Message fromMessage) throws IOException {
String noteId = (String) fromMessage.get("noteId");
String commitMessage = (String) fromMessage.get("commitMessage");
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
Revision revision = notebook.checkpointNote(noteId, commitMessage, subject);
if (!Revision.isEmpty(revision)) {
List<Revision> revisions = notebook.listRevisionHistory(noteId, subject);
conn.send(serializeMessage(new Message(OP.LIST_REVISION_HISTORY).put("revisionList", revisions)));
} else {
conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", "Couldn't checkpoint note revision: possibly storage doesn't support versioning. " + "Please check the logs for more details.")));
}
}
use of org.apache.zeppelin.notebook.repo.NotebookRepo.Revision in project zeppelin by apache.
the class NotebookServer method listRevisionHistory.
private void listRevisionHistory(NotebookSocket conn, Notebook notebook, Message fromMessage) throws IOException {
String noteId = (String) fromMessage.get("noteId");
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
List<Revision> revisions = notebook.listRevisionHistory(noteId, subject);
conn.send(serializeMessage(new Message(OP.LIST_REVISION_HISTORY).put("revisionList", revisions)));
}
use of org.apache.zeppelin.notebook.repo.NotebookRepo.Revision in project zeppelin by apache.
the class GitNotebookRepoTest method setRevisionTest.
@Test
public void setRevisionTest() throws IOException {
//create repo and check that note doesn't contain revisions
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();
// get current note
Note note = notebookRepo.get(TEST_NOTE_ID, null);
int paragraphCount_1 = note.getParagraphs().size();
LOG.info("initial paragraph count: {}", paragraphCount_1);
// checkpoint revision1
Revision revision1 = notebookRepo.checkpoint(TEST_NOTE_ID, "set revision: first commit", null);
//TODO(khalid): change to EMPTY after rebase
assertThat(revision1).isNotNull();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(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("set revision sample text");
notebookRepo.save(note, null);
int paragraphCount_2 = note.getParagraphs().size();
assertThat(paragraphCount_2).isEqualTo(paragraphCount_1 + 1);
LOG.info("paragraph count after modification: {}", paragraphCount_2);
// checkpoint revision2
Revision revision2 = notebookRepo.checkpoint(TEST_NOTE_ID, "set revision: second commit", null);
//TODO(khalid): change to EMPTY after rebase
assertThat(revision2).isNotNull();
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null).size()).isEqualTo(2);
// set note to revision1
Note returnedNote = notebookRepo.setNoteRevision(note.getId(), revision1.id, null);
assertThat(returnedNote).isNotNull();
assertThat(returnedNote.getParagraphs().size()).isEqualTo(paragraphCount_1);
// check note from repo
Note updatedNote = notebookRepo.get(note.getId(), null);
assertThat(updatedNote).isNotNull();
assertThat(updatedNote.getParagraphs().size()).isEqualTo(paragraphCount_1);
// set back to revision2
returnedNote = notebookRepo.setNoteRevision(note.getId(), revision2.id, null);
assertThat(returnedNote).isNotNull();
assertThat(returnedNote.getParagraphs().size()).isEqualTo(paragraphCount_2);
// check note from repo
updatedNote = notebookRepo.get(note.getId(), null);
assertThat(updatedNote).isNotNull();
assertThat(updatedNote.getParagraphs().size()).isEqualTo(paragraphCount_2);
// try failure case - set to invalid revision
returnedNote = notebookRepo.setNoteRevision(note.getId(), "nonexistent_id", null);
assertThat(returnedNote).isNull();
}
use of org.apache.zeppelin.notebook.repo.NotebookRepo.Revision in project zeppelin by apache.
the class GitNotebookRepoTest method addCheckpointTest.
@Test
public void addCheckpointTest() 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();
notebookRepo.checkpoint(TEST_NOTE_ID, "first commit", null);
List<Revision> notebookHistoryBefore = notebookRepo.revisionHistory(TEST_NOTE_ID, null);
assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null)).isNotEmpty();
int initialCount = notebookHistoryBefore.size();
// add changes to 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 checkpoint test text");
// save and checkpoint note
notebookRepo.save(note, null);
notebookRepo.checkpoint(TEST_NOTE_ID, "second commit", null);
// see if commit is added
List<Revision> notebookHistoryAfter = notebookRepo.revisionHistory(TEST_NOTE_ID, null);
assertThat(notebookHistoryAfter.size()).isEqualTo(initialCount + 1);
}
use of org.apache.zeppelin.notebook.repo.NotebookRepo.Revision 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);
}
Aggregations