Search in sources :

Example 16 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method inlineBroadcastParagraphs.

private void inlineBroadcastParagraphs(Map<String, Paragraph> userParagraphMap, String msgId) {
    if (null != userParagraphMap) {
        for (String user : userParagraphMap.keySet()) {
            Message message = new Message(OP.PARAGRAPH).withMsgId(msgId).put("paragraph", userParagraphMap.get(user));
            connectionManager.multicastToUser(user, message);
        }
    }
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message)

Example 17 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method sendMessage.

@ManagedOperation
public void sendMessage(String message) {
    Message m = new Message(OP.NOTICE);
    m.data.put("notice", message);
    connectionManager.broadcast(m);
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Example 18 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method broadcastSpellExecution.

private void broadcastSpellExecution(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = connectionManager.getAssociatedNoteId(conn);
    getNotebookService().spell(noteId, fromMessage, context, new WebSocketServiceCallback<Paragraph>(conn) {

        @Override
        public void onSuccess(Paragraph p, ServiceContext context) throws IOException {
            super.onSuccess(p, context);
            // broadcast to other clients only
            connectionManager.broadcastExcept(p.getNote().getId(), new Message(OP.RUN_PARAGRAPH_USING_SPELL).put("paragraph", p), conn);
        }
    });
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) IOException(java.io.IOException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 19 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method onParaInfosReceived.

@Override
public void onParaInfosReceived(String noteId, String paragraphId, String interpreterSettingId, Map<String, String> metaInfos) {
    try {
        getNotebook().processNote(noteId, note -> {
            if (note != null) {
                Paragraph paragraph = note.getParagraph(paragraphId);
                if (paragraph != null) {
                    InterpreterSetting setting = getNotebook().getInterpreterSettingManager().get(interpreterSettingId);
                    String label = metaInfos.get("label");
                    String tooltip = metaInfos.get("tooltip");
                    List<String> keysToRemove = Arrays.asList("noteId", "paraId", "label", "tooltip");
                    for (String removeKey : keysToRemove) {
                        metaInfos.remove(removeKey);
                    }
                    paragraph.updateRuntimeInfos(label, tooltip, metaInfos, setting.getGroup(), setting.getId());
                    getNotebook().saveNote(note, AuthenticationInfo.ANONYMOUS);
                    connectionManager.broadcast(note.getId(), new Message(OP.PARAS_INFO).put("id", paragraphId).put("infos", paragraph.getRuntimeInfos()));
                }
            }
            return null;
        });
    } catch (IOException e) {
        LOG.warn("Fail to call onParaInfosReceived", e);
    }
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) IOException(java.io.IOException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 20 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method updateNote.

private void updateNote(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("id");
    String name = (String) fromMessage.get("name");
    Map<String, Object> config = (Map<String, Object>) fromMessage.get("config");
    if (noteId == null) {
        return;
    }
    if (config == null) {
        return;
    }
    getNotebookService().updateNote(noteId, name, config, context, new WebSocketServiceCallback<Note>(conn) {

        @Override
        public void onSuccess(Note note, ServiceContext context) throws IOException {
            connectionManager.broadcast(note.getId(), new Message(OP.NOTE_UPDATED).put("name", name).put("config", config).put("info", note.getInfo()));
            broadcastNoteList(context.getAutheInfo(), context.getUserAndRoles());
        }
    });
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) Note(org.apache.zeppelin.notebook.Note) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Message (org.apache.zeppelin.common.Message)49 OnMessage (javax.websocket.OnMessage)31 ClusterMessage (org.apache.zeppelin.cluster.event.ClusterMessage)31 IOException (java.io.IOException)18 ServiceContext (org.apache.zeppelin.service.ServiceContext)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 AngularObject (org.apache.zeppelin.display.AngularObject)10 Test (org.junit.Test)10 Mockito.anyString (org.mockito.Mockito.anyString)10 UnknownHostException (java.net.UnknownHostException)8 TException (org.apache.thrift.TException)8 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)8 Note (org.apache.zeppelin.notebook.Note)8 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)7 HashMap (java.util.HashMap)6 List (java.util.List)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)6