Search in sources :

Example 1 with ZeppelinWebSocketClient

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);
    }
}
Also used : Message(org.apache.zeppelin.common.Message) ZeppelinWebSocketClient(org.apache.zeppelin.client.websocket.ZeppelinWebSocketClient)

Example 2 with ZeppelinWebSocketClient

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);
    }
}
Also used : Message(org.apache.zeppelin.common.Message) ZeppelinWebSocketClient(org.apache.zeppelin.client.websocket.ZeppelinWebSocketClient) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ZeppelinWebSocketClient (org.apache.zeppelin.client.websocket.ZeppelinWebSocketClient)2 Message (org.apache.zeppelin.common.Message)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1