Search in sources :

Example 1 with ZeppelinhubMessage

use of org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage 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"));
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) JSONObject(com.amazonaws.util.json.JSONObject) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Map(java.util.Map)

Example 2 with ZeppelinhubMessage

use of org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage in project zeppelin by apache.

the class ZeppelinClient method handleMsgFromZeppelin.

public void handleMsgFromZeppelin(String message, String noteId) {
    Map<String, String> meta = new HashMap<>();
    meta.put("token", zeppelinhubToken);
    meta.put("noteId", noteId);
    Message zeppelinMsg = deserialize(message);
    if (zeppelinMsg == null) {
        return;
    }
    ZeppelinhubMessage hubMsg = ZeppelinhubMessage.newMessage(zeppelinMsg, meta);
    Client client = Client.getInstance();
    if (client == null) {
        LOG.warn("Client isn't initialized yet");
        return;
    }
    client.relayToZeppelinHub(hubMsg.serialize());
}
Also used : ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient)

Example 3 with ZeppelinhubMessage

use of org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage in project zeppelin by apache.

the class ZeppelinhubClient method handleMsgFromZeppelinHub.

public void handleMsgFromZeppelinHub(String message) {
    ZeppelinhubMessage hubMsg = ZeppelinhubMessage.deserialize(message);
    if (hubMsg.equals(ZeppelinhubMessage.EMPTY)) {
        LOG.error("Cannot handle ZeppelinHub message is empty");
        return;
    }
    String op = StringUtils.EMPTY;
    if (hubMsg.op instanceof String) {
        op = (String) hubMsg.op;
    } else {
        LOG.error("Message OP from ZeppelinHub isn't string {}", hubMsg.op);
        return;
    }
    if (ZeppelinhubUtils.isZeppelinHubOp(op)) {
        handleZeppelinHubOpMsg(ZeppelinhubUtils.toZeppelinHubOp(op), hubMsg, message);
    } else if (ZeppelinhubUtils.isZeppelinOp(op)) {
        forwardToZeppelin(ZeppelinhubUtils.toZeppelinOp(op), hubMsg);
    }
}
Also used : ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage)

Aggregations

ZeppelinhubMessage (org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage)3 Message (org.apache.zeppelin.notebook.socket.Message)2 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)2 JSONObject (com.amazonaws.util.json.JSONObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1