use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class ZSession method reconnect.
private void reconnect(MessageHandler messageHandler) throws Exception {
this.sessionInfo = this.zeppelinClient.getSession(getSessionId());
if (!sessionInfo.getState().equalsIgnoreCase("Running")) {
throw new Exception("Session " + getSessionId() + " is not running, state: " + sessionInfo.getState());
}
if (messageHandler != null) {
this.webSocketClient = new ZeppelinWebSocketClient(messageHandler);
this.webSocketClient.connect(zeppelinClient.getClientConfig().getZeppelinRestUrl().replace("https", "ws").replace("http", "ws") + "/ws");
// call GET_NOTE to establish websocket connection between this session and zeppelin-server
Message msg = new Message(Message.OP.GET_NOTE);
msg.put("id", getNoteId());
this.webSocketClient.send(msg);
}
}
use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class ZSession method start.
/**
* Start this ZSession, underneath it would create a note for this ZSession and
* start a dedicated interpreter process.
*
* @param messageHandler
* @throws Exception
*/
public void start(MessageHandler messageHandler) throws Exception {
this.sessionInfo = zeppelinClient.newSession(interpreter);
// inline configuration
StringBuilder builder = new StringBuilder("%" + interpreter + ".conf\n");
if (intpProperties != null) {
for (Map.Entry<String, String> entry : intpProperties.entrySet()) {
builder.append(entry.getKey() + " " + entry.getValue() + "\n");
}
}
String paragraphId = zeppelinClient.addParagraph(getNoteId(), "Session Configuration", builder.toString());
ParagraphResult paragraphResult = zeppelinClient.executeParagraph(getNoteId(), paragraphId, getSessionId());
if (paragraphResult.getStatus() != Status.FINISHED) {
throw new Exception("Fail to configure session, " + paragraphResult.getResultInText());
}
// start session
// add local properties (init) to avoid skip empty paragraph.
paragraphId = zeppelinClient.addParagraph(getNoteId(), "Session Init", "%" + interpreter + "(init=true)");
paragraphResult = zeppelinClient.executeParagraph(getNoteId(), paragraphId, getSessionId());
if (paragraphResult.getStatus() != Status.FINISHED) {
throw new Exception("Fail to init session, " + paragraphResult.getResultInText());
}
this.sessionInfo = zeppelinClient.getSession(getSessionId());
if (messageHandler != null) {
this.webSocketClient = new ZeppelinWebSocketClient(messageHandler);
this.webSocketClient.connect(zeppelinClient.getClientConfig().getZeppelinRestUrl().replace("https", "ws").replace("http", "ws") + "/ws");
// call GET_NOTE to establish websocket connection between this session and zeppelin-server
Message msg = new Message(Message.OP.GET_NOTE);
msg.put("id", getNoteId());
this.webSocketClient.send(msg);
}
}
use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class AbstractMessageHandler method onMessage.
@Override
public void onMessage(String msg) {
try {
Message messageReceived = GSON.fromJson(msg, Message.class);
if (messageReceived.op != Message.OP.PING) {
LOGGER.debug("RECEIVE: " + messageReceived.op + ", RECEIVE PRINCIPAL: " + messageReceived.principal + ", RECEIVE TICKET: " + messageReceived.ticket + ", RECEIVE ROLES: " + messageReceived.roles + ", RECEIVE DATA: " + messageReceived.data);
}
switch(messageReceived.op) {
case PARAGRAPH_UPDATE_OUTPUT:
String noteId = (String) messageReceived.data.get("noteId");
String paragraphId = (String) messageReceived.data.get("paragraphId");
int index = (int) Double.parseDouble(messageReceived.data.get("index").toString());
String type = (String) messageReceived.data.get("type");
String output = (String) messageReceived.data.get("data");
onStatementUpdateOutput(paragraphId, index, type, output);
break;
case PARAGRAPH_APPEND_OUTPUT:
noteId = (String) messageReceived.data.get("noteId");
paragraphId = (String) messageReceived.data.get("paragraphId");
index = (int) Double.parseDouble(messageReceived.data.get("index").toString());
output = (String) messageReceived.data.get("data");
onStatementAppendOutput(paragraphId, index, output);
break;
default:
break;
}
} catch (Exception e) {
LOGGER.error("Can't handle message: " + msg, e);
}
}
use of org.apache.zeppelin.common.Message in project zeppelin by apache.
the class NotebookServer method pushAngularObjectToRemoteRegistry.
private AngularObject pushAngularObjectToRemoteRegistry(String noteId, String paragraphId, String varName, Object varValue, RemoteAngularObjectRegistry remoteRegistry, String interpreterGroupId, NotebookSocket conn) {
final AngularObject ao = remoteRegistry.addAndNotifyRemoteProcess(varName, varValue, noteId, paragraphId);
connectionManager.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE).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 completion.
private void completion(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
String noteId = connectionManager.getAssociatedNoteId(conn);
String paragraphId = (String) fromMessage.get("id");
String buffer = (String) fromMessage.get("buf");
int cursor = (int) Double.parseDouble(fromMessage.get("cursor").toString());
getNotebookService().completion(noteId, paragraphId, buffer, cursor, context, new WebSocketServiceCallback<List<InterpreterCompletion>>(conn) {
@Override
public void onSuccess(List<InterpreterCompletion> completions, ServiceContext context) throws IOException {
super.onSuccess(completions, context);
Message resp = new Message(OP.COMPLETION_LIST).put("id", paragraphId);
resp.put("completions", completions);
conn.send(serializeMessage(resp));
}
@Override
public void onFailure(Exception ex, ServiceContext context) throws IOException {
super.onFailure(ex, context);
Message resp = new Message(OP.COMPLETION_LIST).put("id", paragraphId);
resp.put("completions", new ArrayList<>());
conn.send(serializeMessage(resp));
}
});
}
Aggregations