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
*/
@PUT
public Response putCredentials(String message) {
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 (StringUtils.isEmpty(entity) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
return new JsonResponse<>(Status.BAD_REQUEST).build();
}
String user = authenticationService.getPrincipal();
LOGGER.info("Update credentials for user {} entity {}", user, entity);
UserCredentials uc;
try {
uc = credentials.getUserCredentials(user);
uc.putUsernamePassword(entity, new UsernamePassword(username, password));
credentials.putUserCredentials(user, uc);
return new JsonResponse<>(Status.OK).build();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class CredentialRestApi method getCredentials.
/**
* Get User Credentials list REST API.
*
* @return JSON with status.OK
*/
@GET
public Response getCredentials() {
String user = authenticationService.getPrincipal();
LOGGER.info("getCredentials for user {} ", user);
UserCredentials uc;
try {
uc = credentials.getUserCredentials(user);
return new JsonResponse<>(Status.OK, uc).build();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class InterpreterRestApi method installInterpreter.
/**
* Install interpreter
*/
@POST
@Path("install")
@ZeppelinApi
public Response installInterpreter(@NotNull String message) {
LOGGER.info("Install interpreter: {}", message);
InterpreterInstallationRequest request = InterpreterInstallationRequest.fromJson(message);
try {
interpreterService.installInterpreter(request, new SimpleServiceCallback<String>() {
@Override
public void onStart(String message, ServiceContext context) {
Message m = new Message(OP.INTERPRETER_INSTALL_STARTED);
Map<String, Object> data = new HashMap<>();
data.put("result", "Starting");
data.put("message", message);
m.data = data;
notebookServer.broadcast(m);
}
@Override
public void onSuccess(String message, ServiceContext context) {
Message m = new Message(OP.INTERPRETER_INSTALL_RESULT);
Map<String, Object> data = new HashMap<>();
data.put("result", "Succeed");
data.put("message", message);
m.data = data;
notebookServer.broadcast(m);
}
@Override
public void onFailure(Exception ex, ServiceContext context) {
Message m = new Message(OP.INTERPRETER_INSTALL_RESULT);
Map<String, Object> data = new HashMap<>();
data.put("result", "Failed");
data.put("message", ex.getMessage());
m.data = data;
notebookServer.broadcast(m);
}
});
} catch (Throwable t) {
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, t.getMessage()).build();
}
return new JsonResponse<>(Status.OK).build();
}
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 = NewInterpreterSettingRequest.fromJson(message);
if (request == null) {
return new JsonResponse<>(Status.BAD_REQUEST).build();
}
InterpreterSetting interpreterSetting = interpreterSettingManager.createNewSetting(request.getName(), request.getGroup(), request.getDependencies(), request.getOption(), request.getProperties());
LOGGER.info("new setting created with {}", interpreterSetting.getId());
return new JsonResponse<>(Status.OK, "", interpreterSetting).build();
} catch (IOException e) {
LOGGER.error("Exception in InterpreterRestApi while creating ", e);
return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
}
}
use of org.apache.zeppelin.server.JsonResponse in project zeppelin by apache.
the class HeliumRestApi method load.
@POST
@Path("load/{noteId}/{paragraphId}")
public Response load(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, String heliumPackage) {
try {
return notebook.processNote(noteId, note -> {
if (note == null) {
return new JsonResponse<>(Response.Status.NOT_FOUND, "Note " + noteId + " not found").build();
}
Paragraph paragraph = note.getParagraph(paragraphId);
if (paragraph == null) {
return new JsonResponse<>(Response.Status.NOT_FOUND, "Paragraph " + paragraphId + " not found").build();
}
HeliumPackage pkg = HeliumPackage.fromJson(heliumPackage);
try {
return new JsonResponse<>(Response.Status.OK, "", helium.getApplicationFactory().loadAndRun(pkg, paragraph)).build();
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
return new JsonResponse<>(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage()).build();
}
});
} catch (IOException e) {
return new JsonResponse<>(Response.Status.NOT_FOUND, "Fail to get note: " + noteId + "\n" + ExceptionUtils.getStackTrace(e)).build();
}
}
Aggregations