use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class DelaProjectService method publish.
@POST
@Path("/uploads")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response publish(@Context SecurityContext sc, InodeIdDTO inodeId) throws DelaException {
Inode inode = getInode(inodeId.getId());
Dataset dataset = getDatasetByInode(inode);
Users user = jWTHelper.getUserPrincipal(sc);
delaWorkerCtrl.shareDatasetWithHops(project, dataset, user);
RESTApiJsonResponse json = new RESTApiJsonResponse();
json.setSuccessMessage("Dataset transfer is started - published");
return successResponse(json);
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class Monitor method serviceOp.
@POST
@Path("/groups/{groupName}/services/{serviceName}")
@RolesAllowed({ "HOPS_ADMIN" })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response serviceOp(@PathParam("groupName") String groupName, @PathParam("serviceName") String serviceName, ServicesActionDTO action, @Context SecurityContext sc) throws GenericException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
json.setSuccessMessage(hostServicesController.serviceOp(serviceName, action.getAction()));
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class Monitor method serviceOnHostOp.
@POST
@Path("/groups/{groupName}/services/{serviceName}/hosts/{hostId}")
@RolesAllowed({ "HOPS_ADMIN" })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response serviceOnHostOp(@PathParam("groupName") String groupName, @PathParam("serviceName") String serviceName, @PathParam("hostId") String hostId, ServicesActionDTO action, @Context SecurityContext sc) throws GenericException, ServiceException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
json.setSuccessMessage(hostServicesController.serviceOnHostOp(groupName, serviceName, hostId, action.getAction()));
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class RequestService method requestAccess.
@POST
@Path("/access")
@Produces(MediaType.APPLICATION_JSON)
public Response requestAccess(RequestDTO requestDTO, @Context SecurityContext sc) throws DatasetException, ProjectException {
RESTApiJsonResponse json = new RESTApiJsonResponse();
if (requestDTO == null || requestDTO.getInodeId() == null || requestDTO.getProjectId() == null) {
throw new IllegalArgumentException("requestDTO was not provided or was incomplete!");
}
Users user = jWTHelper.getUserPrincipal(sc);
Inode inode = inodes.findById(requestDTO.getInodeId());
// requested project
Project proj = datasetCtrl.getOwningProject(inode);
Dataset ds = datasetFacade.findByProjectAndInode(proj, inode);
// requesting project
Project project = projectFacade.find(requestDTO.getProjectId());
Dataset dsInRequesting = datasetFacade.findByProjectAndInode(project, inode);
if (dsInRequesting != null) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DESTINATION_EXISTS, Level.INFO);
}
ProjectTeam projectTeam = projectTeamFacade.findByPrimaryKey(project, user);
ProjectTeam projTeam = projectTeamFacade.findByPrimaryKey(proj, user);
if (projTeam != null && proj.equals(project)) {
throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_ALREADY_EXISTS, Level.FINE);
}
DatasetRequest dsRequest = datasetRequest.findByProjectAndDataset(project, ds);
// email body
String msg = "Hi " + proj.getOwner().getFname() + " " + proj.getOwner().getLname() + ", \n\n" + user.getFname() + " " + user.getLname() + " wants access to a dataset in a project you own. \n\n" + "Dataset name: " + ds.getInode().getInodePK().getName() + "\n" + "Project name: " + proj.getName() + "\n";
if (!Strings.isNullOrEmpty(requestDTO.getMessageContent())) {
msg += "Attached message: " + requestDTO.getMessageContent() + "\n";
}
msg += "After logging in to Hopsworks go to : /project/" + proj.getId() + "/datasets " + " if you want to share this dataset. \n";
// or the prior request is from a data owner do nothing.
if (dsRequest != null && (dsRequest.getProjectTeam().getTeamRole().equals(projectTeam.getTeamRole()) || dsRequest.getProjectTeam().getTeamRole().equals(AllowedProjectRoles.DATA_OWNER))) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_REQUEST_EXISTS, Level.FINE);
} else if (dsRequest != null && projectTeam.getTeamRole().equals(AllowedProjectRoles.DATA_OWNER)) {
dsRequest.setProjectTeam(projectTeam);
dsRequest.setMessageContent(requestDTO.getMessageContent());
datasetRequest.merge(dsRequest);
} else {
Users to = userFacade.findByEmail(proj.getOwner().getEmail());
String message = "Hi " + to.getFname() + "<br>" + "I would like to request access to a dataset in a project you own. <br>" + "Project name: " + proj.getName() + "<br>" + "Dataset name: " + ds.getInode().getInodePK().getName() + "<br>" + "To be shared with my project: " + project.getName() + ".<br>" + "Thank you in advance.";
String preview = user.getFname() + " would like to have access to a dataset in a project you own.";
String subject = Settings.MESSAGE_DS_REQ_SUBJECT;
String path = "project/" + proj.getId() + "/datasets";
// to, from, msg, requested path
Message newMsg = new Message(user, to, null, message, true, false);
newMsg.setPath(path);
newMsg.setSubject(subject);
newMsg.setPreview(preview);
messageBean.send(newMsg);
dsRequest = new DatasetRequest(ds, projectTeam, requestDTO.getMessageContent(), newMsg);
try {
datasetRequest.persistDataset(dsRequest);
} catch (Exception ex) {
messageBean.remove(newMsg);
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_REQUEST_ERROR, Level.WARNING, ex.getMessage(), null, ex);
}
}
try {
emailBean.sendEmail(proj.getOwner().getEmail(), RecipientType.TO, "Access request for dataset " + ds.getInode().getInodePK().getName(), msg);
} catch (MessagingException ex) {
json.setErrorMsg("Could not send e-mail to " + project.getOwner().getEmail());
datasetRequest.remove(dsRequest);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
json.setSuccessMessage("Request sent successfully.");
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
use of io.hops.hopsworks.api.util.RESTApiJsonResponse in project hopsworks by logicalclocks.
the class ProjectMembersService method updateRoleByEmail.
@POST
@Path("/{email}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response updateRoleByEmail(@PathParam("email") String email, @FormParam("role") String role, @Context SecurityContext sc) throws ProjectException, UserException, FeaturestoreException, IOException {
Project project = projectController.findProjectById(this.projectId);
RESTApiJsonResponse json = new RESTApiJsonResponse();
Users user = jWTHelper.getUserPrincipal(sc);
if (email == null) {
throw new IllegalArgumentException("Email was not provided.");
}
if (role == null || !ProjectRoleTypes.isAllowedRole(role)) {
throw new IllegalArgumentException("Role was not provided.");
}
if (project.getOwner().getEmail().equals(email)) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_OWNER_ROLE_NOT_ALLOWED, Level.FINE);
}
projectController.updateMemberRole(project, user, email, ProjectRoleTypes.fromString(role).getRole());
json.setSuccessMessage(ResponseMessages.MEMBER_ROLE_UPDATED);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
Aggregations