Search in sources :

Example 31 with Message

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

the class NotebookServerTest method bindAngularObjectToLocalForParagraphs.

@Test
public void bindAngularObjectToLocalForParagraphs() 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 AngularObjectRegistry mdRegistry = mock(AngularObjectRegistry.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.add(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(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) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 32 with Message

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

the class NotebookServerTest method unbindAngularObjectFromRemoteForParagraphs.

@Test
public void unbindAngularObjectFromRemoteForParagraphs() throws Exception {
    //Given
    final String varName = "name";
    final String value = "val";
    final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_UNBIND).put("noteId", "noteId").put("name", varName).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.removeAndNotifyRemoteProcess(varName, "noteId", "paragraphId")).thenReturn(ao1);
    NotebookSocket conn = mock(NotebookSocket.class);
    NotebookSocket otherConn = mock(NotebookSocket.class);
    final String mdMsg1 = server.serializeMessage(new Message(OP.ANGULAR_OBJECT_REMOVE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
    server.noteSocketMap.put("noteId", asList(conn, otherConn));
    // When
    server.angularObjectClientUnbind(conn, new HashSet<String>(), notebook, messageReceived);
    // Then
    verify(mdRegistry, never()).removeAndNotifyRemoteProcess(varName, "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)

Example 33 with Message

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

the class ZeppelinClient method handleMsgFromZeppelin.

public void handleMsgFromZeppelin(String message, String noteId) {
    Map<String, String> meta = new HashMap<>();
    meta.put("token", zeppelinhubToken);
    meta.put("noteId", noteId);
    Message zeppelinMsg = deserialize(message);
    if (zeppelinMsg == null) {
        return;
    }
    ZeppelinhubMessage hubMsg = ZeppelinhubMessage.newMessage(zeppelinMsg, meta);
    Client client = Client.getInstance();
    if (client == null) {
        LOG.warn("Client isn't initialized yet");
        return;
    }
    client.relayToZeppelinHub(hubMsg.serialize());
}
Also used : ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) 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) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient)

Example 34 with Message

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

the class ZeppelinhubClient method runAllParagraph.

boolean runAllParagraph(String noteId, String hubMsg) {
    LOG.info("Running paragraph with noteId {}", noteId);
    try {
        JSONObject data = new JSONObject(hubMsg);
        if (data.equals(JSONObject.NULL) || !(data.get("data") instanceof JSONArray)) {
            LOG.error("Wrong \"data\" format for RUN_NOTEBOOK");
            return false;
        }
        Client client = Client.getInstance();
        if (client == null) {
            LOG.warn("Base client isn't initialized, returning");
            return false;
        }
        Message zeppelinMsg = new Message(OP.RUN_PARAGRAPH);
        JSONArray paragraphs = data.getJSONArray("data");
        for (int i = 0; i < paragraphs.length(); i++) {
            if (!(paragraphs.get(i) instanceof JSONObject)) {
                LOG.warn("Wrong \"paragraph\" format for RUN_NOTEBOOK");
                continue;
            }
            zeppelinMsg.data = gson.fromJson(paragraphs.getString(i), new TypeToken<Map<String, Object>>() {
            }.getType());
            client.relayToZeppelin(zeppelinMsg, noteId);
            LOG.info("\nSending RUN_PARAGRAPH message to Zeppelin ");
        }
    } catch (JSONException e) {
        LOG.error("Failed to parse RUN_NOTEBOOK message from ZeppelinHub ", e);
        return false;
    }
    return true;
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) JSONArray(com.amazonaws.util.json.JSONArray) JSONException(com.amazonaws.util.json.JSONException) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Map(java.util.Map)

Example 35 with Message

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

the class ZeppelinClientTest method sendToZeppelinTest.

@Test
public void sendToZeppelinTest() {
    ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "TOKEN", null);
    client.start();
    Message msg = new Message(OP.LIST_NOTES);
    msg.data = Maps.newHashMap();
    msg.data.put("key", "value");
    client.send(msg, "DDDD");
    client.removeNoteConnection("DDDD");
    client.stop();
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) 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