Search in sources :

Example 11 with RemoteAngularObjectRegistry

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

the class NotebookServer method angularObjectClientBind.

/**
 * 1. Push the given Angular variable to the target interpreter angular
 * registry given a noteId and a paragraph id.
 * 2. Save AngularObject to note.
 */
protected void angularObjectClientBind(NotebookSocket conn, Message fromMessage) throws Exception {
    String noteId = fromMessage.getType("noteId");
    String varName = fromMessage.getType("name");
    Object varValue = fromMessage.get("value");
    String paragraphId = fromMessage.getType("paragraphId");
    if (paragraphId == null) {
        throw new IllegalArgumentException("target paragraph not specified for " + "angular value bind");
    }
    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 = pushAngularObjectToRemoteRegistry(noteId, paragraphId, varName, varValue, registry, interpreterGroup.getId(), conn);
            note.addOrUpdateAngularObject(interpreterGroup.getId(), ao);
        }
        return null;
    });
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) 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 12 with RemoteAngularObjectRegistry

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

the class NotebookServer method updateAngularObjectRegistry.

/**
 * Update the AngularObject object in the note to InterpreterGroup and AngularObjectRegistry.
 */
private void updateAngularObjectRegistry(NotebookSocket conn, Note note) {
    for (Paragraph paragraph : note.getParagraphs()) {
        InterpreterGroup interpreterGroup = null;
        try {
            interpreterGroup = findInterpreterGroupForParagraph(note, paragraph.getId());
        } catch (Exception e) {
            LOG.warn(e.getMessage(), e);
        }
        if (null == interpreterGroup) {
            return;
        }
        RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry();
        List<AngularObject> angularObjects = note.getAngularObjects(interpreterGroup.getId());
        for (AngularObject ao : angularObjects) {
            if (StringUtils.equals(ao.getNoteId(), note.getId()) && StringUtils.equals(ao.getParagraphId(), paragraph.getId())) {
                pushAngularObjectToRemoteRegistry(ao.getNoteId(), ao.getParagraphId(), ao.getName(), ao.get(), registry, interpreterGroup.getId(), conn);
            }
        }
    }
}
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) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 13 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");
    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.removeAndNotifyRemoteProcess(varName, "noteId", "paragraphId")).thenReturn(ao1);
        NotebookSocket conn = mock(NotebookSocket.class);
        NotebookSocket otherConn = mock(NotebookSocket.class);
        final String mdMsg1 = notebookServer.serializeMessage(new Message(OP.ANGULAR_OBJECT_REMOVE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
        notebookServer.getConnectionManager().noteSocketMap.put("noteId", asList(conn, otherConn));
        // When
        notebookServer.angularObjectClientUnbind(conn, messageReceived);
        // Then
        verify(mdRegistry, never()).removeAndNotifyRemoteProcess(varName, "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 14 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 = getBindedInterpreterSettings(Arrays.asList(user));
    if (settings == null || settings.isEmpty()) {
        return;
    }
    for (InterpreterSetting setting : settings) {
        if (setting.getInterpreterGroup(getExecutionContext()) == null) {
            continue;
        }
        InterpreterGroup intpGroup = setting.getInterpreterGroup(getExecutionContext());
        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 : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)

Example 15 with RemoteAngularObjectRegistry

use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project SSM by Intel-bigdata.

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)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