Search in sources :

Example 26 with Paragraph

use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.

the class ZeppelinSparkClusterTest method sparkRTest.

@Test
public void sparkRTest() throws IOException {
    // create new note
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    int sparkVersion = getSparkVersionNumber(note);
    if (isSparkR() && sparkVersion >= 14) {
        // sparkr supported from 1.4.0
        // restart spark interpreter
        List<InterpreterSetting> settings = ZeppelinServer.notebook.getBindedInterpreterSettings(note.getId());
        for (InterpreterSetting setting : settings) {
            if (setting.getName().equals("spark")) {
                ZeppelinServer.notebook.getInterpreterSettingManager().restart(setting.getId());
                break;
            }
        }
        String sqlContextName = "sqlContext";
        if (sparkVersion >= 20) {
            sqlContextName = "spark";
        }
        Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
        Map config = p.getConfig();
        config.put("enabled", true);
        p.setConfig(config);
        p.setText("%r localDF <- data.frame(name=c(\"a\", \"b\", \"c\"), age=c(19, 23, 18))\n" + "df <- createDataFrame(" + sqlContextName + ", localDF)\n" + "count(df)");
        p.setAuthenticationInfo(anonymous);
        note.run(p.getId());
        waitForFinish(p);
        System.err.println("sparkRTest=" + p.getResult().message().get(0).getData());
        assertEquals(Status.FINISHED, p.getStatus());
        assertEquals("[1] 3", p.getResult().message().get(0).getData().trim());
    }
    ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
Also used : Note(org.apache.zeppelin.notebook.Note) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Map(java.util.Map) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 27 with Paragraph

use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.

the class ZeppelinSparkClusterTest method basicRDDTransformationAndActionTest.

@Test
public void basicRDDTransformationAndActionTest() throws IOException {
    // create new note
    Note note = ZeppelinServer.notebook.createNote(anonymous);
    // run markdown paragraph, again
    Paragraph p = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    Map config = p.getConfig();
    config.put("enabled", true);
    p.setConfig(config);
    p.setText("%spark print(sc.parallelize(1 to 10).reduce(_ + _))");
    p.setAuthenticationInfo(anonymous);
    note.run(p.getId());
    waitForFinish(p);
    assertEquals(Status.FINISHED, p.getStatus());
    assertEquals("55", 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 28 with Paragraph

use of org.apache.zeppelin.notebook.Paragraph 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();
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepo.Revision) Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 29 with Paragraph

use of org.apache.zeppelin.notebook.Paragraph 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);
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepo.Revision) Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 30 with Paragraph

use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.

the class VFSNotebookRepoTest method testSaveNotebook.

@Test
public void testSaveNotebook() throws IOException, InterruptedException {
    AuthenticationInfo anonymous = new AuthenticationInfo("anonymous");
    Note note = notebook.createNote(anonymous);
    interpreterSettingManager.setInterpreters("user", note.getId(), interpreterSettingManager.getDefaultInterpreterSettingList());
    Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p1.getConfig();
    config.put("enabled", true);
    p1.setConfig(config);
    p1.setText("%mock1 hello world");
    p1.setAuthenticationInfo(anonymous);
    note.run(p1.getId());
    int timeout = 1;
    while (!p1.isTerminated()) {
        Thread.sleep(1000);
        if (timeout++ > 10) {
            break;
        }
    }
    int i = 0;
    int TEST_COUNT = 10;
    while (i++ < TEST_COUNT) {
        p1.setText("%mock1 hello zeppelin");
        new Thread(new NotebookWriter(note)).start();
        p1.setText("%mock1 hello world");
        new Thread(new NotebookWriter(note)).start();
    }
    note.setName("SaveTest");
    notebookRepo.save(note, null);
    assertEquals(note.getName(), "SaveTest");
    notebookRepo.remove(note.getId(), null);
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

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