use of kong.unirest.json.JSONObject in project zeppelin by apache.
the class ZeppelinClient method createNote.
/**
* Create a new empty note with provided notePath and defaultInterpreterGroup
*
* @param notePath
* @param defaultInterpreterGroup
* @return
* @throws Exception
*/
public String createNote(String notePath, String defaultInterpreterGroup) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("name", notePath);
bodyObject.put("defaultInterpreterGroup", defaultInterpreterGroup);
HttpResponse<JsonNode> response = Unirest.post("/notebook").body(bodyObject.toString()).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
return jsonNode.getObject().getString("body");
}
use of kong.unirest.json.JSONObject in project zeppelin by apache.
the class ZeppelinClient method queryNoteResultByPath.
/**
* Query {@link NoteResult} with provided notePath.
*
* @param notePath
* @return
* @throws Exception
*/
public NoteResult queryNoteResultByPath(String notePath) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("notePath", notePath);
HttpResponse<JsonNode> response = Unirest.post("/notebook/getByPath").body(bodyObject).asJson();
return extractNoteResultFromResponse(response);
}
use of kong.unirest.json.JSONObject 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.JSONObject in project zeppelin by apache.
the class ZeppelinClient method submitParagraph.
/**
* Submit paragraph to execute with provided parameters and sessionId. Return at once the submission is completed.
* You need to query {@link ParagraphResult} by yourself afterwards until paragraph execution is completed.
*
* @param noteId
* @param paragraphId
* @param sessionId
* @param parameters
* @return
* @throws Exception
*/
public ParagraphResult submitParagraph(String noteId, String paragraphId, String sessionId, Map<String, String> parameters) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("params", parameters);
HttpResponse<JsonNode> response = Unirest.post("/notebook/job/{noteId}/{paragraphId}").routeParam("noteId", noteId).routeParam("paragraphId", paragraphId).queryString("sessionId", sessionId).body(bodyObject.toString()).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
return queryParagraphResult(noteId, paragraphId);
}
use of kong.unirest.json.JSONObject in project zeppelin by apache.
the class ZeppelinClient method queryParagraphResult.
/**
* Query {@link ParagraphResult}
*
* @param noteId
* @param paragraphId
* @return
* @throws Exception
*/
public ParagraphResult queryParagraphResult(String noteId, String paragraphId) throws Exception {
HttpResponse<JsonNode> response = Unirest.get("/notebook/{noteId}/paragraph/{paragraphId}").routeParam("noteId", noteId).routeParam("paragraphId", paragraphId).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
JSONObject paragraphJson = jsonNode.getObject().getJSONObject("body");
return new ParagraphResult(paragraphJson);
}
Aggregations