use of kong.unirest.JsonNode in project zeppelin by apache.
the class ZeppelinClient method addParagraph.
/**
* Add paragraph to note with provided title and text.
*
* @param noteId
* @param title
* @param text
* @return
* @throws Exception
*/
public String addParagraph(String noteId, String title, String text) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("title", title);
bodyObject.put("text", text);
HttpResponse<JsonNode> response = Unirest.post("/notebook/{noteId}/paragraph").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 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;
}
use of kong.unirest.JsonNode in project zeppelin by apache.
the class ZeppelinClient method newSession.
/**
* Request a new session id. It doesn't create session (interpreter process) in zeppelin server side, but just
* create an unique session id.
*
* @param interpreter
* @return
* @throws Exception
*/
public SessionInfo newSession(String interpreter) throws Exception {
HttpResponse<JsonNode> response = Unirest.post("/session").queryString("interpreter", interpreter).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
return createSessionInfoFromJson(jsonNode.getObject().getJSONObject("body"));
}
use of kong.unirest.JsonNode in project zeppelin by apache.
the class ZeppelinClient method stopInterpreter.
/**
* This is equal to the restart operation in note page.
*
* @param noteId
* @param interpreter
*/
public void stopInterpreter(String noteId, String interpreter) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("noteId", noteId);
HttpResponse<JsonNode> response = Unirest.put("/interpreter/setting/restart/{interpreter}").routeParam("interpreter", interpreter).body(bodyObject.toString()).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
}
use of kong.unirest.JsonNode in project zeppelin by apache.
the class ZeppelinClient method renameNote.
public void renameNote(String noteId, String newNotePath) throws Exception {
JSONObject bodyObject = new JSONObject();
bodyObject.put("name", newNotePath);
HttpResponse<JsonNode> response = Unirest.put("/notebook/{noteId}/rename").routeParam("noteId", noteId).body(bodyObject.toString()).asJson();
checkResponse(response);
JsonNode jsonNode = response.getBody();
checkJsonNodeStatus(jsonNode);
}
Aggregations