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);
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations