Search in sources :

Example 6 with InterpreterSetting

use of org.apache.zeppelin.interpreter.InterpreterSetting in project zeppelin by apache.

the class NotebookServer method onMetaInfosReceived.

@Override
public void onMetaInfosReceived(String settingId, Map<String, String> metaInfos) {
    InterpreterSetting interpreterSetting = notebook().getInterpreterSettingManager().get(settingId);
    interpreterSetting.setInfos(metaInfos);
}
Also used : InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting)

Example 7 with InterpreterSetting

use of org.apache.zeppelin.interpreter.InterpreterSetting in project zeppelin by apache.

the class NotebookServer method onUpdate.

@Override
public void onUpdate(String interpreterGroupId, AngularObject object) {
    Notebook notebook = notebook();
    if (notebook == null) {
        return;
    }
    List<Note> notes = notebook.getAllNotes();
    for (Note note : notes) {
        if (object.getNoteId() != null && !note.getId().equals(object.getNoteId())) {
            continue;
        }
        List<InterpreterSetting> intpSettings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
        if (intpSettings.isEmpty()) {
            continue;
        }
        broadcast(note.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", object).put("interpreterGroupId", interpreterGroupId).put("noteId", note.getId()).put("paragraphId", object.getParagraphId()));
    }
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting)

Example 8 with InterpreterSetting

use of org.apache.zeppelin.interpreter.InterpreterSetting in project zeppelin by apache.

the class NotebookServerTest method testCreateNoteWithDefaultInterpreterId.

@Test
public void testCreateNoteWithDefaultInterpreterId() throws IOException {
    // create two sockets and open it
    NotebookSocket sock1 = createWebSocket();
    NotebookSocket sock2 = createWebSocket();
    assertEquals(sock1, sock1);
    assertNotEquals(sock1, sock2);
    notebookServer.onOpen(sock1);
    notebookServer.onOpen(sock2);
    String noteName = "Note with millis " + System.currentTimeMillis();
    String defaultInterpreterId = "";
    List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().get();
    if (settings.size() > 1) {
        defaultInterpreterId = settings.get(1).getId();
    }
    // create note from sock1
    notebookServer.onMessage(sock1, gson.toJson(new Message(OP.NEW_NOTE).put("name", noteName).put("defaultInterpreterId", defaultInterpreterId)));
    // expect the events are broadcasted properly
    verify(sock1, times(2)).send(anyString());
    Note createdNote = null;
    for (Note note : notebook.getAllNotes()) {
        if (note.getName().equals(noteName)) {
            createdNote = note;
            break;
        }
    }
    if (settings.size() > 1) {
        assertEquals(notebook.getInterpreterSettingManager().getDefaultInterpreterSetting(createdNote.getId()).getId(), defaultInterpreterId);
    }
    notebook.removeNote(createdNote.getId(), anonymous);
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Note(org.apache.zeppelin.notebook.Note) Test(org.junit.Test)

Example 9 with InterpreterSetting

use of org.apache.zeppelin.interpreter.InterpreterSetting 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 10 with InterpreterSetting

use of org.apache.zeppelin.interpreter.InterpreterSetting in project zeppelin by apache.

the class NotebookServerTest method testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent.

@Test
public void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() throws IOException {
    // create a notebook
    Note note1 = notebook.createNote(anonymous);
    // get reference to interpreterGroup
    InterpreterGroup interpreterGroup = null;
    List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId());
    for (InterpreterSetting setting : settings) {
        if (setting.getName().equals("md")) {
            interpreterGroup = setting.getInterpreterGroup("anonymous", "sharedProcess");
            break;
        }
    }
    // start interpreter process
    Paragraph p1 = note1.addParagraph(AuthenticationInfo.ANONYMOUS);
    p1.setText("%md start remote interpreter process");
    p1.setAuthenticationInfo(anonymous);
    note1.run(p1.getId());
    // add angularObject
    interpreterGroup.getAngularObjectRegistry().add("object1", "value1", note1.getId(), null);
    // create two sockets and open it
    NotebookSocket sock1 = createWebSocket();
    NotebookSocket sock2 = createWebSocket();
    assertEquals(sock1, sock1);
    assertNotEquals(sock1, sock2);
    notebookServer.onOpen(sock1);
    notebookServer.onOpen(sock2);
    // getNote, getAngularObject
    verify(sock1, times(0)).send(anyString());
    // open the same notebook from sockets
    notebookServer.onMessage(sock1, gson.toJson(new Message(OP.GET_NOTE).put("id", note1.getId())));
    notebookServer.onMessage(sock2, gson.toJson(new Message(OP.GET_NOTE).put("id", note1.getId())));
    reset(sock1);
    reset(sock2);
    // update object from sock1
    notebookServer.onMessage(sock1, gson.toJson(new Message(OP.ANGULAR_OBJECT_UPDATED).put("noteId", note1.getId()).put("name", "object1").put("value", "value1").put("interpreterGroupId", interpreterGroup.getId())));
    // expect object is broadcasted except for where the update is created
    verify(sock1, times(0)).send(anyString());
    verify(sock2, times(1)).send(anyString());
    notebook.removeNote(note1.getId(), anonymous);
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Aggregations

InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)21 Note (org.apache.zeppelin.notebook.Note)9 Test (org.junit.Test)9 Message (org.apache.zeppelin.notebook.socket.Message)7 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)6 Paragraph (org.apache.zeppelin.notebook.Paragraph)6 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)5 Map (java.util.Map)4 Path (javax.ws.rs.Path)4 JsonObject (com.google.gson.JsonObject)3 PutMethod (org.apache.commons.httpclient.methods.PutMethod)3 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)3 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)3 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)3 JsonResponse (org.apache.zeppelin.server.JsonResponse)3 JsonElement (com.google.gson.JsonElement)2 File (java.io.File)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 PUT (javax.ws.rs.PUT)2