Search in sources :

Example 21 with Message

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

the class ZeppelinClient method zeppelinGetNoteMsg.

private Message zeppelinGetNoteMsg(String noteId) {
    Message getNoteMsg = new Message(Message.OP.GET_NOTE);
    HashMap<String, Object> data = new HashMap<String, Object>();
    data.put("id", noteId);
    getNoteMsg.data = data;
    return getNoteMsg;
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 22 with Message

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

the class ZeppelinhubClient method forwardToZeppelin.

@SuppressWarnings("unchecked")
private void forwardToZeppelin(Message.OP op, ZeppelinhubMessage hubMsg) {
    Message zeppelinMsg = new Message(op);
    if (!(hubMsg.data instanceof Map)) {
        LOG.error("Data field of message from ZeppelinHub isn't in correct Map format");
        return;
    }
    zeppelinMsg.data = (Map<String, Object>) hubMsg.data;
    Client client = Client.getInstance();
    if (client == null) {
        LOG.warn("Base client isn't initialized, returning");
        return;
    }
    client.relayToZeppelin(zeppelinMsg, hubMsg.meta.get("noteId"));
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) JSONObject(com.amazonaws.util.json.JSONObject) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Map(java.util.Map)

Example 23 with Message

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

the class ZeppelinClientTest method zeppelinMessageSerializationTest.

@Test
public void zeppelinMessageSerializationTest() {
    Message msg = new Message(OP.LIST_NOTES);
    msg.data = Maps.newHashMap();
    msg.data.put("key", "value");
    ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "TOKEN", null);
    String serializedMsg = client.serialize(msg);
    Message deserializedMsg = client.deserialize(serializedMsg);
    assertEquals(msg.op, deserializedMsg.op);
    assertEquals(msg.data.get("key"), deserializedMsg.data.get("key"));
    String invalidMsg = "random text";
    deserializedMsg = client.deserialize(invalidMsg);
    assertNull(deserializedMsg);
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) Test(org.junit.Test)

Example 24 with Message

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

the class NotebookServer method onOutputAppend.

/**
   * This callback is for the paragraph that runs on ZeppelinServer
   *
   * @param output output to append
   */
@Override
public void onOutputAppend(String noteId, String paragraphId, int index, String output) {
    Message msg = new Message(OP.PARAGRAPH_APPEND_OUTPUT).put("noteId", noteId).put("paragraphId", paragraphId).put("index", index).put("data", output);
    broadcast(noteId, msg);
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage)

Example 25 with Message

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

the class NotebookServer method removeParagraph.

private void removeParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    final String paragraphId = (String) fromMessage.get("id");
    if (paragraphId == null) {
        return;
    }
    String noteId = getOpenNoteId(conn);
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
        return;
    }
    /** We dont want to remove the last paragraph */
    final Note note = notebook.getNote(noteId);
    if (!note.isLastParagraph(paragraphId)) {
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        Paragraph para = note.removeParagraph(subject.getUser(), paragraphId);
        note.persist(subject);
        if (para != null) {
            broadcast(note.getId(), new Message(OP.PARAGRAPH_REMOVED).put("id", para.getId()));
        }
    }
}
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) Paragraph(org.apache.zeppelin.notebook.Paragraph)

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