Search in sources :

Example 11 with Project

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();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) MessagingException(javax.mail.MessagingException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) Users(io.hops.hopsworks.persistence.entity.user.Users) MessagingException(javax.mail.MessagingException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) DatasetRequest(io.hops.hopsworks.persistence.entity.dataset.DatasetRequest) RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 12 with Project

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);
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Matcher(java.util.regex.Matcher) YarnApplicationstate(io.hops.hopsworks.persistence.entity.jobs.history.YarnApplicationstate) Users(io.hops.hopsworks.persistence.entity.user.Users)

Example 13 with Project

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;
}
Also used : Stateless(javax.ejb.Stateless) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO) ModelsBuilder(io.hops.hopsworks.api.modelregistry.models.ModelsBuilder) Collection(java.util.Collection) ModelRegistryException(io.hops.hopsworks.exceptions.ModelRegistryException) Collectors(java.util.stream.Collectors) Project(io.hops.hopsworks.persistence.entity.project.Project) Settings(io.hops.hopsworks.common.util.Settings) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) TransactionAttributeType(javax.ejb.TransactionAttributeType) GenericException(io.hops.hopsworks.exceptions.GenericException) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) MetadataException(io.hops.hopsworks.exceptions.MetadataException) TransactionAttribute(javax.ejb.TransactionAttribute) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriInfo(javax.ws.rs.core.UriInfo) Users(io.hops.hopsworks.persistence.entity.user.Users) EJB(javax.ejb.EJB) SchematizedTagException(io.hops.hopsworks.exceptions.SchematizedTagException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO)

Example 14 with Project

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);
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 15 with 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);
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Route(io.hops.hopsworks.alerting.config.dto.Route)

Aggregations

Project (io.hops.hopsworks.persistence.entity.project.Project)149 Users (io.hops.hopsworks.persistence.entity.user.Users)56 ProjectException (io.hops.hopsworks.exceptions.ProjectException)47 Produces (javax.ws.rs.Produces)39 Path (javax.ws.rs.Path)35 ArrayList (java.util.ArrayList)28 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)26 IOException (java.io.IOException)25 DatasetException (io.hops.hopsworks.exceptions.DatasetException)24 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)24 ApiOperation (io.swagger.annotations.ApiOperation)21 GET (javax.ws.rs.GET)20 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)19 TransactionAttribute (javax.ejb.TransactionAttribute)19 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)17 Featurestore (io.hops.hopsworks.persistence.entity.featurestore.Featurestore)16 List (java.util.List)16 EJB (javax.ejb.EJB)16 TransactionAttributeType (javax.ejb.TransactionAttributeType)16 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)14