Search in sources :

Example 1 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookRestApi method getNoteJobStatus.

/**
   * Get note job status REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@GET
@Path("job/{noteId}")
@ZeppelinApi
public Response getNoteJobStatus(@PathParam("noteId") String noteId) throws IOException, IllegalArgumentException {
    LOG.info("get note job status.");
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanRead(noteId, "Insufficient privileges you cannot get job status");
    return new JsonResponse<>(Status.OK, null, note.generateParagraphsInfo()).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 2 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookRestApi method getNote.

@GET
@Path("{noteId}")
@ZeppelinApi
public Response getNote(@PathParam("noteId") String noteId) throws IOException {
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanRead(noteId, "Insufficient privileges you cannot get this note");
    return new JsonResponse<>(Status.OK, "", note).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 3 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookRestApi method moveParagraph.

/**
   * Move paragraph REST API
   *
   * @param newIndex - new index to move
   * @return JSON with status.OK
   * @throws IOException
   */
@POST
@Path("{noteId}/paragraph/{paragraphId}/move/{newIndex}")
@ZeppelinApi
public Response moveParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, @PathParam("newIndex") String newIndex) throws IOException {
    LOG.info("move paragraph {} {} {}", noteId, paragraphId, newIndex);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot move paragraph");
    Paragraph p = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(p);
    try {
        note.moveParagraph(paragraphId, Integer.parseInt(newIndex), true);
        AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
        note.persist(subject);
        notebookServer.broadcastNote(note);
        return new JsonResponse(Status.OK, "").build();
    } catch (IndexOutOfBoundsException e) {
        LOG.error("Exception in NotebookRestApi while moveParagraph ", e);
        return new JsonResponse(Status.BAD_REQUEST, "paragraph's new index is out of bound").build();
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 4 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookRestApi method deleteNote.

/**
   * Delete note REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException
   */
@DELETE
@Path("{noteId}")
@ZeppelinApi
public Response deleteNote(@PathParam("noteId") String noteId) throws IOException {
    LOG.info("Delete note {} ", noteId);
    checkIfUserIsOwner(noteId, "Insufficient privileges you cannot delete this note");
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    if (!(noteId.isEmpty())) {
        Note note = notebook.getNote(noteId);
        if (note != null) {
            notebook.removeNote(noteId, subject);
        }
    }
    notebookServer.broadcastNoteList(subject, SecurityUtils.getRoles());
    return new JsonResponse<>(Status.OK, "").build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 5 with Note

use of org.apache.zeppelin.notebook.Note in project zeppelin by apache.

the class NotebookRestApi method registerCronJob.

/**
   * Register cron job REST API
   *
   * @param message - JSON with cron expressions.
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@POST
@Path("cron/{noteId}")
@ZeppelinApi
public Response registerCronJob(@PathParam("noteId") String noteId, String message) throws IOException, IllegalArgumentException {
    LOG.info("Register cron job note={} request cron msg={}", noteId, message);
    CronRequest request = gson.fromJson(message, CronRequest.class);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot set a cron job for this note");
    if (!CronExpression.isValidExpression(request.getCronString())) {
        return new JsonResponse<>(Status.BAD_REQUEST, "wrong cron expressions.").build();
    }
    Map<String, Object> config = note.getConfig();
    config.put("cron", request.getCronString());
    note.setConfig(config);
    notebook.refreshCron(note.getId());
    return new JsonResponse<>(Status.OK).build();
}
Also used : CronRequest(org.apache.zeppelin.rest.message.CronRequest) Note(org.apache.zeppelin.notebook.Note) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Aggregations

Note (org.apache.zeppelin.notebook.Note)142 Paragraph (org.apache.zeppelin.notebook.Paragraph)63 Test (org.junit.Test)63 Map (java.util.Map)35 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)31 IOException (java.io.IOException)24 Notebook (org.apache.zeppelin.notebook.Notebook)20 HashMap (java.util.HashMap)17 Message (org.apache.zeppelin.notebook.socket.Message)17 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)15 Path (javax.ws.rs.Path)13 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)13 NoteInfo (org.apache.zeppelin.notebook.NoteInfo)12 Gson (com.google.gson.Gson)11 TypeToken (com.google.gson.reflect.TypeToken)11 AngularObject (org.apache.zeppelin.display.AngularObject)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)9 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)9