Search in sources :

Example 1 with GetRequest

use of kong.unirest.GetRequest 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)1 GetRequest (kong.unirest.GetRequest)1 JsonNode (kong.unirest.JsonNode)1 JSONArray (kong.unirest.json.JSONArray)1 SessionInfo (org.apache.zeppelin.common.SessionInfo)1