use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class NotebookServer method removeAngularFromRemoteRegistry.
private AngularObject removeAngularFromRemoteRegistry(String noteId, String paragraphId, String varName, RemoteAngularObjectRegistry remoteRegistry, String interpreterGroupId, NotebookSocket conn) {
final AngularObject ao = remoteRegistry.removeAndNotifyRemoteProcess(varName, noteId, paragraphId);
connectionManager.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_REMOVE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", noteId).put("paragraphId", paragraphId), conn);
return ao;
}
use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class NotebookServer method onOutputAppend.
/**
* When application append output.
*/
@Override
public void onOutputAppend(String noteId, String paragraphId, int index, String appId, String output) {
Message msg = new Message(OP.APP_APPEND_OUTPUT).put("noteId", noteId).put("paragraphId", paragraphId).put("index", index).put("appId", appId).put("data", output);
connectionManager.broadcast(noteId, msg);
}
use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class NotebookServerTest method testAngularObjectSaveToNote.
@Test
public void testAngularObjectSaveToNote() throws IOException, InterruptedException {
// create a notebook
String note1Id = null;
try {
note1Id = notebook.createNote("note1", "angular", anonymous);
// get reference to interpreterGroup
InterpreterGroup interpreterGroup = null;
List<InterpreterSetting> settings = notebook.processNote(note1Id, note1 -> note1.getBindedInterpreterSettings(new ArrayList<>()));
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("angular")) {
interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", note1Id);
break;
}
}
String p1Id = notebook.processNote(note1Id, note1 -> {
// start interpreter process
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%angular <h2>Bind here : {{COMMAND_TYPE}}</h2>");
p1.setAuthenticationInfo(anonymous);
note1.run(p1.getId());
return p1.getId();
});
// wait for paragraph finished
Status status = notebook.processNote(note1Id, note1 -> note1.getParagraph(p1Id).getStatus());
while (true) {
if (status == Job.Status.FINISHED) {
break;
}
Thread.sleep(100);
status = notebook.processNote(note1Id, note1 -> note1.getParagraph(p1Id).getStatus());
}
// sleep for 1 second to make sure job running thread finish to fire event. See ZEPPELIN-3277
Thread.sleep(1000);
// create two sockets and open it
NotebookSocket sock1 = createWebSocket();
notebookServer.onOpen(sock1);
// getNote, getAngularObject
verify(sock1, times(0)).send(anyString());
// open the same notebook from sockets
notebookServer.onMessage(sock1, new Message(OP.GET_NOTE).put("id", note1Id).toJson());
reset(sock1);
// bind object from sock1
notebookServer.onMessage(sock1, new Message(OP.ANGULAR_OBJECT_CLIENT_BIND).put("noteId", note1Id).put("paragraphId", p1Id).put("name", "COMMAND_TYPE").put("value", "COMMAND_TYPE_VALUE").put("interpreterGroupId", interpreterGroup.getId()).toJson());
List<AngularObject> list = notebook.processNote(note1Id, note1 -> note1.getAngularObjects("angular-shared_process"));
assertEquals(1, list.size());
assertEquals(note1Id, list.get(0).getNoteId());
assertEquals(p1Id, list.get(0).getParagraphId());
assertEquals("COMMAND_TYPE", list.get(0).getName());
assertEquals("COMMAND_TYPE_VALUE", list.get(0).get());
// Check if the interpreterGroup AngularObjectRegistry is updated
Map<String, Map<String, AngularObject>> mapRegistry = interpreterGroup.getAngularObjectRegistry().getRegistry();
AngularObject ao = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE");
assertEquals("COMMAND_TYPE", ao.getName());
assertEquals("COMMAND_TYPE_VALUE", ao.get());
// update bind object from sock1
notebookServer.onMessage(sock1, new Message(OP.ANGULAR_OBJECT_UPDATED).put("noteId", note1Id).put("paragraphId", p1Id).put("name", "COMMAND_TYPE").put("value", "COMMAND_TYPE_VALUE_UPDATE").put("interpreterGroupId", interpreterGroup.getId()).toJson());
list = notebook.processNote(note1Id, note1 -> note1.getAngularObjects("angular-shared_process"));
assertEquals(1, list.size());
assertEquals(note1Id, list.get(0).getNoteId());
assertEquals(p1Id, list.get(0).getParagraphId());
assertEquals("COMMAND_TYPE", list.get(0).getName());
assertEquals("COMMAND_TYPE_VALUE_UPDATE", list.get(0).get());
// Check if the interpreterGroup AngularObjectRegistry is updated
mapRegistry = interpreterGroup.getAngularObjectRegistry().getRegistry();
AngularObject ao1 = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE");
assertEquals("COMMAND_TYPE", ao1.getName());
assertEquals("COMMAND_TYPE_VALUE_UPDATE", ao1.get());
// unbind object from sock1
notebookServer.onMessage(sock1, new Message(OP.ANGULAR_OBJECT_CLIENT_UNBIND).put("noteId", note1Id).put("paragraphId", p1Id).put("name", "COMMAND_TYPE").put("value", "COMMAND_TYPE_VALUE").put("interpreterGroupId", interpreterGroup.getId()).toJson());
list = notebook.processNote(note1Id, note1 -> note1.getAngularObjects("angular-shared_process"));
assertEquals(0, list.size());
// Check if the interpreterGroup AngularObjectRegistry is delete
mapRegistry = interpreterGroup.getAngularObjectRegistry().getRegistry();
AngularObject ao2 = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE");
assertNull(ao2);
} finally {
if (note1Id != null) {
notebook.removeNote(note1Id, anonymous);
}
}
}
use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class NotebookServerTest method testRuntimeInfos.
@Test
public void testRuntimeInfos() throws IOException {
// mock note
String msg = "{\"op\":\"IMPORT_NOTE\",\"data\":" + "{\"note\":{\"paragraphs\": [{\"text\": \"Test " + "paragraphs import\"," + "\"progressUpdateIntervalMs\":500," + "\"config\":{},\"settings\":{}}]," + "\"name\": \"Test RuntimeInfos\",\"config\": " + "{}}}}";
Message messageReceived = notebookServer.deserializeMessage(msg);
String noteId = null;
ServiceContext context = new ServiceContext(AuthenticationInfo.ANONYMOUS, new HashSet<>());
try {
noteId = notebookServer.importNote(null, context, messageReceived);
} catch (NullPointerException e) {
// broadcastNoteList(); failed nothing to worry.
LOG.error("Exception in NotebookServerTest while testImportNotebook, failed nothing to " + "worry ", e);
} catch (IOException e) {
e.printStackTrace();
}
// update RuntimeInfos
Map<String, String> infos = new java.util.HashMap<>();
String paragraphId = notebook.processNote(noteId, note -> {
assertNotNull(note);
assertNotNull(note.getParagraph(0));
infos.put("jobUrl", "jobUrl_value");
infos.put("jobLabel", "jobLabel_value");
infos.put("label", "SPARK JOB");
infos.put("tooltip", "View in Spark web UI");
infos.put("noteId", note.getId());
infos.put("paraId", note.getParagraph(0).getId());
return note.getParagraph(0).getId();
});
notebookServer.onParaInfosReceived(noteId, paragraphId, "spark", infos);
notebook.processNote(noteId, note -> {
Paragraph paragraph = note.getParagraph(paragraphId);
// check RuntimeInfos
assertTrue(paragraph.getRuntimeInfos().containsKey("jobUrl"));
List<Object> list = paragraph.getRuntimeInfos().get("jobUrl").getValue();
assertEquals(1, list.size());
Map<String, String> map = (Map<String, String>) list.get(0);
assertEquals(2, map.size());
assertEquals(map.get("jobUrl"), "jobUrl_value");
assertEquals(map.get("jobLabel"), "jobLabel_value");
return null;
});
}
use of org.apache.zeppelin.common.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");
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);
}
}
Aggregations