use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class ZeppelinClient method zeppelinGetNoteMsg.
private Message zeppelinGetNoteMsg(String noteId) {
Message getNoteMsg = new Message(Message.OP.GET_NOTE);
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("id", noteId);
getNoteMsg.data = data;
return getNoteMsg;
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class ZeppelinhubClient method forwardToZeppelin.
@SuppressWarnings("unchecked")
private void forwardToZeppelin(Message.OP op, ZeppelinhubMessage hubMsg) {
Message zeppelinMsg = new Message(op);
if (!(hubMsg.data instanceof Map)) {
LOG.error("Data field of message from ZeppelinHub isn't in correct Map format");
return;
}
zeppelinMsg.data = (Map<String, Object>) hubMsg.data;
Client client = Client.getInstance();
if (client == null) {
LOG.warn("Base client isn't initialized, returning");
return;
}
client.relayToZeppelin(zeppelinMsg, hubMsg.meta.get("noteId"));
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class ZeppelinClientTest method zeppelinMessageSerializationTest.
@Test
public void zeppelinMessageSerializationTest() {
Message msg = new Message(OP.LIST_NOTES);
msg.data = Maps.newHashMap();
msg.data.put("key", "value");
ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "TOKEN", null);
String serializedMsg = client.serialize(msg);
Message deserializedMsg = client.deserialize(serializedMsg);
assertEquals(msg.op, deserializedMsg.op);
assertEquals(msg.data.get("key"), deserializedMsg.data.get("key"));
String invalidMsg = "random text";
deserializedMsg = client.deserialize(invalidMsg);
assertNull(deserializedMsg);
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class NotebookServer method onOutputAppend.
/**
* This callback is for the paragraph that runs on ZeppelinServer
*
* @param output output to append
*/
@Override
public void onOutputAppend(String noteId, String paragraphId, int index, String output) {
Message msg = new Message(OP.PARAGRAPH_APPEND_OUTPUT).put("noteId", noteId).put("paragraphId", paragraphId).put("index", index).put("data", output);
broadcast(noteId, msg);
}
use of org.apache.zeppelin.notebook.socket.Message in project zeppelin by apache.
the class NotebookServer method removeParagraph.
private void removeParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final String paragraphId = (String) fromMessage.get("id");
if (paragraphId == null) {
return;
}
String noteId = getOpenNoteId(conn);
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
return;
}
/** We dont want to remove the last paragraph */
final Note note = notebook.getNote(noteId);
if (!note.isLastParagraph(paragraphId)) {
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
Paragraph para = note.removeParagraph(subject.getUser(), paragraphId);
note.persist(subject);
if (para != null) {
broadcast(note.getId(), new Message(OP.PARAGRAPH_REMOVED).put("id", para.getId()));
}
}
}
Aggregations