Search in sources :

Example 11 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class InterpreterRestApi method removeSetting.

/**
   * Remove interpreter setting
   */
@DELETE
@Path("setting/{settingId}")
@ZeppelinApi
public Response removeSetting(@PathParam("settingId") String settingId) throws IOException {
    logger.info("Remove interpreterSetting {}", settingId);
    interpreterSettingManager.remove(settingId);
    return new JsonResponse(Status.OK).build();
}
Also used : JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 12 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi 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 13 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class NotebookRepoRestApi method updateRepoSetting.

/**
   * Update a specific note repo.
   *
   * @param message
   * @param settingId
   * @return
   */
@PUT
@ZeppelinApi
public Response updateRepoSetting(String payload) {
    if (StringUtils.isBlank(payload)) {
        return new JsonResponse<>(Status.NOT_FOUND, "", Collections.emptyMap()).build();
    }
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    NotebookRepoSettingsRequest newSettings = NotebookRepoSettingsRequest.EMPTY;
    try {
        newSettings = gson.fromJson(payload, NotebookRepoSettingsRequest.class);
    } catch (JsonSyntaxException e) {
        LOG.error("Cannot update notebook repo settings", e);
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload structure")).build();
    }
    if (NotebookRepoSettingsRequest.isEmpty(newSettings)) {
        LOG.error("Invalid property");
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload")).build();
    }
    LOG.info("User {} is going to change repo setting", subject.getUser());
    NotebookRepoWithSettings updatedSettings = noteRepos.updateNotebookRepo(newSettings.name, newSettings.settings, subject);
    if (!updatedSettings.isEmpty()) {
        LOG.info("Broadcasting note list to user {}", subject.getUser());
        notebookWsServer.broadcastReloadedNoteList(subject, null);
    }
    return new JsonResponse<>(Status.OK, "", updatedSettings).build();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) NotebookRepoWithSettings(org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings) NotebookRepoSettingsRequest(org.apache.zeppelin.rest.message.NotebookRepoSettingsRequest) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 14 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi 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 15 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi 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

ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)45 Path (javax.ws.rs.Path)35 Note (org.apache.zeppelin.notebook.Note)22 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)16 JsonResponse (org.apache.zeppelin.server.JsonResponse)15 GET (javax.ws.rs.GET)13 POST (javax.ws.rs.POST)13 Paragraph (org.apache.zeppelin.notebook.Paragraph)11 DELETE (javax.ws.rs.DELETE)6 PUT (javax.ws.rs.PUT)6 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ResourcePool (org.apache.zeppelin.resource.ResourcePool)4 Map (java.util.Map)3 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)3 Properties (java.util.Properties)2 Subject (org.apache.shiro.subject.Subject)2 NotebookRepoWithSettings (org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings)2