Search in sources :

Example 11 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class ConfigurationsRestApi method getByPrefix.

@GET
@Path("prefix/{prefix}")
@ZeppelinApi
public Response getByPrefix(@PathParam("prefix") final String prefix) {
    ZeppelinConfiguration conf = notebook.getConf();
    Map<String, String> configurations = conf.dumpConfigurations(conf, new ZeppelinConfiguration.ConfigurationKeyPredicate() {

        @Override
        public boolean apply(String key) {
            return !key.contains("password") && !key.equals(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING.getVarName()) && key.startsWith(prefix);
        }
    });
    return new JsonResponse(Status.OK, "", configurations).build();
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 12 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.

the class InterpreterRestApi method addRepository.

/**
   * Add new repository
   *
   * @param message Repository
   */
@POST
@Path("repository")
@ZeppelinApi
public Response addRepository(String message) {
    try {
        Repository request = gson.fromJson(message, Repository.class);
        interpreterSettingManager.addRepository(request.getId(), request.getUrl(), request.isSnapshot(), request.getAuthentication(), request.getProxy());
        logger.info("New repository {} added", request.getId());
    } catch (Exception e) {
        logger.error("Exception in InterpreterRestApi while adding repository ", e);
        return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    }
    return new JsonResponse(Status.OK).build();
}
Also used : Repository(org.apache.zeppelin.dep.Repository) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) IOException(java.io.IOException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 13 with JsonResponse

use of org.apache.zeppelin.server.JsonResponse 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 14 with JsonResponse

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

use of org.apache.zeppelin.server.JsonResponse 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)

Aggregations

JsonResponse (org.apache.zeppelin.server.JsonResponse)21 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)15 Path (javax.ws.rs.Path)13 POST (javax.ws.rs.POST)6 IOException (java.io.IOException)5 Note (org.apache.zeppelin.notebook.Note)5 PUT (javax.ws.rs.PUT)4 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)4 GET (javax.ws.rs.GET)3 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)3 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)3 UserCredentials (org.apache.zeppelin.user.UserCredentials)3 DELETE (javax.ws.rs.DELETE)2 Subject (org.apache.shiro.subject.Subject)2 JsonParseException (com.google.gson.JsonParseException)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 TypeToken (com.google.gson.reflect.TypeToken)1 HashMap (java.util.HashMap)1