mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
add job operation api
This commit is contained in:
parent
98758d1cc5
commit
1255674531
2 changed files with 130 additions and 1 deletions
|
|
@ -29,9 +29,11 @@ import javax.ws.rs.core.Response.Status;
|
|||
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;
|
||||
import org.apache.zeppelin.rest.message.RunNotebookRequest;
|
||||
import org.apache.zeppelin.server.JsonResponse;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.socket.NotebookServer;
|
||||
|
|
@ -166,11 +168,12 @@ public class NotebookRestApi {
|
|||
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}")
|
||||
|
|
@ -185,4 +188,115 @@ public class NotebookRestApi {
|
|||
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) {
|
||||
throw new IllegalArgumentException(notebookId + " not found");
|
||||
}
|
||||
|
||||
note.runAll();
|
||||
return new JsonResponse(Status.ACCEPTED, "", note.getId()).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) {
|
||||
throw new IllegalArgumentException(notebookId + " not found");
|
||||
}
|
||||
|
||||
for (Paragraph p : note.getParagraphs()) {
|
||||
if(!p.isTerminated()) {
|
||||
p.abort();
|
||||
}
|
||||
}
|
||||
return new JsonResponse(Status.ACCEPTED, "", note.getId()).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) {
|
||||
throw new IllegalArgumentException(notebookId + " not found");
|
||||
}
|
||||
|
||||
return new JsonResponse(Status.OK, "", 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) {
|
||||
throw new IllegalArgumentException(notebookId + " note not found");
|
||||
}
|
||||
|
||||
if(note.getParagraph(paragraphId) == null) {
|
||||
throw new IllegalArgumentException(notebookId + " paragraph not found");
|
||||
}
|
||||
|
||||
note.run(paragraphId);
|
||||
return new JsonResponse(Status.ACCEPTED, null, note.getId()).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) {
|
||||
throw new IllegalArgumentException(notebookId + " note not found");
|
||||
}
|
||||
|
||||
Paragraph p = note.getParagraph(paragraphId);
|
||||
if(p == null) {
|
||||
throw new IllegalArgumentException(notebookId + " paragraph not found");
|
||||
}
|
||||
p.abort();
|
||||
return new JsonResponse(Status.ACCEPTED, "", note.getId()).build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,6 +294,21 @@ public class Note implements Serializable, JobListener {
|
|||
}
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue