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);
}
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;
}
Aggregations