Search in sources :

Example 36 with Message

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

the class NotebookServer method angularObjectUpdated.

/**
   * When angular object updated from client
   *
   * @param conn the web socket.
   * @param notebook the notebook.
   * @param fromMessage the message.
   */
private void angularObjectUpdated(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) {
    String noteId = (String) fromMessage.get("noteId");
    String paragraphId = (String) fromMessage.get("paragraphId");
    String interpreterGroupId = (String) fromMessage.get("interpreterGroupId");
    String varName = (String) fromMessage.get("name");
    Object varValue = fromMessage.get("value");
    String user = fromMessage.principal;
    AngularObject ao = null;
    boolean global = false;
    // propagate change to (Remote) AngularObjectRegistry
    Note note = notebook.getNote(noteId);
    if (note != null) {
        List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
        for (InterpreterSetting setting : settings) {
            if (setting.getInterpreterGroup(user, note.getId()) == null) {
                continue;
            }
            if (interpreterGroupId.equals(setting.getInterpreterGroup(user, note.getId()).getId())) {
                AngularObjectRegistry angularObjectRegistry = setting.getInterpreterGroup(user, note.getId()).getAngularObjectRegistry();
                // first trying to get local registry
                ao = angularObjectRegistry.get(varName, noteId, paragraphId);
                if (ao == null) {
                    // then try notebook scope registry
                    ao = angularObjectRegistry.get(varName, noteId, null);
                    if (ao == null) {
                        // then try global scope registry
                        ao = angularObjectRegistry.get(varName, null, null);
                        if (ao == null) {
                            LOG.warn("Object {} is not binded", varName);
                        } else {
                            // path from client -> server
                            ao.set(varValue, false);
                            global = true;
                        }
                    } else {
                        // path from client -> server
                        ao.set(varValue, false);
                        global = false;
                    }
                } else {
                    ao.set(varValue, false);
                    global = false;
                }
                break;
            }
        }
    }
    if (global) {
        // interpreter.
        for (Note n : notebook.getAllNotes()) {
            List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
            for (InterpreterSetting setting : settings) {
                if (setting.getInterpreterGroup(user, n.getId()) == null) {
                    continue;
                }
                if (interpreterGroupId.equals(setting.getInterpreterGroup(user, n.getId()).getId())) {
                    AngularObjectRegistry angularObjectRegistry = setting.getInterpreterGroup(user, n.getId()).getAngularObjectRegistry();
                    this.broadcastExcept(n.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", n.getId()).put("paragraphId", ao.getParagraphId()), conn);
                }
            }
        }
    } else {
        // broadcast to all web session for the note
        this.broadcastExcept(note.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", note.getId()).put("paragraphId", ao.getParagraphId()), conn);
    }
}
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) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 37 with Message

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

the class NotebookServer method cloneNote.

private void cloneNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException, CloneNotSupportedException {
    String noteId = getOpenNoteId(conn);
    String name = (String) fromMessage.get("name");
    Note newNote = notebook.cloneNote(noteId, name, new AuthenticationInfo(fromMessage.principal));
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    addConnectionToNote(newNote.getId(), (NotebookSocket) conn);
    conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", newNote)));
    broadcastNoteList(subject, userAndRoles);
}
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) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 38 with Message

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

the class NotebookServer method createNote.

private void createNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message message) throws IOException {
    AuthenticationInfo subject = new AuthenticationInfo(message.principal);
    try {
        Note note = null;
        String defaultInterpreterId = (String) message.get("defaultInterpreterId");
        if (!StringUtils.isEmpty(defaultInterpreterId)) {
            List<String> interpreterSettingIds = new LinkedList<>();
            interpreterSettingIds.add(defaultInterpreterId);
            for (String interpreterSettingId : notebook.getInterpreterSettingManager().getDefaultInterpreterSettingList()) {
                if (!interpreterSettingId.equals(defaultInterpreterId)) {
                    interpreterSettingIds.add(interpreterSettingId);
                }
            }
            note = notebook.createNote(interpreterSettingIds, subject);
        } else {
            note = notebook.createNote(subject);
        }
        // it's an empty note. so add one paragraph
        note.addParagraph(subject);
        if (message != null) {
            String noteName = (String) message.get("name");
            if (StringUtils.isEmpty(noteName)) {
                noteName = "Note " + note.getId();
            }
            note.setName(noteName);
        }
        note.persist(subject);
        addConnectionToNote(note.getId(), (NotebookSocket) conn);
        conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note)));
    } catch (FileSystemException e) {
        LOG.error("Exception from createNote", e);
        conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", "Oops! There is something wrong with the notebook file system. " + "Please check the logs for more details.")));
        return;
    }
    broadcastNoteList(subject, userAndRoles);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) 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) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList)

Example 39 with Message

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

the class NotebookServer method getInterpreterSettings.

private void getInterpreterSettings(NotebookSocket conn, AuthenticationInfo subject) throws IOException {
    List<InterpreterSetting> availableSettings = notebook().getInterpreterSettingManager().get();
    conn.send(serializeMessage(new Message(OP.INTERPRETER_SETTINGS).put("interpreterSettings", availableSettings)));
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting)

Example 40 with Message

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

the class NotebookServer method unicastNoteJobInfo.

public void unicastNoteJobInfo(NotebookSocket conn, Message fromMessage) throws IOException {
    addConnectionToNote(JOB_MANAGER_SERVICE.JOB_MANAGER_PAGE.getKey(), conn);
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    List<Map<String, Object>> noteJobs = notebook().getJobListByUnixTime(false, 0, subject);
    Map<String, Object> response = new HashMap<>();
    response.put("lastResponseUnixTime", System.currentTimeMillis());
    response.put("jobs", noteJobs);
    conn.send(serializeMessage(new Message(OP.LIST_NOTE_JOBS).put("noteJobs", response)));
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

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