use of kong.unirest.json.JSONObject in project zeppelin by apache.
the class ZeppelinClient method getSession.
/**
* Get session info for the provided sessionId.
* Return null if provided sessionId doesn't exist.
*
* @param sessionId
* @throws Exception
*/
public SessionInfo getSession(String sessionId) throws Exception {
HttpResponse<JsonNode> response = Unirest.get("/session/{sessionId}").routeParam("sessionId", sessionId).asJson();
if (response.getStatus() == 404) {
String statusText = response.getStatusText();
if (response.getBody().getObject().has("message")) {
statusText = response.getBody().getObject().getString("message");
}
if (statusText.contains("No such session")) {
return null;
}
}
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
JSONObject bodyObject = jsonNode.getObject().getJSONObject("body");
return createSessionInfoFromJson(bodyObject);
}
use of kong.unirest.json.JSONObject in project zeppelin by apache.
the class ZeppelinClient method cloneNote.
/**
* Clone a note to a specified notePath.
*
* @param noteId
* @param destPath
* @return
* @throws Exception
*/
public String cloneNote(String noteId, String destPath) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("name", destPath);
HttpResponse<JsonNode> response = Unirest.post("/notebook/{noteId}").routeParam("noteId", noteId).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 submitNote.
/**
* Submit note to execute with provided noteId and parameters, return at once the submission is completed.
* You need to query {@link NoteResult} by yourself afterwards until note execution is completed.
* Interpreter process will be stopped after note execution.
*
* @param noteId
* @param parameters
* @return
* @throws Exception
*/
public NoteResult submitNote(String noteId, Map<String, String> parameters) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("params", parameters);
// run note in non-blocking and isolated way.
HttpResponse<JsonNode> response = Unirest.post("/notebook/job/{noteId}").routeParam("noteId", noteId).queryString("blocking", "false").queryString("isolated", "true").body(bodyObject).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
return queryNoteResult(noteId);
}
use of kong.unirest.json.JSONObject in project zeppelin by apache.
the class ZeppelinClient method importNote.
/**
* Import note with given note json content to the specified notePath.
*
* @param notePath
* @param noteContent
* @return
* @throws Exception
*/
public String importNote(String notePath, String noteContent) throws Exception {
JSONObject bodyObject = new JSONObject(noteContent);
HttpResponse<JsonNode> response = Unirest.post("/notebook/import").queryString("notePath", notePath).body(bodyObject).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 updateParagraph.
/**
* Update paragraph with specified title and text.
*
* @param noteId
* @param paragraphId
* @param title
* @param text
* @throws Exception
*/
public void updateParagraph(String noteId, String paragraphId, String title, String text) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("title", title);
bodyObject.put("text", text);
HttpResponse<JsonNode> response = Unirest.put("/notebook/{noteId}/paragraph/{paragraphId}").routeParam("noteId", noteId).routeParam("paragraphId", paragraphId).body(bodyObject.toString()).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
}
Aggregations