use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class NotebookServer method sendNote.
private void sendNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
LOG.info("New operation from {} : {} : {} : {} : {}", conn.getRequest().getRemoteAddr(), conn.getRequest().getRemotePort(), fromMessage.principal, fromMessage.op, fromMessage.get("id"));
String noteId = (String) fromMessage.get("id");
if (noteId == null) {
return;
}
String user = fromMessage.principal;
Note note = notebook.getNote(noteId);
if (note != null) {
if (!hasParagraphReaderPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "read")) {
return;
}
addConnectionToNote(note.getId(), conn);
if (note.isPersonalizedMode()) {
note = note.getUserNote(user);
}
conn.send(serializeMessage(new Message(OP.NOTE).put("note", note)));
sendAllAngularObjects(note, user, conn);
} else {
conn.send(serializeMessage(new Message(OP.NOTE).put("note", null)));
}
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class NotebookServer method onUpdate.
@Override
public void onUpdate(String interpreterGroupId, AngularObject object) {
Notebook notebook = notebook();
if (notebook == null) {
return;
}
List<Note> notes = notebook.getAllNotes();
for (Note note : notes) {
if (object.getNoteId() != null && !note.getId().equals(object.getNoteId())) {
continue;
}
List<InterpreterSetting> intpSettings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
if (intpSettings.isEmpty()) {
continue;
}
broadcast(note.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", object).put("interpreterGroupId", interpreterGroupId).put("noteId", note.getId()).put("paragraphId", object.getParagraphId()));
}
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class NotebookServer method sendHomeNote.
private void sendHomeNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
String noteId = notebook.getConf().getString(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN);
String user = fromMessage.principal;
Note note = null;
if (noteId != null) {
note = notebook.getNote(noteId);
}
if (note != null) {
if (!hasParagraphReaderPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "read")) {
return;
}
addConnectionToNote(note.getId(), conn);
conn.send(serializeMessage(new Message(OP.NOTE).put("note", note)));
sendAllAngularObjects(note, user, conn);
} else {
removeConnectionFromAllNote(conn);
conn.send(serializeMessage(new Message(OP.NOTE).put("note", null)));
}
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class NotebookServerTest method testCreateNoteWithDefaultInterpreterId.
@Test
public void testCreateNoteWithDefaultInterpreterId() throws IOException {
// create two sockets and open it
NotebookSocket sock1 = createWebSocket();
NotebookSocket sock2 = createWebSocket();
assertEquals(sock1, sock1);
assertNotEquals(sock1, sock2);
notebookServer.onOpen(sock1);
notebookServer.onOpen(sock2);
String noteName = "Note with millis " + System.currentTimeMillis();
String defaultInterpreterId = "";
List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().get();
if (settings.size() > 1) {
defaultInterpreterId = settings.get(1).getId();
}
// create note from sock1
notebookServer.onMessage(sock1, gson.toJson(new Message(OP.NEW_NOTE).put("name", noteName).put("defaultInterpreterId", defaultInterpreterId)));
// expect the events are broadcasted properly
verify(sock1, times(2)).send(anyString());
Note createdNote = null;
for (Note note : notebook.getAllNotes()) {
if (note.getName().equals(noteName)) {
createdNote = note;
break;
}
}
if (settings.size() > 1) {
assertEquals(notebook.getInterpreterSettingManager().getDefaultInterpreterSetting(createdNote.getId()).getId(), defaultInterpreterId);
}
notebook.removeNote(createdNote.getId(), anonymous);
}
use of org.apache.zeppelin.notebook.socket.Message 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");
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.addAndNotifyRemoteProcess(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(mdRegistry, never()).addAndNotifyRemoteProcess(varName, value, "noteId", null);
verify(otherConn).send(mdMsg1);
}
Aggregations