Search in sources :

Example 26 with ZeppelinApi

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

the class NotebookRestApi method stopParagraph.

/**
   * Stop(delete) paragraph job REST API
   *
   * @param noteId  ID of Note
   * @param paragraphId ID of Paragraph
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@DELETE
@Path("job/{noteId}/{paragraphId}")
@ZeppelinApi
public Response stopParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId) throws IOException, IllegalArgumentException {
    LOG.info("stop paragraph job {} ", noteId);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot stop paragraph");
    Paragraph p = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(p);
    p.abort();
    return new JsonResponse<>(Status.OK).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 27 with ZeppelinApi

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

the class NotebookRestApi method runNoteJobs.

/**
   * Run note jobs REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@POST
@Path("job/{noteId}")
@ZeppelinApi
public Response runNoteJobs(@PathParam("noteId") String noteId) throws IOException, IllegalArgumentException {
    LOG.info("run note jobs {} ", noteId);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot run job for this note");
    try {
        note.runAll();
    } catch (Exception ex) {
        LOG.error("Exception from run", ex);
        return new JsonResponse<>(Status.PRECONDITION_FAILED, ex.getMessage() + "- Not selected or Invalid Interpreter bind").build();
    }
    return new JsonResponse<>(Status.OK).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) IOException(java.io.IOException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) BadRequestException(org.apache.zeppelin.rest.exception.BadRequestException) NotFoundException(org.apache.zeppelin.rest.exception.NotFoundException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 28 with ZeppelinApi

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

the class InterpreterRestApi method restartSetting.

/**
   * Restart interpreter setting
   */
@PUT
@Path("setting/restart/{settingId}")
@ZeppelinApi
public Response restartSetting(String message, @PathParam("settingId") String settingId) {
    logger.info("Restart interpreterSetting {}, msg={}", settingId, message);
    InterpreterSetting setting = interpreterSettingManager.get(settingId);
    try {
        RestartInterpreterRequest request = gson.fromJson(message, RestartInterpreterRequest.class);
        String noteId = request == null ? null : request.getNoteId();
        if (null == noteId) {
            interpreterSettingManager.close(setting);
        } else {
            interpreterSettingManager.restart(settingId, noteId, SecurityUtils.getPrincipal());
        }
        notebookServer.clearParagraphRuntimeInfo(setting);
    } catch (InterpreterException e) {
        logger.error("Exception in InterpreterRestApi while restartSetting ", e);
        return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    }
    if (setting == null) {
        return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build();
    }
    return new JsonResponse<>(Status.OK, "", setting).build();
}
Also used : RestartInterpreterRequest(org.apache.zeppelin.rest.message.RestartInterpreterRequest) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 29 with ZeppelinApi

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

the class NotebookRestApi method putNotePermissions.

/**
   * set note authorization information
   */
@PUT
@Path("{noteId}/permissions")
@ZeppelinApi
public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException {
    String principal = SecurityUtils.getPrincipal();
    HashSet<String> roles = SecurityUtils.getRoles();
    HashSet<String> userAndRoles = new HashSet<>();
    userAndRoles.add(principal);
    userAndRoles.addAll(roles);
    checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
    checkIfUserIsOwner(noteId, ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));
    HashMap<String, HashSet<String>> permMap = gson.fromJson(req, new TypeToken<HashMap<String, HashSet<String>>>() {
    }.getType());
    Note note = notebook.getNote(noteId);
    LOG.info("Set permissions {} {} {} {} {}", noteId, principal, permMap.get("owners"), permMap.get("readers"), permMap.get("writers"));
    HashSet<String> readers = permMap.get("readers");
    HashSet<String> owners = permMap.get("owners");
    HashSet<String> writers = permMap.get("writers");
    // Set readers, if writers and owners is empty -> set to user requesting the change
    if (readers != null && !readers.isEmpty()) {
        if (writers.isEmpty()) {
            writers = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
        if (owners.isEmpty()) {
            owners = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
    }
    // Set writers, if owners is empty -> set to user requesting the change
    if (writers != null && !writers.isEmpty()) {
        if (owners.isEmpty()) {
            owners = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
    }
    notebookAuthorization.setReaders(noteId, readers);
    notebookAuthorization.setWriters(noteId, writers);
    notebookAuthorization.setOwners(noteId, owners);
    LOG.debug("After set permissions {} {} {}", notebookAuthorization.getOwners(noteId), notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId));
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    note.persist(subject);
    notebookServer.broadcastNote(note);
    notebookServer.broadcastNoteList(subject, userAndRoles);
    return new JsonResponse<>(Status.OK).build();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 30 with ZeppelinApi

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

the class NotebookRestApi method insertParagraph.

/**
   * Insert paragraph REST API
   *
   * @param message - JSON containing paragraph's information
   * @return JSON with status.OK
   * @throws IOException
   */
@POST
@Path("{noteId}/paragraph")
@ZeppelinApi
public Response insertParagraph(@PathParam("noteId") String noteId, String message) throws IOException {
    LOG.info("insert paragraph {} {}", noteId, message);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot add paragraph to this note");
    NewParagraphRequest request = gson.fromJson(message, NewParagraphRequest.class);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    Paragraph p;
    Double indexDouble = request.getIndex();
    if (indexDouble == null) {
        p = note.addParagraph(subject);
    } else {
        p = note.insertParagraph(indexDouble.intValue(), subject);
    }
    p.setTitle(request.getTitle());
    p.setText(request.getText());
    note.persist(subject);
    notebookServer.broadcastNote(note);
    return new JsonResponse<>(Status.OK, "", p.getId()).build();
}
Also used : 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)

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