Search in sources :

Example 1 with Message

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

Example 2 with Message

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

Example 3 with Message

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

Example 4 with Message

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;
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) AngularObject(org.apache.zeppelin.display.AngularObject)

Example 5 with Message

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));
        }
    });
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) ArrayList(java.util.ArrayList) List(java.util.List) InterpreterSettingsList(org.apache.zeppelin.types.InterpreterSettingsList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServerEndpoint(javax.websocket.server.ServerEndpoint) URISyntaxException(java.net.URISyntaxException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ServiceException(org.apache.zeppelin.interpreter.thrift.ServiceException)

Aggregations

Message (org.apache.zeppelin.common.Message)49 OnMessage (javax.websocket.OnMessage)31 ClusterMessage (org.apache.zeppelin.cluster.event.ClusterMessage)31 IOException (java.io.IOException)18 ServiceContext (org.apache.zeppelin.service.ServiceContext)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 AngularObject (org.apache.zeppelin.display.AngularObject)10 Test (org.junit.Test)10 Mockito.anyString (org.mockito.Mockito.anyString)10 UnknownHostException (java.net.UnknownHostException)8 TException (org.apache.thrift.TException)8 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)8 Note (org.apache.zeppelin.notebook.Note)8 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)7 HashMap (java.util.HashMap)6 List (java.util.List)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)6