use of org.apache.zeppelin.client.websocket.ZeppelinWebSocketClient 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.client.websocket.ZeppelinWebSocketClient 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);
}
}
Aggregations