use of io.hops.hopsworks.persistence.entity.project.Project 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.persistence.entity.project.Project in project hopsworks by logicalclocks.
the class GrafanaProxyServlet method service.
@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
if (servletRequest.getUserPrincipal() == null || (!servletRequest.isUserInRole("HOPS_ADMIN") && !servletRequest.isUserInRole("HOPS_USER"))) {
servletResponse.sendError(403, "User is not logged in");
return;
}
if (servletRequest.getRequestURI().contains("query")) {
String email = servletRequest.getUserPrincipal().getName();
Users user = userFacade.findByEmail(email);
Matcher matcher = pattern.matcher(servletRequest.getQueryString());
if (matcher.find()) {
String appId = matcher.group(1);
YarnApplicationstate appState = yarnApplicationstateFacade.findByAppId(appId);
if (appState == null) {
servletResponse.sendError(Response.Status.BAD_REQUEST.getStatusCode(), "You don't have the access right for this application");
return;
}
String projectName = hdfsUsersBean.getProjectName(appState.getAppuser());
Project project = projectFacade.findByName(projectName);
if (project == null) {
servletResponse.sendError(Response.Status.BAD_REQUEST.getStatusCode(), "Project does not exists");
return;
}
if (!projectTeamFacade.isUserMemberOfProject(project, user)) {
servletResponse.sendError(Response.Status.BAD_REQUEST.getStatusCode(), "You don't have the access right for this application");
return;
}
} else {
boolean userRole = servletRequest.isUserInRole("HOPS_ADMIN");
if (!userRole) {
servletResponse.sendError(Response.Status.BAD_REQUEST.getStatusCode(), "You don't have the access right for this application");
return;
}
}
}
super.service(servletRequest, servletResponse);
}
use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.
the class ModelRegistryBuilder method build.
// Build collection
public ModelRegistryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project project) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
ModelRegistryDTO dto = new ModelRegistryDTO();
uri(dto, uriInfo, project);
expand(dto, resourceRequest);
Collection<Dataset> dsInProject = project.getDatasetCollection();
// Add all datasets shared with the project
dsInProject.addAll(project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).map(DatasetSharedWith::getDataset).collect(Collectors.toList()));
Collection<Dataset> modelsDatasets = dsInProject.stream().filter(ds -> ds.getName().equals(Settings.HOPS_MODELS_DATASET)).collect(Collectors.toList());
dto.setCount((long) modelsDatasets.size());
for (Dataset ds : modelsDatasets) {
ModelRegistryDTO modelRegistryDTO = build(uriInfo, resourceRequest, user, project, ds.getProject());
if (modelRegistryDTO != null) {
dto.addItem(modelRegistryDTO);
}
}
return dto;
}
use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.
the class AlertController method deleteRoute.
public void deleteRoute(FeatureGroupAlert alert) throws AlertManagerUnreachableException, AlertManagerAccessControlException, AlertManagerConfigUpdateException, AlertManagerConfigCtrlCreateException, AlertManagerConfigReadException, AlertManagerClientCreateException {
Project project = alert.getFeatureGroup().getFeaturestore().getProject();
Route route = ConfigUtil.getRoute(alert);
if (!isUsedByOtherAlerts(route, alert.getId())) {
alertManagerConfiguration.removeRoute(route, project);
}
}
use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.
the class AlertController method deleteRoute.
public void deleteRoute(JobAlert alert) throws AlertManagerUnreachableException, AlertManagerAccessControlException, AlertManagerConfigUpdateException, AlertManagerConfigCtrlCreateException, AlertManagerConfigReadException, AlertManagerClientCreateException {
Project project = alert.getJobId().getProject();
Route route = ConfigUtil.getRoute(alert);
if (!isUsedByOtherAlerts(route, alert.getId())) {
alertManagerConfiguration.removeRoute(route, project);
}
}
Aggregations