Search in sources :

Example 16 with JsonResponse

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

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

the class CredentialRestApi method removeCredentials.

/**
  * Remove User Credentials REST API
  * @param
  * @return JSON with status.OK
  * @throws IOException, IllegalArgumentException
  */
@DELETE
public Response removeCredentials(String message) throws IOException, IllegalArgumentException {
    String user = SecurityUtils.getPrincipal();
    logger.info("removeCredentials credentials for user {} ", user);
    UserCredentials uc = credentials.removeUserCredentials(user);
    if (uc == null) {
        return new JsonResponse(Status.NOT_FOUND).build();
    }
    return new JsonResponse(Status.OK).build();
}
Also used : UserCredentials(org.apache.zeppelin.user.UserCredentials) JsonResponse(org.apache.zeppelin.server.JsonResponse)

Example 18 with JsonResponse

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

the class CredentialRestApi method putCredentials.

/**
   * Put User Credentials REST API
   * @param message - JSON with entity, username, password.
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@PUT
public Response putCredentials(String message) throws IOException, IllegalArgumentException {
    Map<String, String> messageMap = gson.fromJson(message, new TypeToken<Map<String, String>>() {
    }.getType());
    String entity = messageMap.get("entity");
    String username = messageMap.get("username");
    String password = messageMap.get("password");
    if (Strings.isNullOrEmpty(entity) || Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password)) {
        return new JsonResponse(Status.BAD_REQUEST).build();
    }
    String user = SecurityUtils.getPrincipal();
    logger.info("Update credentials for user {} entity {}", user, entity);
    UserCredentials uc = credentials.getUserCredentials(user);
    uc.putUsernamePassword(entity, new UsernamePassword(username, password));
    credentials.putUserCredentials(user, uc);
    return new JsonResponse(Status.OK).build();
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) UserCredentials(org.apache.zeppelin.user.UserCredentials) JsonResponse(org.apache.zeppelin.server.JsonResponse) UsernamePassword(org.apache.zeppelin.user.UsernamePassword)

Example 19 with JsonResponse

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

the class HeliumRestApi method updatePackageConfig.

@POST
@Path("config/{packageName}/{artifact}")
public Response updatePackageConfig(@PathParam("packageName") String packageName, @PathParam("artifact") String artifact, String rawConfig) {
    if (StringUtils.isEmpty(packageName) || StringUtils.isEmpty(artifact)) {
        return new JsonResponse(Response.Status.BAD_REQUEST, "package name or artifact is empty").build();
    }
    Map<String, Object> packageConfig = null;
    try {
        packageConfig = gson.fromJson(rawConfig, new TypeToken<Map<String, Object>>() {
        }.getType());
        helium.updatePackageConfig(artifact, packageConfig);
    } catch (JsonParseException e) {
        logger.error(e.getMessage(), e);
        return new JsonResponse(Response.Status.BAD_REQUEST, e.getMessage()).build();
    } catch (IOException | RuntimeException e) {
        return new JsonResponse(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage()).build();
    }
    return new JsonResponse(Response.Status.OK, packageConfig).build();
}
Also used : IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) Map(java.util.Map) JsonResponse(org.apache.zeppelin.server.JsonResponse)

Example 20 with JsonResponse

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

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