Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/rest-api/rest-notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ limitations under the License.
</tr>
<tr>
<td> sample JSON response </td>
<td><pre>{"status":"OK","body":[{"id":"20151121-212654_766735423","status":"FINISHED","finished":"Tue Nov 24 14:21:40 KST 2015","started":"Tue Nov 24 14:21:39 KST 2015"},{"id":"20151121-212657_730976687","status":"FINISHED","finished":"Tue Nov 24 14:21:40 KST 2015","started":"Tue Nov 24 14:21:40 KST 2015"}]}</pre></td>
<td><pre>{"status":"OK","body":[{"id":"20151121-212654_766735423","status":"FINISHED","finished":"Tue Nov 24 14:21:40 KST 2015","started":"Tue Nov 24 14:21:39 KST 2015"},{"progress":"1","id":"20151121-212657_730976687","status":"RUNNING","finished":"Tue Nov 24 14:21:35 KST 2015","started":"Tue Nov 24 14:21:40 KST 2015"}]}</pre></td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public static enum Status {
FINISHED,
ERROR,
ABORT;
boolean isReady() {
public boolean isReady() {
return this == READY;
}

boolean isRunning() {
public boolean isRunning() {
return this == RUNNING;
}

boolean isPending() {
public boolean isPending() {
return this == PENDING;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,59 @@ public void testNoteJobs() throws IOException, InterruptedException {
ZeppelinServer.notebook.removeNote(note.getId());
}

@Test
public void testGetNotebookJob() throws IOException, InterruptedException {
LOG.info("testGetNotebookJob");
// Create note to run test.
Note note = ZeppelinServer.notebook.createNote();
assertNotNull("can't create new note", note);
note.setName("note for run test");
Paragraph paragraph = note.addParagraph();

Map config = paragraph.getConfig();
config.put("enabled", true);
paragraph.setConfig(config);

paragraph.setText("%sh sleep 1");
note.persist();
String noteID = note.getId();

note.runAll();

// wait until paragraph gets started
while (!paragraph.getStatus().isRunning()) {
Thread.sleep(100);
}

// assume that status of the paragraph is running
GetMethod get = httpGet("/notebook/job/" + noteID);
assertThat("test get notebook job: ", get, isAllowed());
String responseBody = get.getResponseBodyAsString();
get.releaseConnection();

LOG.info("test get notebook job: \n" + responseBody);
Map<String, Object> resp = gson.fromJson(responseBody, new TypeToken<Map<String, Object>>() {
}.getType());

List<Map<String, Object>> paragraphs = (List<Map<String, Object>>) resp.get("body");
assertEquals(1, paragraphs.size());
assertTrue(paragraphs.get(0).containsKey("progress"));
int progress = Integer.parseInt((String) paragraphs.get(0).get("progress"));
assertTrue(progress >= 0 && progress <= 100);

// wait until job is finished or timeout.
int timeout = 1;
while (!paragraph.isTerminated()) {
Thread.sleep(100);
if (timeout++ > 10) {
LOG.info("testGetNotebookJob timeout job.");
break;
}
}

ZeppelinServer.notebook.removeNote(note.getId());
}

@Test
public void testRunParagraphWithParams() throws IOException, InterruptedException {
LOG.info("testRunParagraphWithParams");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ public List<Map<String, String>> generateParagraphsInfo (){
if (p.getDateFinished() != null) {
info.put("finished", p.getDateFinished().toString());
}
if (p.getStatus().isRunning()) {
info.put("progress", String.valueOf(p.progress()));
}
paragraphsInfo.add(info);
}
}
Expand Down