Search in sources :

Example 1 with JSONArray

use of com.amazonaws.util.json.JSONArray in project zeppelin by apache.

the class ZeppelinhubClient method runAllParagraph.

boolean runAllParagraph(String noteId, String hubMsg) {
    LOG.info("Running paragraph with noteId {}", noteId);
    try {
        JSONObject data = new JSONObject(hubMsg);
        if (data.equals(JSONObject.NULL) || !(data.get("data") instanceof JSONArray)) {
            LOG.error("Wrong \"data\" format for RUN_NOTEBOOK");
            return false;
        }
        Client client = Client.getInstance();
        if (client == null) {
            LOG.warn("Base client isn't initialized, returning");
            return false;
        }
        Message zeppelinMsg = new Message(OP.RUN_PARAGRAPH);
        JSONArray paragraphs = data.getJSONArray("data");
        for (int i = 0; i < paragraphs.length(); i++) {
            if (!(paragraphs.get(i) instanceof JSONObject)) {
                LOG.warn("Wrong \"paragraph\" format for RUN_NOTEBOOK");
                continue;
            }
            zeppelinMsg.data = gson.fromJson(paragraphs.getString(i), new TypeToken<Map<String, Object>>() {
            }.getType());
            client.relayToZeppelin(zeppelinMsg, noteId);
            LOG.info("\nSending RUN_PARAGRAPH message to Zeppelin ");
        }
    } catch (JSONException e) {
        LOG.error("Failed to parse RUN_NOTEBOOK message from ZeppelinHub ", e);
        return false;
    }
    return true;
}
Also used : JSONObject(com.amazonaws.util.json.JSONObject) Message(org.apache.zeppelin.notebook.socket.Message) ZeppelinhubMessage(org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage) JSONArray(com.amazonaws.util.json.JSONArray) JSONException(com.amazonaws.util.json.JSONException) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Map(java.util.Map)

Aggregations

JSONArray (com.amazonaws.util.json.JSONArray)1 JSONException (com.amazonaws.util.json.JSONException)1 JSONObject (com.amazonaws.util.json.JSONObject)1 Map (java.util.Map)1 ZeppelinhubMessage (org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol.ZeppelinhubMessage)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)1