use of kong.unirest.JsonNode in project zeppelin by apache.
the class ZeppelinClient method nextSessionParagraph.
/**
* This used by {@link ZSession} for creating or reusing a paragraph for executing another piece of code.
*
* @param noteId
* @param maxParagraph
* @return
* @throws Exception
*/
public String nextSessionParagraph(String noteId, int maxParagraph) throws Exception {
HttpResponse<JsonNode> response = Unirest.post("/notebook/{noteId}/paragraph/next").routeParam("noteId", noteId).queryString("maxParagraph", maxParagraph).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
return jsonNode.getObject().getString("message");
}
use of kong.unirest.JsonNode 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.JsonNode 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.JsonNode 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.JsonNode 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");
}
Aggregations