Search in sources :

Example 1 with ProjectTeam

use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.

the class DelaService method getContentsForUser.

@GET
@Path("/transfers")
@Produces(MediaType.APPLICATION_JSON)
public Response getContentsForUser(@Context SecurityContext sc, @QueryParam("filter") TransfersFilter filter) throws DelaException {
    if (!filter.equals(TransfersFilter.USER)) {
        throw new DelaException(RESTCodes.DelaErrorCode.ILLEGAL_ARGUMENT, Level.FINE, DelaException.Source.LOCAL, "not handling filter value:" + filter);
    }
    Users user = jWTHelper.getUserPrincipal(sc);
    List<ProjectTeam> teams = projectCtrl.findProjectByUser(user.getEmail());
    List<Integer> projectIds = new LinkedList<>();
    for (ProjectTeam t : teams) {
        projectIds.add(t.getProject().getId());
    }
    HopsContentsSummaryJSON.Contents resp = delaTransferCtrl.getContents(projectIds);
    List<UserContentsSummaryJSON> userContents = new ArrayList<>();
    Iterator<Map.Entry<Integer, ElementSummaryJSON[]>> it = resp.getContents().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Integer, ElementSummaryJSON[]> n = it.next();
        userContents.add(new UserContentsSummaryJSON(n.getKey(), n.getValue()));
    }
    GenericEntity<List<UserContentsSummaryJSON>> userContentsList = new GenericEntity<List<UserContentsSummaryJSON>>(userContents) {
    };
    return success(userContentsList);
}
Also used : ArrayList(java.util.ArrayList) Users(io.hops.hopsworks.persistence.entity.user.Users) DelaException(io.hops.hopsworks.exceptions.DelaException) LinkedList(java.util.LinkedList) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) GenericEntity(javax.ws.rs.core.GenericEntity) ElementSummaryJSON(io.hops.hopsworks.dela.old_dto.ElementSummaryJSON) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HopsContentsSummaryJSON(io.hops.hopsworks.dela.old_dto.HopsContentsSummaryJSON) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ProjectTeam

use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.

the class ModelsBuilder method buildFilter.

private Pair<ProvStateParamBuilder, ModelRegistryDTO> buildFilter(Project project, Project modelRegistryProject, Set<? extends AbstractFacade.FilterBy> filters) throws GenericException, ProvenanceException, DatasetException {
    ProvStateParamBuilder provFilesParamBuilder = new ProvStateParamBuilder();
    if (filters != null) {
        Users filterUser = null;
        Project filterUserProject = project;
        for (AbstractFacade.FilterBy filterBy : filters) {
            if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_EQ.name()) == 0) {
                provFilesParamBuilder.filterByXAttr(MODEL_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_LIKE.name()) == 0) {
                provFilesParamBuilder.filterLikeXAttr(MODEL_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.VERSION.name()) == 0) {
                provFilesParamBuilder.filterByXAttr(MODEL_SUMMARY_XATTR_NAME + ".version", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.ID_EQ.name()) == 0) {
                provFilesParamBuilder.filterByXAttr(MODEL_SUMMARY_XATTR_NAME + ".id", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.USER.name()) == 0) {
                try {
                    filterUser = userFacade.find(Integer.parseInt(filterBy.getValue()));
                } catch (NumberFormatException e) {
                    throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user id, found: " + filterBy.getValue());
                }
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.USER_PROJECT.name()) == 0) {
                try {
                    filterUserProject = projectFacade.find(Integer.parseInt(filterBy.getValue()));
                } catch (NumberFormatException e) {
                    throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user project id, found: " + filterBy.getValue());
                }
            } else {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Filter by - found: " + filterBy.getParam() + " expected:" + EnumSet.allOf(Filters.class));
            }
        }
        if (filterUser != null) {
            ProjectTeam member = projectTeamFacade.findByPrimaryKey(filterUserProject, filterUser);
            if (member == null) {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Selected user: " + filterUser.getUid() + " is not part of project:" + filterUserProject.getId());
            }
            String hdfsUserStr = hdfsUsersController.getHdfsUserName(filterUserProject, filterUser);
            HdfsUsers hdfsUsers = hdfsUsersFacade.findByName(hdfsUserStr);
            provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.USER_ID, hdfsUsers.getId().toString());
        }
    }
    ModelRegistryDTO modelRegistryDTO = modelsController.getModelRegistry(modelRegistryProject);
    provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.PROJECT_I_ID, modelRegistryDTO.getParentProject().getInode().getId()).filterByField(ProvStateParser.FieldsP.DATASET_I_ID, modelRegistryDTO.getDatasetInodeId());
    return Pair.with(provFilesParamBuilder, modelRegistryDTO);
}
Also used : ProvStateParamBuilder(io.hops.hopsworks.common.provenance.state.ProvStateParamBuilder) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Users(io.hops.hopsworks.persistence.entity.user.Users) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO) GenericException(io.hops.hopsworks.exceptions.GenericException) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)

Example 3 with ProjectTeam

use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam 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 4 with ProjectTeam

use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.

the class ExperimentsBuilder method buildFilter.

private Pair<ProvStateParamBuilder, Map<Long, ExperimentsEndpointDTO>> buildFilter(Project project, Set<? extends AbstractFacade.FilterBy> filters) throws ProvenanceException, GenericException, DatasetException {
    ProvStateParamBuilder provFilesParamBuilder = new ProvStateParamBuilder();
    Map<Long, ExperimentsEndpointDTO> selectedEndpoints = new HashMap<>();
    if (filters != null) {
        Users filterUser = null;
        Project filterUserProject = project;
        for (AbstractFacade.FilterBy filterBy : filters) {
            if (filterBy.getParam().compareToIgnoreCase(Filters.ENDPOINT_ID.name()) == 0) {
                ExperimentsEndpointDTO endpoint = verifyExperimentsEndpoint(project, filterBy.getValue());
                selectedEndpoints.put(endpoint.getParentProject().getInode().getId(), endpoint);
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_LIKE.name()) == 0) {
                provFilesParamBuilder.filterLikeXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.NAME_EQ.name()) == 0) {
                provFilesParamBuilder.filterByXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".name", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.DATE_START_LT.name()) == 0) {
                Long timestamp = getDate(filterBy.getField(), filterBy.getValue()).getTime();
                provFilesParamBuilder.filterByField(ProvStateParser.FieldsPF.CREATE_TIMESTAMP_LT, timestamp);
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.DATE_START_GT.name()) == 0) {
                Long timestamp = getDate(filterBy.getField(), filterBy.getValue()).getTime();
                provFilesParamBuilder.filterByField(ProvStateParser.FieldsPF.CREATE_TIMESTAMP_GT, timestamp);
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.USER.name()) == 0) {
                try {
                    filterUser = userFacade.find(Integer.parseInt(filterBy.getValue()));
                } catch (NumberFormatException e) {
                    throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user id, found: " + filterBy.getValue());
                }
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.USER_PROJECT.name()) == 0) {
                try {
                    filterUserProject = projectFacade.find(Integer.parseInt(filterBy.getValue()));
                } catch (NumberFormatException e) {
                    throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "expected int user project id, found: " + filterBy.getValue());
                }
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.STATE.name()) == 0) {
                provFilesParamBuilder.filterLikeXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".state", filterBy.getValue());
            } else if (filterBy.getParam().compareToIgnoreCase(Filters.ID_EQ.name()) == 0) {
                provFilesParamBuilder.filterByXAttr(EXPERIMENT_SUMMARY_XATTR_NAME + ".id", filterBy.getValue());
            } else {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Filter by - found: " + filterBy.getParam() + " expected:" + EnumSet.allOf(Filters.class));
            }
        }
        if (filterUser != null) {
            ProjectTeam member = projectTeamFacade.findByPrimaryKey(filterUserProject, filterUser);
            if (member == null) {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "Selected user: " + filterUser.getUid() + " is not part of project:" + filterUserProject.getId());
            }
            String hdfsUserStr = hdfsUsersController.getHdfsUserName(filterUserProject, filterUser);
            HdfsUsers hdfsUsers = hdfsUsersFacade.findByName(hdfsUserStr);
            provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.USER_ID, hdfsUsers.getId().toString());
        }
    }
    // an endpoint always has to be selected, if none provided, then all accessible endpoints are used
    if (selectedEndpoints.isEmpty()) {
        for (ExperimentsEndpointDTO endpoint : experimentsController.getExperimentsEndpoints(project)) {
            selectedEndpoints.put(endpoint.getParentProject().getInode().getId(), endpoint);
        }
    }
    for (ExperimentsEndpointDTO endpoint : selectedEndpoints.values()) {
        provFilesParamBuilder.filterByField(ProvStateParser.FieldsP.PROJECT_I_ID, endpoint.getParentProject().getInode().getId()).filterByField(ProvStateParser.FieldsP.DATASET_I_ID, endpoint.getDatasetInodeId());
    }
    return Pair.with(provFilesParamBuilder, selectedEndpoints);
}
Also used : HashMap(java.util.HashMap) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Users(io.hops.hopsworks.persistence.entity.user.Users) GenericException(io.hops.hopsworks.exceptions.GenericException) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) ProvStateParamBuilder(io.hops.hopsworks.common.provenance.state.ProvStateParamBuilder) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) ExperimentsEndpointDTO(io.hops.hopsworks.api.experiments.dto.ExperimentsEndpointDTO)

Example 5 with ProjectTeam

use of io.hops.hopsworks.persistence.entity.project.team.ProjectTeam in project hopsworks by logicalclocks.

the class ProjectMembersService method getDatasetMembers.

@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@Path("/dataset/{name}")
public Response getDatasetMembers(@PathParam("name") String dsName, @QueryParam("type") DatasetType datasetType) throws ProjectException, DatasetException {
    Project project = projectController.findProjectById(this.projectId);
    String path = Utils.getProjectPath(project.getName()) + dsName;
    DatasetPath dp = datasetHelper.getDatasetPath(project, path, datasetType);
    Collection<ProjectTeam> membersCol = accessCtrl.getExtendedMembers(dp.getDataset());
    GenericEntity<Collection<ProjectTeam>> members = new GenericEntity<Collection<ProjectTeam>>(membersCol) {
    };
    return Response.ok().entity(members).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) GenericEntity(javax.ws.rs.core.GenericEntity) Collection(java.util.Collection) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)30 Users (io.hops.hopsworks.persistence.entity.user.Users)13 Project (io.hops.hopsworks.persistence.entity.project.Project)11 ArrayList (java.util.ArrayList)10 ProjectException (io.hops.hopsworks.exceptions.ProjectException)9 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)8 IOException (java.io.IOException)7 GenericException (io.hops.hopsworks.exceptions.GenericException)6 Date (java.util.Date)6 UserException (io.hops.hopsworks.exceptions.UserException)5 Produces (javax.ws.rs.Produces)5 DatasetException (io.hops.hopsworks.exceptions.DatasetException)4 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)4 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)4 KafkaException (io.hops.hopsworks.exceptions.KafkaException)4 ServiceException (io.hops.hopsworks.exceptions.ServiceException)4 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)4 Path (javax.ws.rs.Path)4 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)3 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)3