Search in sources :

Example 56 with Paragraph

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);
}
Also used : Note(org.apache.zeppelin.notebook.Note) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 57 with Paragraph

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);
}
Also used : Note(org.apache.zeppelin.notebook.Note) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 58 with Paragraph

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;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) ApplicationState(org.apache.zeppelin.notebook.ApplicationState) Gson(com.google.gson.Gson) IOException(java.io.IOException) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) Date(java.util.Date) Paragraph(org.apache.zeppelin.notebook.Paragraph) FileContent(org.apache.commons.vfs2.FileContent) Note(org.apache.zeppelin.notebook.Note) FileObject(org.apache.commons.vfs2.FileObject)

Example 59 with Paragraph

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();
        ;
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 60 with Paragraph

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;
}
Also used : Paragraph(org.apache.zeppelin.notebook.Paragraph)

Aggregations

Paragraph (org.apache.zeppelin.notebook.Paragraph)75 Note (org.apache.zeppelin.notebook.Note)69 Test (org.junit.Test)40 Map (java.util.Map)30 TypeToken (com.google.gson.reflect.TypeToken)12 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)12 Path (javax.ws.rs.Path)11 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)9 Message (org.apache.zeppelin.notebook.socket.Message)9 Notebook (org.apache.zeppelin.notebook.Notebook)7 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 JsonObject (com.google.gson.JsonObject)4 IOException (java.io.IOException)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4