Search in sources :

Example 1 with RemoteAngularObjectRegistry

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

the class NotebookServer method angularObjectClientUnbind.

/**
   * Remove the given Angular variable to the target
   * interpreter(s) angular registry given a noteId
   * and an optional list of paragraph id(s)
   */
protected void angularObjectClientUnbind(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws Exception {
    String noteId = fromMessage.getType("noteId");
    String varName = fromMessage.getType("name");
    String paragraphId = fromMessage.getType("paragraphId");
    Note note = notebook.getNote(noteId);
    if (paragraphId == null) {
        throw new IllegalArgumentException("target paragraph not specified for " + "angular value unBind");
    }
    if (note != null) {
        final InterpreterGroup interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
        final AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
        if (registry instanceof RemoteAngularObjectRegistry) {
            RemoteAngularObjectRegistry remoteRegistry = (RemoteAngularObjectRegistry) registry;
            removeAngularFromRemoteRegistry(noteId, paragraphId, varName, remoteRegistry, interpreterGroup.getId(), conn);
        } else {
            removeAngularObjectFromLocalRepo(noteId, paragraphId, varName, registry, interpreterGroup.getId(), conn);
        }
    }
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 2 with RemoteAngularObjectRegistry

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

the class Notebook method removeNote.

public void removeNote(String id, AuthenticationInfo subject) {
    Preconditions.checkNotNull(subject, "AuthenticationInfo should not be null");
    Note note;
    synchronized (notes) {
        note = notes.remove(id);
        folders.removeNote(note);
    }
    interpreterSettingManager.removeNoteInterpreterSettingBinding(subject.getUser(), id);
    noteSearchService.deleteIndexDocs(note);
    notebookAuthorization.removeNote(id);
    // remove from all interpreter instance's angular object registry
    for (InterpreterSetting settings : interpreterSettingManager.get()) {
        AngularObjectRegistry registry = settings.getInterpreterGroup(subject.getUser(), id).getAngularObjectRegistry();
        if (registry instanceof RemoteAngularObjectRegistry) {
            // remove paragraph scope object
            for (Paragraph p : note.getParagraphs()) {
                ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, p.getId());
                // remove app scope object
                List<ApplicationState> appStates = p.getAllApplicationStates();
                if (appStates != null) {
                    for (ApplicationState app : appStates) {
                        ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, app.getId());
                    }
                }
            }
            // remove note scope object
            ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, null);
        } else {
            // remove paragraph scope object
            for (Paragraph p : note.getParagraphs()) {
                registry.removeAll(id, p.getId());
                // remove app scope object
                List<ApplicationState> appStates = p.getAllApplicationStates();
                if (appStates != null) {
                    for (ApplicationState app : appStates) {
                        registry.removeAll(id, app.getId());
                    }
                }
            }
            // remove note scope object
            registry.removeAll(id, null);
        }
    }
    ResourcePoolUtils.removeResourcesBelongsToNote(id);
    fireNoteRemoveEvent(note);
    try {
        note.unpersist(subject);
    } catch (IOException e) {
        logger.error(e.toString(), e);
    }
}
Also used : RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) IOException(java.io.IOException) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)

Example 3 with RemoteAngularObjectRegistry

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

the class NotebookServer method angularObjectClientUnbind.

/**
 * 1. Remove the given Angular variable to the target interpreter(s) angular
 * registry given a noteId and an optional list of paragraph id(s).
 * 2. Delete AngularObject from note.
 */
protected void angularObjectClientUnbind(NotebookSocket conn, Message fromMessage) throws Exception {
    String noteId = fromMessage.getType("noteId");
    String varName = fromMessage.getType("name");
    String paragraphId = fromMessage.getType("paragraphId");
    if (paragraphId == null) {
        throw new IllegalArgumentException("target paragraph not specified for " + "angular value unBind");
    }
    getNotebook().processNote(noteId, note -> {
        if (note != null) {
            InterpreterGroup interpreterGroup;
            try {
                interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
            } catch (Exception e) {
                LOG.error("No interpreter group found for noteId {} and paragraphId {}", noteId, paragraphId, e);
                return null;
            }
            final RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry();
            AngularObject ao = removeAngularFromRemoteRegistry(noteId, paragraphId, varName, registry, interpreterGroup.getId(), conn);
            note.deleteAngularObject(interpreterGroup.getId(), noteId, paragraphId, varName);
        }
        return null;
    });
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObject(org.apache.zeppelin.display.AngularObject) URISyntaxException(java.net.URISyntaxException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ServiceException(org.apache.zeppelin.interpreter.thrift.ServiceException)

Example 4 with RemoteAngularObjectRegistry

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

the class NotebookServerTest method bindAngularObjectToRemoteForParagraphs.

@Test
public void bindAngularObjectToRemoteForParagraphs() 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");
    try {
        final Notebook notebook = mock(Notebook.class);
        notebookServer.setNotebook(() -> notebook);
        notebookServer.setNotebookService(() -> notebookService);
        final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
        when(notebook.processNote(eq("noteId"), Mockito.any())).then(e -> e.getArgumentAt(1, NoteProcessor.class).process(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.getBindedInterpreter().getInterpreterGroup()).thenReturn(mdGroup);
        final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
        when(mdRegistry.addAndNotifyRemoteProcess(varName, value, "noteId", "paragraphId")).thenReturn(ao1);
        NotebookSocket conn = mock(NotebookSocket.class);
        NotebookSocket otherConn = mock(NotebookSocket.class);
        final String mdMsg1 = notebookServer.serializeMessage(new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
        notebookServer.getConnectionManager().noteSocketMap.put("noteId", asList(conn, otherConn));
        // When
        notebookServer.angularObjectClientBind(conn, messageReceived);
        // Then
        verify(mdRegistry, never()).addAndNotifyRemoteProcess(varName, value, "noteId", null);
        verify(otherConn).send(mdMsg1);
    } finally {
        // reset these so that it won't affect other tests
        notebookServer.setNotebook(() -> NotebookServerTest.notebook);
        notebookServer.setNotebookService(() -> NotebookServerTest.notebookService);
    }
}
Also used : Message(org.apache.zeppelin.common.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) Mockito.anyString(org.mockito.Mockito.anyString) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 5 with RemoteAngularObjectRegistry

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

the class InterpreterSetting method createInterpreterGroup.

private ManagedInterpreterGroup createInterpreterGroup(String groupId) {
    AngularObjectRegistry angularObjectRegistry;
    ManagedInterpreterGroup interpreterGroup = new ManagedInterpreterGroup(groupId, this);
    angularObjectRegistry = new RemoteAngularObjectRegistry(groupId, angularObjectRegistryListener, interpreterGroup);
    interpreterGroup.setAngularObjectRegistry(angularObjectRegistry);
    return interpreterGroup;
}
Also used : RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Aggregations

RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)15 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)10 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)8 IOException (java.io.IOException)5 AngularObject (org.apache.zeppelin.display.AngularObject)4 Note (org.apache.zeppelin.notebook.Note)4 Paragraph (org.apache.zeppelin.notebook.Paragraph)4 URISyntaxException (java.net.URISyntaxException)3 UnknownHostException (java.net.UnknownHostException)3 TException (org.apache.thrift.TException)3 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)3 ForbiddenException (org.apache.zeppelin.rest.exception.ForbiddenException)3 NullArgumentException (org.apache.commons.lang.NullArgumentException)2 Message (org.apache.zeppelin.common.Message)2 Notebook (org.apache.zeppelin.notebook.Notebook)2 Test (org.junit.Test)2 Mockito.anyString (org.mockito.Mockito.anyString)2 JsonObject (com.google.gson.JsonObject)1 RegisteredInterpreter (org.apache.zeppelin.interpreter.Interpreter.RegisteredInterpreter)1 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)1