Search in sources :

Example 16 with JsonNode

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");
}
Also used : JSONObject(kong.unirest.json.JSONObject) JsonNode(kong.unirest.JsonNode)

Example 17 with JsonNode

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;
}
Also used : GetRequest(kong.unirest.GetRequest) JSONArray(kong.unirest.json.JSONArray) ArrayList(java.util.ArrayList) SessionInfo(org.apache.zeppelin.common.SessionInfo) JsonNode(kong.unirest.JsonNode)

Example 18 with JsonNode

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"));
}
Also used : JsonNode(kong.unirest.JsonNode)

Example 19 with JsonNode

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);
}
Also used : JSONObject(kong.unirest.json.JSONObject) JsonNode(kong.unirest.JsonNode)

Example 20 with 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);
}
Also used : JSONObject(kong.unirest.json.JSONObject) JsonNode(kong.unirest.JsonNode)

Aggregations

JsonNode (kong.unirest.JsonNode)20 JSONObject (kong.unirest.json.JSONObject)13 ArrayList (java.util.ArrayList)2 JSONArray (kong.unirest.json.JSONArray)2 GetRequest (kong.unirest.GetRequest)1 SessionInfo (org.apache.zeppelin.common.SessionInfo)1