Search in sources :

Example 16 with POST

use of javax.ws.rs.POST in project zeppelin by apache.

the class NotebookRestApi method runParagraph.

/**
   * Run asynchronously paragraph job REST API
   *
   * @param message - JSON with params if user wants to update dynamic form's value
   *                null, empty string, empty json if user doesn't want to update
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@POST
@Path("job/{noteId}/{paragraphId}")
@ZeppelinApi
public Response runParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, String message) throws IOException, IllegalArgumentException {
    LOG.info("run paragraph job asynchronously {} {} {}", noteId, paragraphId, message);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot run job for this note");
    Paragraph paragraph = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(paragraph);
    // handle params if presented
    handleParagraphParams(message, note, paragraph);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    paragraph.setAuthenticationInfo(subject);
    note.persist(subject);
    note.run(paragraph.getId());
    return new JsonResponse<>(Status.OK).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 17 with POST

use of javax.ws.rs.POST in project zeppelin by apache.

the class NotebookRestApi method createNote.

/**
   * Create new note REST API
   *
   * @param message - JSON with new note name
   * @return JSON with new note ID
   * @throws IOException
   */
@POST
@Path("/")
@ZeppelinApi
public Response createNote(String message) throws IOException {
    LOG.info("Create new note by JSON {}", message);
    NewNoteRequest request = gson.fromJson(message, NewNoteRequest.class);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    Note note = notebook.createNote(subject);
    List<NewParagraphRequest> initialParagraphs = request.getParagraphs();
    if (initialParagraphs != null) {
        for (NewParagraphRequest paragraphRequest : initialParagraphs) {
            Paragraph p = note.addParagraph(subject);
            p.setTitle(paragraphRequest.getTitle());
            p.setText(paragraphRequest.getText());
        }
    }
    // add one paragraph to the last
    note.addParagraph(subject);
    String noteName = request.getName();
    if (noteName.isEmpty()) {
        noteName = "Note " + note.getId();
    }
    note.setName(noteName);
    note.persist(subject);
    notebookServer.broadcastNote(note);
    notebookServer.broadcastNoteList(subject, SecurityUtils.getRoles());
    return new JsonResponse<>(Status.OK, "", note.getId()).build();
}
Also used : NewNoteRequest(org.apache.zeppelin.rest.message.NewNoteRequest) NewParagraphRequest(org.apache.zeppelin.rest.message.NewParagraphRequest) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 18 with POST

use of javax.ws.rs.POST 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 19 with POST

use of javax.ws.rs.POST in project zeppelin by apache.

the class LoginRestApi method logout.

@POST
@Path("logout")
@ZeppelinApi
public Response logout() {
    JsonResponse response;
    Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
    currentUser.logout();
    response = new JsonResponse(Response.Status.UNAUTHORIZED, "", "");
    LOG.warn(response.toString());
    return response.build();
}
Also used : JsonResponse(org.apache.zeppelin.server.JsonResponse) Subject(org.apache.shiro.subject.Subject) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 20 with POST

use of javax.ws.rs.POST 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

POST (javax.ws.rs.POST)513 Path (javax.ws.rs.Path)360 Consumes (javax.ws.rs.Consumes)242 Produces (javax.ws.rs.Produces)222 ApiOperation (io.swagger.annotations.ApiOperation)133 ApiResponses (io.swagger.annotations.ApiResponses)107 IOException (java.io.IOException)74 URI (java.net.URI)63 WebApplicationException (javax.ws.rs.WebApplicationException)62 Timed (com.codahale.metrics.annotation.Timed)55 Response (javax.ws.rs.core.Response)50 TimedResource (org.killbill.commons.metrics.TimedResource)36 CallContext (org.killbill.billing.util.callcontext.CallContext)35 AuditEvent (org.graylog2.audit.jersey.AuditEvent)33 HashMap (java.util.HashMap)32 BadRequestException (co.cask.cdap.common.BadRequestException)24 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Account (org.killbill.billing.account.api.Account)22 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)20