Search in sources :

Example 1 with CronRequest

use of org.apache.zeppelin.rest.message.CronRequest 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)1 Path (javax.ws.rs.Path)1 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)1 Note (org.apache.zeppelin.notebook.Note)1 CronRequest (org.apache.zeppelin.rest.message.CronRequest)1