Search in sources :

Example 11 with DatasetSharedWith

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

the class DatasetController method share.

public void share(String targetProjectName, String fullPath, DatasetAccessPermission permission, Project project, Users user) throws DatasetException, ProjectException {
    Project targetProject = projectFacade.findByName(targetProjectName);
    Dataset ds = getByProjectAndFullPath(project, fullPath);
    if (targetProject == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Target project not found.");
    }
    DatasetSharedWith datasetSharedWith = shareInternal(targetProject, ds, user, permission);
    if (DatasetType.FEATURESTORE.equals(ds.getDsType()) && datasetSharedWith.getAccepted()) {
        Dataset trainingDataset = getTrainingDataset(project);
        if (trainingDataset != null) {
            try {
                shareInternal(targetProject, trainingDataset, user, permission);
            } catch (DatasetException de) {
            // Dataset already shared nothing to do
            }
        }
        // If we migrate Training Datasets to remove the project prefix, these methods can be reused
        shareFeatureStoreServiceDataset(user, project, targetProject, permission, Settings.ServiceDataset.STATISTICS);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 12 with DatasetSharedWith

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

the class DatasetController method shareInternal.

private DatasetSharedWith shareInternal(Project targetProject, Dataset ds, Users user, DatasetAccessPermission permission) throws DatasetException {
    DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(targetProject, ds);
    if (datasetSharedWith != null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DESTINATION_EXISTS, Level.FINE, "Dataset already in " + targetProject.getName());
    }
    // Create the new Dataset entry
    datasetSharedWith = new DatasetSharedWith(targetProject, ds, permission, false, user);
    // if the dataset is not requested or is requested by a data scientist set status to pending.
    DatasetRequest dsReq = datasetRequest.findByProjectAndDataset(targetProject, ds);
    if (ds.isPublicDs()) {
        if (targetProject.equals(ds.getProject())) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_ALREADY_IN_PROJECT, Level.FINE, "Dataset already in project.");
        }
        datasetSharedWith.setAccepted(true);
        datasetSharedWith.setAcceptedBy(user);
        addMembersToGroup(datasetSharedWith);
    } else if (dsReq != null && dsReq.getProjectTeam().getTeamRole().equals(AllowedRoles.DATA_OWNER)) {
        // dataset is private and requested by a data owner
        datasetSharedWith.setAccepted(true);
        datasetSharedWith.setAcceptedBy(dsReq.getProjectTeam().getUser());
        addMembersToGroup(datasetSharedWith);
    }
    datasetSharedWithFacade.save(datasetSharedWith);
    if (dsReq != null) {
        // the dataset is shared so remove the request.
        datasetRequest.remove(dsReq);
    }
    activityFacade.persistActivity(ActivityFacade.SHARED_DATA + ds.getName() + " with project " + targetProject.getName(), ds.getProject(), user, ActivityFlag.DATASET);
    return datasetSharedWith;
}
Also used : DatasetRequest(io.hops.hopsworks.persistence.entity.dataset.DatasetRequest) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 13 with DatasetSharedWith

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

the class DatasetController method unshare.

public void unshare(Project project, Users user, Dataset dataset, String targetProjectName, DistributedFileSystemOps dfso) throws DatasetException {
    Project targetProject = projectFacade.findByName(targetProjectName);
    if (targetProject == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.TARGET_PROJECT_NOT_FOUND, Level.FINE);
    }
    DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(targetProject, dataset);
    if (datasetSharedWith == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_SHARED_WITH_PROJECT, Level.FINE, "project: " + targetProject.getName());
    }
    if (DatasetType.FEATURESTORE.equals(datasetSharedWith.getDataset().getDsType())) {
        DatasetSharedWith trainingDataset = getSharedTrainingDataset(targetProject, datasetSharedWith.getDataset().getProject());
        if (trainingDataset != null) {
            unshareDs(project, user, trainingDataset, dfso);
        }
        unshareFeatureStoreServiceDataset(user, project, targetProject, datasetSharedWith, Settings.ServiceDataset.STATISTICS, dfso);
    }
    unshareDs(project, user, datasetSharedWith, dfso);
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 14 with DatasetSharedWith

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

the class PermissionsCleaner method fixPermission.

private void fixPermission(Dataset dataset, HdfsGroups hdfsDatasetGroup, HdfsGroups hdfsDatasetAclGroup, DistributedFileSystemOps dfso) throws IOException {
    if (hdfsDatasetGroup == null || hdfsDatasetAclGroup == null) {
        LOGGER.log(Level.WARNING, "Failed to get groups: {0} or {1}", new Object[] { hdfsDatasetGroup.getName(), hdfsDatasetAclGroup.getName() });
        return;
    }
    if (dataset.isPublicDs() && !DatasetAccessPermission.READ_ONLY.equals(dataset.getPermission())) {
        dataset.setPermission(DatasetAccessPermission.READ_ONLY);
        datasetFacade.merge(dataset);
    }
    List<ProjectTeam> datasetTeamCollection = new ArrayList<>();
    testFsPermission(dataset, dfso);
    testAndFixPermissionForAllMembers(dataset.getProject(), dfso, hdfsDatasetGroup, hdfsDatasetAclGroup, dataset.getInode().getHdfsUser(), dataset.getPermission());
    datasetTeamCollection.addAll(dataset.getProject().getProjectTeamCollection());
    for (DatasetSharedWith datasetSharedWith : dataset.getDatasetSharedWithCollection()) {
        if (dataset.isPublicDs() && !DatasetAccessPermission.READ_ONLY.equals(datasetSharedWith.getPermission())) {
            datasetSharedWith.setPermission(DatasetAccessPermission.READ_ONLY);
            datasetSharedWithFacade.update(datasetSharedWith);
        }
        if (datasetSharedWith.getAccepted()) {
            testAndFixPermissionForAllMembers(datasetSharedWith.getProject(), dfso, hdfsDatasetGroup, hdfsDatasetAclGroup, null, datasetSharedWith.getPermission());
            datasetTeamCollection.addAll(datasetSharedWith.getProject().getProjectTeamCollection());
        }
    }
    testAndRemoveUsersFromGroup(datasetTeamCollection, hdfsDatasetGroup, hdfsDatasetAclGroup, dataset.getInode().getHdfsUser(), dfso);
}
Also used : ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ArrayList(java.util.ArrayList)

Example 15 with DatasetSharedWith

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

the class DatasetHelper method getDatasetPath.

public DatasetPath getDatasetPath(Project project, String path, DatasetType datasetType) throws DatasetException {
    DatasetPath datasetPath = getNewDatasetPath(project, path, datasetType);
    Dataset dataset = datasetController.getByProjectAndFullPath(project, datasetPath.getDatasetFullPath().toString());
    datasetPath.setDataset(dataset);
    if (dataset != null && dataset.isShared(project)) {
        DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(project, dataset);
        datasetPath.setDatasetSharedWith(datasetSharedWith);
    }
    if (datasetPath.isTopLevelDataset()) {
        datasetPath.setInode(datasetPath.getDataset().getInode());
    } else {
        datasetPath.setInode(inodeController.getInodeAtPath(datasetPath.getDataset().getInode(), datasetPath.getDatasetFullPath().depth(), // expensive
        datasetPath.getDatasetRelativePath()));
    }
    return datasetPath;
}
Also used : Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith)

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