Search in sources :

Example 6 with JsonNode

use of kong.unirest.JsonNode in project zeppelin by apache.

the class ZeppelinClient method getVersion.

/**
 * Get Zeppelin version.
 *
 * @return
 * @throws Exception
 */
public String getVersion() throws Exception {
    HttpResponse<JsonNode> response = Unirest.get("/version").asJson();
    checkResponse(response);
    JsonNode jsonNode = response.getBody();
    checkJsonNodeStatus(jsonNode);
    return jsonNode.getObject().getJSONObject("body").getString("version");
}
Also used : JsonNode(kong.unirest.JsonNode)

Example 7 with JsonNode

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

Example 8 with JsonNode

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

Example 9 with JsonNode

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

Example 10 with JsonNode

use of kong.unirest.JsonNode 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);
}
Also used : JSONObject(kong.unirest.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(kong.unirest.json.JSONArray) 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