Search in sources :

Example 1 with Project

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

the class DatasetAccessController method getProjectWithCache.

private Pair<Project, String> getProjectWithCache(Users user, Integer projectId, ShortLivedCache cache) {
    if (cache.projectCache.containsKey(projectId)) {
        return cache.projectCache.get(projectId);
    } else {
        Project project = projectFacade.find(projectId);
        if (project == null) {
            return null;
        }
        String projectRole = projectTeamFacade.findCurrentRole(project, user);
        cache.projectCache.put(project.getId(), Pair.with(project, projectRole));
        return Pair.with(project, projectRole);
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project)

Example 2 with Project

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

the class DatasetAccessController method accessorProjects.

private void accessorProjects(Users user, DatasetDetails datasetDetails, ProjectsCollector collector, ShortLivedCache cache) {
    // <project, userProjectRole>
    Pair<Project, String> projectAux = getProjectWithCache(user, datasetDetails.getParentProjectId(), cache);
    // check if parent project and parent dataset still exist or is this a stale item
    if (projectAux == null) {
        LOGGER.log(Level.FINE, "parent project of item - not found - probably stale item:{0}", datasetDetails);
        return;
    }
    Dataset dataset = getDatasetWithCache(projectAux.getValue0(), datasetDetails.getParentDatasetIId(), cache);
    if (dataset == null) {
        LOGGER.log(Level.FINE, "parent dataset of item - not found - probably stale item:{0}", datasetDetails);
        return;
    }
    // check parent project for access
    if (projectAux.getValue1() != null) {
        collector.addAccessProject(projectAux.getValue0());
    }
    // check shared datasets for access
    checkSharedDatasetsAccess(user, dataset, collector, cache);
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset)

Example 3 with Project

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

the class DatasetAccessController method checkSharedDatasetsAccess.

private void checkSharedDatasetsAccess(Users user, Dataset dataset, ProjectsCollector collector, ShortLivedCache cache) {
    if (cache.sharedWithProjectsCache.containsKey(dataset.getInodeId())) {
        // cached
        Set<Integer> projectIds = cache.sharedWithProjectsCache.get(dataset.getInodeId());
        for (Integer projectId : projectIds) {
            Pair<Project, String> projectAux = getProjectWithCache(user, projectId, cache);
            if (projectAux != null && projectAux.getValue1() != null) {
                collector.addAccessProject(projectAux.getValue0());
            }
        }
    } else {
        // not yet cached
        List<DatasetSharedWith> dsSharedWith = dsSharedWithFacade.findByDataset(dataset);
        Set<Integer> projectIds = new HashSet<>();
        cache.sharedWithProjectsCache.put(dataset.getInodeId(), projectIds);
        for (DatasetSharedWith ds : dsSharedWith) {
            projectIds.add(ds.getProject().getId());
            Pair<Project, String> projectAux = getProjectWithCache(user, ds.getProject(), cache);
            if (projectAux != null && projectAux.getValue1() != null) {
                collector.addAccessProject(projectAux.getValue0());
            }
        }
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) HashSet(java.util.HashSet)

Example 4 with Project

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

the class DatasetResource method getByPath.

@GET
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get or list files in path.", response = InodeDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_VIEW }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getByPath(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Get action, @QueryParam("mode") FilePreviewMode mode, @BeanParam Pagination pagination, @BeanParam InodeBeanParam inodeBeanParam, @BeanParam DatasetExpansionBeanParam datasetExpansionBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ProjectException, MetadataException, SchematizedTagException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.INODES);
    resourceRequest.setExpansions(datasetExpansionBeanParam.getResources());
    Project project = this.getProject();
    DatasetPath datasetPath = datasetHelper.getDatasetPathIfFileExist(project, path, datasetType);
    InodeDTO dto;
    switch(action == null ? DatasetActions.Get.STAT : action) {
        case BLOB:
            dto = inodeBuilder.buildBlob(uriInfo, resourceRequest, user, datasetPath, mode);
            break;
        case LISTING:
            resourceRequest.setOffset(pagination.getOffset());
            resourceRequest.setLimit(pagination.getLimit());
            resourceRequest.setSort(inodeBeanParam.getSortBySet());
            resourceRequest.setFilter(inodeBeanParam.getFilter());
            dto = inodeBuilder.buildItems(uriInfo, resourceRequest, user, datasetPath);
            break;
        case STAT:
            if (datasetPath.isTopLevelDataset()) {
                ResourceRequest datasetResourceRequest = new ResourceRequest(ResourceRequest.Name.DATASET);
                datasetResourceRequest.setExpansions(datasetExpansionBeanParam.getResources());
                DatasetDTO datasetDTO = datasetBuilder.build(uriInfo, datasetResourceRequest, user, datasetPath, null, null, true);
                return Response.ok().entity(datasetDTO).build();
            } else {
                dto = inodeBuilder.buildStat(uriInfo, resourceRequest, user, datasetPath);
            }
            break;
        default:
            throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
    }
    return Response.ok().entity(dto).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) WebApplicationException(javax.ws.rs.WebApplicationException) InodeDTO(io.hops.hopsworks.api.dataset.inode.InodeDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 5 with Project

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

the class DatasetResource method delete.

@DELETE
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@ApiOperation(value = "Delete/unshare dataset")
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_DELETE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response delete(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Delete action, @QueryParam("target_project") String targetProject, @Context SecurityContext sc) throws DatasetException, ProjectException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(this.getProject(), path, datasetType);
    Users user = jwtHelper.getUserPrincipal(sc);
    Project project = this.getProject();
    if (action == null) {
        datasetController.delete(project, user, datasetPath.getFullPath(), datasetPath.getDataset(), datasetPath.isTopLevelDataset());
    } else {
        switch(action) {
            case UNSHARE:
                checkIfDataOwner(project, user);
                datasetController.unshare(project, user, datasetPath.getDataset(), targetProject);
                break;
            case CORRUPTED:
                if (datasetPath.isTopLevelDataset()) {
                    throw new IllegalArgumentException("Use DELETE /{datasetName} to delete top level dataset)");
                }
                datasetController.deleteCorrupted(project, user, datasetPath.getFullPath(), datasetPath.getDataset());
                break;
            default:
                throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
        }
    }
    return Response.noContent().build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) WebApplicationException(javax.ws.rs.WebApplicationException) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

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