Search in sources :

Example 16 with Message

use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.

the class NotebookServer method sendNote.

private void sendNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    LOG.info("New operation from {} : {} : {} : {} : {}", conn.getRequest().getRemoteAddr(), conn.getRequest().getRemotePort(), fromMessage.principal, fromMessage.op, fromMessage.get("id"));
    String noteId = (String) fromMessage.get("id");
    if (noteId == null) {
        return;
    }
    String user = fromMessage.principal;
    Note note = notebook.getNote(noteId);
    if (note != null) {
        if (!hasParagraphReaderPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "read")) {
            return;
        }
        addConnectionToNote(note.getId(), conn);
        if (note.isPersonalizedMode()) {
            note = note.getUserNote(user);
        }
        conn.send(serializeMessage(new Message(OP.NOTE).put("note", note)));
        sendAllAngularObjects(note, user, conn);
    } else {
        conn.send(serializeMessage(new Message(OP.NOTE).put("note", null)));
    }
}
Also used : 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)

Example 17 with Message

use of org.apache.zeppelin.notebook.socket.Message 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 18 with Message

use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.

the class NotebookServer method sendHomeNote.

private void sendHomeNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    String noteId = notebook.getConf().getString(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN);
    String user = fromMessage.principal;
    Note note = null;
    if (noteId != null) {
        note = notebook.getNote(noteId);
    }
    if (note != null) {
        if (!hasParagraphReaderPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "read")) {
            return;
        }
        addConnectionToNote(note.getId(), conn);
        conn.send(serializeMessage(new Message(OP.NOTE).put("note", note)));
        sendAllAngularObjects(note, user, conn);
    } else {
        removeConnectionFromAllNote(conn);
        conn.send(serializeMessage(new Message(OP.NOTE).put("note", null)));
    }
}
Also used : 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)

Example 19 with Message

use of org.apache.zeppelin.notebook.socket.Message 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 20 with Message

use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.

the class NotebookServerTest method bindAngularObjectToRemoteForParagraphs.

@Test
public void bindAngularObjectToRemoteForParagraphs() throws Exception {
    //Given
    final String varName = "name";
    final String value = "DuyHai DOAN";
    final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_BIND).put("noteId", "noteId").put("name", varName).put("value", value).put("paragraphId", "paragraphId");
    final NotebookServer server = new NotebookServer();
    final Notebook notebook = mock(Notebook.class);
    final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
    when(notebook.getNote("noteId")).thenReturn(note);
    final Paragraph paragraph = mock(Paragraph.class, RETURNS_DEEP_STUBS);
    when(note.getParagraph("paragraphId")).thenReturn(paragraph);
    final RemoteAngularObjectRegistry mdRegistry = mock(RemoteAngularObjectRegistry.class);
    final InterpreterGroup mdGroup = new InterpreterGroup("mdGroup");
    mdGroup.setAngularObjectRegistry(mdRegistry);
    when(paragraph.getCurrentRepl().getInterpreterGroup()).thenReturn(mdGroup);
    final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
    when(mdRegistry.addAndNotifyRemoteProcess(varName, value, "noteId", "paragraphId")).thenReturn(ao1);
    NotebookSocket conn = mock(NotebookSocket.class);
    NotebookSocket otherConn = mock(NotebookSocket.class);
    final String mdMsg1 = server.serializeMessage(new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
    server.noteSocketMap.put("noteId", asList(conn, otherConn));
    // When
    server.angularObjectClientBind(conn, new HashSet<String>(), notebook, messageReceived);
    // Then
    verify(mdRegistry, never()).addAndNotifyRemoteProcess(varName, value, "noteId", null);
    verify(otherConn).send(mdMsg1);
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Aggregations

Message (org.apache.zeppelin.notebook.socket.Message)51 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)38 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)38 Note (org.apache.zeppelin.notebook.Note)24 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)14 AngularObject (org.apache.zeppelin.display.AngularObject)9 Paragraph (org.apache.zeppelin.notebook.Paragraph)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 Notebook (org.apache.zeppelin.notebook.Notebook)8 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)7 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)6 JsonObject (com.google.gson.JsonObject)5 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)4 ZeppelinhubMessage (org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)3