Search in sources :

Example 6 with RemoteAngularObjectRegistry

use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry 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 7 with RemoteAngularObjectRegistry

use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project zeppelin by apache.

the class Note method removeAllAngularObjectInParagraph.

private void removeAllAngularObjectInParagraph(String user, String paragraphId) {
    angularObjects = new HashMap<>();
    List<InterpreterSetting> settings = interpreterSettingManager.getInterpreterSettings(getId());
    if (settings == null || settings.size() == 0) {
        return;
    }
    for (InterpreterSetting setting : settings) {
        InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id);
        AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
        if (registry instanceof RemoteAngularObjectRegistry) {
            // remove paragraph scope object
            ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, paragraphId);
            // remove app scope object
            List<ApplicationState> appStates = getParagraph(paragraphId).getAllApplicationStates();
            if (appStates != null) {
                for (ApplicationState app : appStates) {
                    ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, app.getId());
                }
            }
        } else {
            registry.removeAll(id, paragraphId);
            // remove app scope object
            List<ApplicationState> appStates = getParagraph(paragraphId).getAllApplicationStates();
            if (appStates != null) {
                for (ApplicationState app : appStates) {
                    registry.removeAll(id, app.getId());
                }
            }
        }
    }
}
Also used : RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)

Aggregations

RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)7 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)5 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)4 Note (org.apache.zeppelin.notebook.Note)4 Notebook (org.apache.zeppelin.notebook.Notebook)2 Paragraph (org.apache.zeppelin.notebook.Paragraph)2 Message (org.apache.zeppelin.notebook.socket.Message)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 NullArgumentException (org.apache.commons.lang.NullArgumentException)1 AngularObject (org.apache.zeppelin.display.AngularObject)1