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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations