Search in sources :

Example 1 with DatasetSharedWith

use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith 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 2 with DatasetSharedWith

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

the class DatasetBuilder method datasetSharedWithItems.

// create dto from a list of DatasetSharedWith objects
private DatasetDTO datasetSharedWithItems(DatasetDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, Project accessProject, Users user, List<DatasetSharedWith> datasetSharedWithList, String parentPath, Users dirOwner) throws DatasetException, MetadataException, SchematizedTagException {
    if (datasetSharedWithList != null && !datasetSharedWithList.isEmpty()) {
        for (DatasetSharedWith datasetSharedWith : datasetSharedWithList) {
            DatasetPath datasetPath = datasetHelper.getTopLevelDatasetPath(accessProject, datasetSharedWith);
            dto.addItem(buildItems(uriInfo, resourceRequest, user, datasetPath, parentPath, dirOwner));
        }
    }
    return dto;
}
Also used : DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath)

Example 3 with DatasetSharedWith

use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith 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 4 with DatasetSharedWith

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

the class DatasetSharedWithFacade method findAllDatasetByProject.

public CollectionInfo findAllDatasetByProject(Integer offset, Integer limit, Set<? extends FilterBy> filter, Set<? extends SortBy> sort, Project project) {
    String queryStr = buildQuery("SELECT d FROM DatasetSharedWith d ", filter, sort, "d.project = :project ");
    String queryCountStr = buildQuery("SELECT COUNT(DISTINCT d.id) FROM DatasetSharedWith d ", filter, null, "d.project = :project ");
    Query query = em.createQuery(queryStr, DatasetSharedWith.class).setParameter("project", project);
    Query queryCount = em.createQuery(queryCountStr, DatasetSharedWith.class).setParameter("project", project);
    setFilter(filter, query, project);
    setFilter(filter, queryCount, project);
    setOffsetAndLim(offset, limit, query);
    return new CollectionInfo((Long) queryCount.getSingleResult(), query.getResultList());
}
Also used : Query(javax.persistence.Query) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith)

Example 5 with DatasetSharedWith

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

the class PathValidator method buildFullPath.

private void buildFullPath(Project project, String path, DsPath dsPath) throws DatasetException {
    // Strip leading slashes.
    while (path.startsWith("/")) {
        path = path.substring(1);
    }
    String[] pathComponents = path.split(File.separator);
    String dsName = pathComponents[0];
    boolean shared = false;
    String parentProjectPath = null;
    if (pathComponents[0].contains(Settings.SHARED_FILE_SEPARATOR)) {
        // we can split the string and get the project name
        String[] shardDS = pathComponents[0].split(Settings.SHARED_FILE_SEPARATOR);
        if (shardDS.length != 2) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
        }
        parentProjectPath = Utils.getProjectPath(shardDS[0]);
        dsName = shardDS[1];
        shared = true;
    }
    Dataset ds = datasetController.getByProjectAndDsName(project, parentProjectPath, dsName);
    if (ds == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
    }
    // If the dataset is shared, make sure that the user can access it
    if (shared) {
        DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(project, ds);
        if (datasetSharedWith != null && !datasetSharedWith.getAccepted()) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PENDING, Level.FINE, "datasetId: " + ds.getId());
        }
    }
    dsPath.setDs(ds);
    String dsRelativePathStr = buildRelativePath(pathComponents, 1, pathComponents.length);
    if (dsRelativePathStr.isEmpty()) {
        dsPath.setFullPath(datasetController.getDatasetPath(ds));
    } else {
        Path dsRelativePath = new Path(dsRelativePathStr);
        dsPath.setDsRelativePath(dsRelativePath);
        Path fullPath = new Path(datasetController.getDatasetPath(ds), dsRelativePath);
        dsPath.setFullPath(fullPath);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Aggregations

DatasetSharedWith (io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith)28 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)12 Project (io.hops.hopsworks.persistence.entity.project.Project)11 ArrayList (java.util.ArrayList)7 ProjectException (io.hops.hopsworks.exceptions.ProjectException)6 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)5 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)4 PermissionTransition (io.hops.hopsworks.persistence.entity.dataset.PermissionTransition)4 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)3 TransactionAttribute (javax.ejb.TransactionAttribute)3 Path (org.apache.hadoop.fs.Path)3 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)2 ServiceException (io.hops.hopsworks.exceptions.ServiceException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 Pair (io.hops.common.Pair)1 ModelRegistryDTO (io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO)1 ModelsBuilder (io.hops.hopsworks.api.modelregistry.models.ModelsBuilder)1