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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Zeppelin




**Documentation:** [User Guide](http://zeppelin.incubator.apache.org/docs/index.html)<br/>
**Mailing List:** [User and Dev mailing list](http://zeppelin.incubator.apache.org/community.html)<br/>
**Continuous Integration:** [![Build Status](https://secure.travis-ci.org/apache/incubator-zeppelin.png?branch=master)](https://travis-ci.org/apache/incubator-zeppelin) <br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.notebook.Note;
import org.apache.zeppelin.notebook.Notebook;
import org.apache.zeppelin.notebook.Paragraph;
import org.apache.zeppelin.rest.message.InterpreterSettingListForNoteBind;
import org.apache.zeppelin.rest.message.NewInterpreterSettingRequest;
import org.apache.zeppelin.rest.message.NewNotebookRequest;
Expand Down Expand Up @@ -166,11 +167,12 @@ public Response deleteNote(@PathParam("notebookId") String notebookId) throws IO
notebookServer.broadcastNoteList();
return new JsonResponse(Status.OK, "").build();
}

/**
* Clone note REST API
* @param
* @return JSON with status.CREATED
* @throws IOException
* @throws IOException, CloneNotSupportedException, IllegalArgumentException
*/
@POST
@Path("{notebookId}")
Expand All @@ -185,4 +187,117 @@ public Response cloneNote(@PathParam("notebookId") String notebookId, String mes
notebookServer.broadcastNoteList();
return new JsonResponse(Status.CREATED, "", newNote.getId()).build();
}

/**
* Run notebook jobs REST API
* @param
* @return JSON with status.ACCEPTED
* @throws IOException, IllegalArgumentException
*/
@POST
@Path("job/{notebookId}")
public Response runNoteJobs(@PathParam("notebookId") String notebookId) throws
IOException, IllegalArgumentException {
logger.info("run notebook jobs {} ", notebookId);
Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

note.runAll();
return new JsonResponse(Status.ACCEPTED).build();
}

/**
* Stop(delete) notebook jobs REST API
* @param
* @return JSON with status.ACCEPTED
* @throws IOException, IllegalArgumentException
*/
@DELETE
@Path("job/{notebookId}")
public Response stopNoteJobs(@PathParam("notebookId") String notebookId) throws
IOException, IllegalArgumentException {
logger.info("stop notebook jobs {} ", notebookId);
Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

for (Paragraph p : note.getParagraphs()) {
if (!p.isTerminated()) {
p.abort();
}
}
return new JsonResponse(Status.ACCEPTED).build();
}

/**
* Get notebook job status REST API
* @param
* @return JSON with status.OK
* @throws IOException, IllegalArgumentException
*/
@GET
@Path("job/{notebookId}")
public Response getNoteJobStatus(@PathParam("notebookId") String notebookId) throws
IOException, IllegalArgumentException {
logger.info("get notebook job status.");
Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

return new JsonResponse(Status.OK, null, note.generateParagraphsInfo()).build();
}

/**
* Run paragraph job REST API
* @param
* @return JSON with status.ACCEPTED
* @throws IOException, IllegalArgumentException
*/
@POST
@Path("job/{notebookId}/{paragraphId}")
public Response runParagraph(@PathParam("notebookId") String notebookId,
@PathParam("paragraphId") String paragraphId) throws
IOException, IllegalArgumentException {
logger.info("run paragraph job {} {} ", notebookId, paragraphId);
Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

if (note.getParagraph(paragraphId) == null) {
return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build();
}

note.run(paragraphId);
return new JsonResponse(Status.ACCEPTED).build();
}

/**
* Stop(delete) paragraph job REST API
* @param
* @return JSON with status.ACCEPTED
* @throws IOException, IllegalArgumentException
*/
@DELETE
@Path("job/{notebookId}/{paragraphId}")
public Response stopParagraph(@PathParam("notebookId") String notebookId,
@PathParam("paragraphId") String paragraphId) throws
IOException, IllegalArgumentException {
logger.info("stop paragraph job {} ", notebookId);
Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build();
}
p.abort();
return new JsonResponse(Status.ACCEPTED).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ protected Matcher<? super HttpMethodBase> isAllowed() {

protected Matcher<? super HttpMethodBase> isCreated() { return responsesWith(201); }

protected Matcher<? super HttpMethodBase> isAccepted() { return responsesWith(202); }

protected Matcher<? super HttpMethodBase> isNotAllowed() {
return responsesWith(405);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void testCloneNotebook() throws IOException, CloneNotSupportedException,
LOG.info("testCloneNotebook");
// Create note to clone
Note note = ZeppelinServer.notebook.createNote();
assertNotNull("cant create new note", note);
assertNotNull("can't create new note", note);
note.setName("source note for clone");
Paragraph paragraph = note.addParagraph();
paragraph.setText("%md This is my new paragraph in my new note");
Expand Down Expand Up @@ -300,5 +300,49 @@ public void testListNotebooks() throws IOException {
get.releaseConnection();
}

@Test
public void testNoteJobs() throws IOException, InterruptedException {
LOG.info("testNoteJobs");
// 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();
paragraph.setText("%md This is test paragraph.");
note.persist();
String noteID = note.getId();

// Call Run Notebook Jobs REST API
PostMethod postNoteJobs = httpPost("/notebook/job/" + noteID, "");
assertThat("test notebook jobs run:", postNoteJobs, isAccepted());
postNoteJobs.releaseConnection();

// wait until job is finished or timeout.
int timeout = 1;
while (paragraph.getStatus() == Status.PENDING || paragraph.isTerminated()) {
Thread.sleep(1000);
if (timeout++ > 10) {
LOG.info("testNoteJobs timeout job.");
break;
}
}
// Call Stop Notebook Jobs REST API
DeleteMethod deleteNoteJobs = httpDelete("/notebook/job/" + noteID);
assertThat("test notebook stop:", deleteNoteJobs, isAccepted());
deleteNoteJobs.releaseConnection();

// Call Run paragraph REST API
PostMethod postParagraph = httpPost("/notebook/job/" + noteID + "/" + paragraph.getId(), "");
assertThat("test paragraph run:", postParagraph, isAccepted());
postParagraph.releaseConnection();

// Call Stop paragraph REST API
DeleteMethod deleteParagraph = httpDelete("/notebook/job/" + noteID + "/" + paragraph.getId());
assertThat("test paragraph stop:", deleteParagraph, isAccepted());
deleteParagraph.releaseConnection();

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

Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,21 @@ public Paragraph getLastParagraph() {
}
}

public List<Map<String, String>> generateParagraphsInfo (){
List<Map<String, String>> paragraphsInfo = new LinkedList<>();
synchronized (paragraphs) {
for (Paragraph p : paragraphs) {
Map<String, String> info = new HashMap<>();
info.put("id", p.getId());
info.put("status", p.getStatus().toString());
info.put("started", p.getDateStarted().toString());
info.put("finished", p.getDateFinished().toString());
paragraphsInfo.add(info);
}
}
return paragraphsInfo;
}

/**
* Run all paragraphs sequentially.
*
Expand Down