Search in sources :

Example 1 with JSONArray

use of kong.unirest.json.JSONArray in project zeppelin by apache.

the class ZeppelinClient method extractNoteResultFromResponse.

private NoteResult extractNoteResultFromResponse(HttpResponse<JsonNode> response) throws Exception {
    checkResponse(response);
    JsonNode jsonNode = response.getBody();
    checkJsonNodeStatus(jsonNode);
    JSONObject noteJsonObject = jsonNode.getObject().getJSONObject("body");
    boolean isRunning = false;
    if (noteJsonObject.has("info")) {
        JSONObject infoJsonObject = noteJsonObject.getJSONObject("info");
        if (infoJsonObject.has("isRunning")) {
            isRunning = Boolean.parseBoolean(infoJsonObject.getString("isRunning"));
        }
    }
    String noteId = null;
    if (noteJsonObject.has("id")) {
        noteId = noteJsonObject.getString("id");
    }
    String notePath = null;
    if (noteJsonObject.has("path")) {
        notePath = noteJsonObject.getString("path");
    }
    List<ParagraphResult> paragraphResultList = new ArrayList<>();
    if (noteJsonObject.has("paragraphs")) {
        JSONArray paragraphJsonArray = noteJsonObject.getJSONArray("paragraphs");
        for (int i = 0; i < paragraphJsonArray.length(); ++i) {
            paragraphResultList.add(new ParagraphResult(paragraphJsonArray.getJSONObject(i)));
        }
    }
    return new NoteResult(noteId, notePath, isRunning, paragraphResultList);
}
Also used : JSONObject(kong.unirest.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(kong.unirest.json.JSONArray) JsonNode(kong.unirest.JsonNode)

Example 2 with JSONArray

use of kong.unirest.json.JSONArray in project zeppelin by apache.

the class ZeppelinClient method listSessions.

/**
 * List all the sessions for the provided interpreter.
 *
 * @param interpreter
 * @return
 * @throws Exception
 */
public List<SessionInfo> listSessions(String interpreter) throws Exception {
    GetRequest getRequest = Unirest.get("/session");
    if (interpreter != null) {
        getRequest.queryString("interpreter", interpreter);
    }
    HttpResponse<JsonNode> response = getRequest.asJson();
    checkResponse(response);
    JsonNode jsonNode = response.getBody();
    checkJsonNodeStatus(jsonNode);
    JSONArray sessionJsonArray = jsonNode.getObject().getJSONArray("body");
    List<SessionInfo> sessionInfos = new ArrayList<>();
    for (int i = 0; i < sessionJsonArray.length(); ++i) {
        sessionInfos.add(createSessionInfoFromJson(sessionJsonArray.getJSONObject(i)));
    }
    return sessionInfos;
}
Also used : GetRequest(kong.unirest.GetRequest) JSONArray(kong.unirest.json.JSONArray) ArrayList(java.util.ArrayList) SessionInfo(org.apache.zeppelin.common.SessionInfo) JsonNode(kong.unirest.JsonNode)

Aggregations

ArrayList (java.util.ArrayList)2 JsonNode (kong.unirest.JsonNode)2 JSONArray (kong.unirest.json.JSONArray)2 GetRequest (kong.unirest.GetRequest)1 JSONObject (kong.unirest.json.JSONObject)1 SessionInfo (org.apache.zeppelin.common.SessionInfo)1