Search in sources :

Example 21 with ZeppelinApi

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

the class InterpreterRestApi method updateSetting.

@PUT
@Path("setting/{settingId}")
@ZeppelinApi
public Response updateSetting(String message, @PathParam("settingId") String settingId) {
    logger.info("Update interpreterSetting {}", settingId);
    try {
        UpdateInterpreterSettingRequest request = gson.fromJson(message, UpdateInterpreterSettingRequest.class);
        interpreterSettingManager.setPropertyAndRestart(settingId, request.getOption(), request.getProperties(), request.getDependencies());
    } catch (InterpreterException e) {
        logger.error("Exception in InterpreterRestApi while updateSetting ", e);
        return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    } catch (IOException e) {
        logger.error("Exception in InterpreterRestApi while updateSetting ", e);
        return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    }
    InterpreterSetting setting = interpreterSettingManager.get(settingId);
    if (setting == null) {
        return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build();
    }
    return new JsonResponse<>(Status.OK, "", setting).build();
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) UpdateInterpreterSettingRequest(org.apache.zeppelin.rest.message.UpdateInterpreterSettingRequest) IOException(java.io.IOException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 22 with ZeppelinApi

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

the class InterpreterRestApi method newSettings.

/**
   * Add new interpreter setting
   *
   * @param message NewInterpreterSettingRequest
   */
@POST
@Path("setting")
@ZeppelinApi
public Response newSettings(String message) {
    try {
        NewInterpreterSettingRequest request = gson.fromJson(message, NewInterpreterSettingRequest.class);
        if (request == null) {
            return new JsonResponse<>(Status.BAD_REQUEST).build();
        }
        Properties p = new Properties();
        p.putAll(request.getProperties());
        InterpreterSetting interpreterSetting = interpreterSettingManager.createNewSetting(request.getName(), request.getGroup(), request.getDependencies(), request.getOption(), p);
        logger.info("new setting created with {}", interpreterSetting.getId());
        return new JsonResponse<>(Status.OK, "", interpreterSetting).build();
    } catch (InterpreterException | IOException e) {
        logger.error("Exception in InterpreterRestApi while creating ", e);
        return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    }
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) NewInterpreterSettingRequest(org.apache.zeppelin.rest.message.NewInterpreterSettingRequest) IOException(java.io.IOException) Properties(java.util.Properties) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 23 with ZeppelinApi

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

the class LoginRestApi method postLogin.

/**
   * Post Login
   * Returns userName & password
   * for anonymous access, username is always anonymous.
   * After getting this ticket, access through websockets become safe
   *
   * @return 200 response
   */
@POST
@ZeppelinApi
public Response postLogin(@FormParam("userName") String userName, @FormParam("password") String password) {
    JsonResponse response = null;
    // ticket set to anonymous for anonymous user. Simplify testing.
    Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
    if (currentUser.isAuthenticated()) {
        currentUser.logout();
    }
    if (!currentUser.isAuthenticated()) {
        try {
            UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
            //      token.setRememberMe(true);
            currentUser.login(token);
            HashSet<String> roles = SecurityUtils.getRoles();
            String principal = SecurityUtils.getPrincipal();
            String ticket;
            if ("anonymous".equals(principal))
                ticket = "anonymous";
            else
                ticket = TicketContainer.instance.getTicket(principal);
            Map<String, String> data = new HashMap<>();
            data.put("principal", principal);
            data.put("roles", roles.toString());
            data.put("ticket", ticket);
            response = new JsonResponse(Response.Status.OK, "", data);
            //if no exception, that's it, we're done!
            //set roles for user in NotebookAuthorization module
            NotebookAuthorization.getInstance().setRoles(principal, roles);
        } catch (UnknownAccountException uae) {
            //username wasn't in the system, show them an error message?
            LOG.error("Exception in login: ", uae);
        } catch (IncorrectCredentialsException ice) {
            //password didn't match, try again?
            LOG.error("Exception in login: ", ice);
        } catch (LockedAccountException lae) {
            //account for that username is locked - can't login.  Show them a message?
            LOG.error("Exception in login: ", lae);
        } catch (AuthenticationException ae) {
            //unexpected condition - error?
            LOG.error("Exception in login: ", ae);
        }
    }
    if (response == null) {
        response = new JsonResponse(Response.Status.FORBIDDEN, "", "");
    }
    LOG.warn(response.toString());
    return response.build();
}
Also used : HashMap(java.util.HashMap) JsonResponse(org.apache.zeppelin.server.JsonResponse) Subject(org.apache.shiro.subject.Subject) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 24 with ZeppelinApi

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

the class NotebookRepoRestApi method listRepoSettings.

/**
   * List all notebook repository
   */
@GET
@ZeppelinApi
public Response listRepoSettings() {
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    LOG.info("Getting list of NoteRepo with Settings for user {}", subject.getUser());
    List<NotebookRepoWithSettings> settings = noteRepos.getNotebookRepos(subject);
    return new JsonResponse<>(Status.OK, "", settings).build();
}
Also used : NotebookRepoWithSettings(org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 25 with ZeppelinApi

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

the class NotebookRepoRestApi method refreshRepo.

/**
   * Reload notebook repository
   */
@GET
@Path("reload")
@ZeppelinApi
public Response refreshRepo() {
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    LOG.info("Reloading notebook repository for user {}", subject.getUser());
    notebookWsServer.broadcastReloadedNoteList(subject, null);
    return new JsonResponse<>(Status.OK, "", null).build();
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

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