You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2015/12/24 16:58:34 UTC

incubator-zeppelin git commit: ZEPPELIN-528 REST API: add "progress" to 'get notebook job' API

Repository: incubator-zeppelin
Updated Branches:
  refs/heads/master 927f48225 -> f78d3096e


ZEPPELIN-528 REST API: add "progress" to 'get notebook job' API

### What is this PR for?

To add 'progress' to 'get notebook job' REST API.
All paragraphs which status is 'running' will include 'progress' to their job status.

### What type of PR is it?

Improvement

### Todos

### Is there a relevant Jira issue?

https://issues.apache.org/jira/browse/ZEPPELIN-528

### How should this be tested?

1. Run a notebook or paragraph which takes some times. Paragraph which could show progress (%) would be more appreciated. Confirm that its status is 'RUNNING'.
2. Call ```http://<zeppelin host>:<zeppelin port>/api/notebook/job/<notebook id>``` to see if it has 'progress' field in JSON.

### Screenshots (if appropriate)

![notebook-2b68v95jm](https://cloud.githubusercontent.com/assets/1317309/11949192/cf176d8e-a8bf-11e5-9bb2-8f4dbd1666c8.png)
![notebook-job-api-result-2b68v95jm](https://cloud.githubusercontent.com/assets/1317309/11949191/cf16f7e6-a8bf-11e5-825b-97c6fa227d05.png)

### Questions:
* Does the licenses files need update? (No)
* Is there breaking changes for older versions? (No)
* Does this needs documentation? (Yes or no. Output of the JSON format could be updated, but it could be treated as not mandatory.)

Author: Jungtaek Lim <ka...@gmail.com>

Closes #563 from HeartSaVioR/ZEPPELIN-528 and squashes the following commits:

dc86b01 [Jungtaek Lim] ZEPPELIN-528 Add UT to get notebook job (especially 'progress' field)
69a58ab [Jungtaek Lim] Merge branch 'master' into ZEPPELIN-528
31a8e88 [Jungtaek Lim] ZEPPELIN-528 Explain new field 'progress' to JSON output
2597ebf [Jungtaek Lim] ZEPPELIN-528 Add 'progress' to paragraph information when running


Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/f78d3096
Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/f78d3096
Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/f78d3096

Branch: refs/heads/master
Commit: f78d3096e04d2b520e2fb257586ab61bdd9c847e
Parents: 927f482
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Thu Dec 24 15:03:15 2015 +0900
Committer: Lee moon soo <mo...@apache.org>
Committed: Fri Dec 25 01:00:07 2015 +0900

----------------------------------------------------------------------
 docs/rest-api/rest-notebook.md                  |  2 +-
 .../java/org/apache/zeppelin/scheduler/Job.java |  6 +--
 .../zeppelin/rest/ZeppelinRestApiTest.java      | 53 ++++++++++++++++++++
 .../java/org/apache/zeppelin/notebook/Note.java |  3 ++
 4 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/f78d3096/docs/rest-api/rest-notebook.md
----------------------------------------------------------------------
diff --git a/docs/rest-api/rest-notebook.md b/docs/rest-api/rest-notebook.md
index fade802..ffc3d8d 100644
--- a/docs/rest-api/rest-notebook.md
+++ b/docs/rest-api/rest-notebook.md
@@ -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>
   

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/f78d3096/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
----------------------------------------------------------------------
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
index c803d78..6379e4c 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/scheduler/Job.java
@@ -57,15 +57,15 @@ public abstract class Job {
     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;
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/f78d3096/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
index 2db3092..c69b223 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
@@ -434,6 +434,59 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
   }
 
   @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");
     // Create note to run test.

http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/f78d3096/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
index d193ecc..47da7c8 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
@@ -318,6 +318,9 @@ public class Note implements Serializable, JobListener {
         if (p.getDateFinished() != null) {
           info.put("finished", p.getDateFinished().toString());
         }
+        if (p.getStatus().isRunning()) {
+          info.put("progress", String.valueOf(p.progress()));
+        }
         paragraphsInfo.add(info);
       }
     }