use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class ZeppelinSparkClusterTest method zRunTest.
@Test
public void zRunTest() throws IOException {
// create new note
Note note = ZeppelinServer.notebook.createNote(anonymous);
Paragraph p0 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config0 = p0.getConfig();
config0.put("enabled", true);
p0.setConfig(config0);
p0.setText("%spark z.run(1)");
p0.setAuthenticationInfo(anonymous);
Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config1 = p1.getConfig();
config1.put("enabled", true);
p1.setConfig(config1);
p1.setText("%spark val a=10");
p1.setAuthenticationInfo(anonymous);
Paragraph p2 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config2 = p2.getConfig();
config2.put("enabled", true);
p2.setConfig(config2);
p2.setText("%spark print(a)");
p2.setAuthenticationInfo(anonymous);
note.run(p0.getId());
waitForFinish(p0);
assertEquals(Status.FINISHED, p0.getStatus());
// z.run is not blocking call. So p1 may not be finished when p0 is done.
waitForFinish(p1);
note.run(p2.getId());
waitForFinish(p2);
assertEquals(Status.FINISHED, p2.getStatus());
assertEquals("10", p2.getResult().message().get(0).getData());
Paragraph p3 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config3 = p3.getConfig();
config3.put("enabled", true);
p3.setConfig(config3);
p3.setText("%spark println(new java.util.Date())");
p3.setAuthenticationInfo(anonymous);
p0.setText(String.format("%%spark z.runNote(\"%s\")", note.getId()));
note.run(p0.getId());
waitForFinish(p0);
waitForFinish(p1);
waitForFinish(p2);
waitForFinish(p3);
assertEquals(Status.FINISHED, p3.getStatus());
String p3result = p3.getResult().message().get(0).getData();
assertNotEquals(null, p3result);
assertNotEquals("", p3result);
p0.setText(String.format("%%spark z.run(\"%s\", \"%s\")", note.getId(), p3.getId()));
p3.setText("%%spark println(\"END\")");
note.run(p0.getId());
waitForFinish(p0);
waitForFinish(p3);
assertNotEquals(p3result, p3.getResult().message());
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class ZeppelinSparkClusterTest method scalaOutputTest.
@Test
public void scalaOutputTest() throws IOException {
// create new note
Note note = ZeppelinServer.notebook.createNote(anonymous);
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
Map config = p.getConfig();
config.put("enabled", true);
p.setConfig(config);
p.setText("%spark import java.util.Date\n" + "import java.net.URL\n" + "println(\"hello\")\n");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
waitForFinish(p);
assertEquals(Status.FINISHED, p.getStatus());
assertEquals("import java.util.Date\n" + "import java.net.URL\n" + "hello\n", p.getResult().message().get(0).getData());
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class VFSNotebookRepo method getNote.
private Note getNote(FileObject noteDir) throws IOException {
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD);
if (!noteJson.exists()) {
throw new IOException(noteJson.getName().toString() + " not found");
}
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
FileContent content = noteJson.getContent();
InputStream ins = content.getInputStream();
String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
ins.close();
Note note = gson.fromJson(json, Note.class);
for (Paragraph p : note.getParagraphs()) {
if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
p.setStatus(Status.ABORT);
}
List<ApplicationState> appStates = p.getAllApplicationStates();
if (appStates != null) {
for (ApplicationState app : appStates) {
if (app.getStatus() != ApplicationState.Status.ERROR) {
app.setStatus(ApplicationState.Status.UNLOADED);
}
}
}
}
return note;
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class LuceneSearchTest method indexParagraphUpdatedOnNoteSave.
@Test
public void indexParagraphUpdatedOnNoteSave() throws IOException {
//given: total 2 notebooks, 3 paragraphs
Note note1 = newNoteWithParagraph("Notebook1", "test");
Note note2 = newNoteWithParagraphs("Notebook2", "not test", "not test at all");
noteSearchService.addIndexDocs(Arrays.asList(note1, note2));
assertThat(resultForQuery("test").size()).isEqualTo(3);
//when
Paragraph p1 = note1.getLastParagraph();
p1.setText("no no no");
note1.persist(anonymous);
//then
assertThat(resultForQuery("Notebook1").size()).isEqualTo(1);
List<Map<String, String>> results = resultForQuery("test");
assertThat(results).isNotEmpty();
assertThat(results.size()).isEqualTo(2);
//does not include Notebook1's paragraph any more
for (Map<String, String> result : results) {
assertThat(result.get("id").startsWith(note1.getId())).isFalse();
;
}
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class LuceneSearchTest method addParagraphWithText.
private Paragraph addParagraphWithText(Note note, String text) {
Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
p.setText(text);
return p;
}
Aggregations