use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetController method updateSharePermission.
public void updateSharePermission(Dataset ds, DatasetAccessPermission datasetPermissions, Project project, String targetProjectName, Users user) throws DatasetException, ProjectException {
if (ds.isShared(project)) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_OWNER_ERROR, Level.FINE);
}
if (ds.isPublicDs()) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PUBLIC_IMMUTABLE, Level.FINE);
}
Project targetProject = projectFacade.findByName(targetProjectName);
if (targetProject == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Target project not " + "found.");
}
DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(targetProject, ds);
if (datasetSharedWith == null) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_SHARED_WITH_PROJECT, Level.FINE, "project: " + targetProject.getName());
}
PermissionTransition permissionTransition = PermissionTransition.valueOf(datasetSharedWith.getPermission(), datasetPermissions);
updateSharePermission(datasetSharedWith, permissionTransition, project, user);
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetController method getOrCreateSharedTrainingDataset.
private DatasetSharedWith getOrCreateSharedTrainingDataset(Project project, Project parentProject, DatasetAccessPermission permission, Users sharedBy) {
Dataset trainingDataset = getTrainingDataset(parentProject);
DatasetSharedWith sharedTrainingDataset = datasetSharedWithFacade.findByProjectAndDataset(project, trainingDataset);
if (sharedTrainingDataset == null) {
sharedTrainingDataset = new DatasetSharedWith(project, trainingDataset, permission, false, sharedBy);
datasetSharedWithFacade.save(sharedTrainingDataset);
sharedTrainingDataset = datasetSharedWithFacade.findByProjectAndDataset(project, trainingDataset);
}
return sharedTrainingDataset;
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetController method getAllByName.
/**
* @param project
* @param dsName
* @return The list of datasets that match the name, including the datasets shared with this project
*/
public List<Dataset> getAllByName(Project project, String dsName) {
List<Dataset> result = new ArrayList<>();
try {
Dataset nativeDataset = getByName(project, dsName);
result.add(nativeDataset);
} catch (DatasetException e) {
// not found, don't do anything
}
List<Dataset> sharedDatasets = project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).filter((sds) -> sds.getDataset().getName().equals(dsName)).map((sds) -> sds.getDataset()).collect(Collectors.toCollection(ArrayList::new));
result.addAll(sharedDatasets);
return result;
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetController method unshareDataset.
/**
* Unshares a dataset from the target project.
* @param targetProject
* @param dataset
* @throws IOException
*/
public void unshareDataset(Project project, Users user, Project targetProject, Dataset dataset) throws DatasetException {
DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(targetProject, dataset);
if (datasetSharedWith == null) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_SHARED_WITH_PROJECT, Level.FINE, "project: " + targetProject.getName());
}
unshareDs(project, user, dataset, datasetSharedWith);
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetController method makeImmutable.
public void makeImmutable(Dataset ds, Project project, Users user, Path path) throws DatasetException {
PermissionTransition permissionTransition = PermissionTransition.valueOf(ds.getPermission(), DatasetAccessPermission.READ_ONLY);
DistributedFileSystemOps dfso = null;
try {
dfso = dfs.getDfsOps();
hdfsUsersController.makeImmutable(path, dfso);
changePermissions(ds, permissionTransition, project, dfso);
List<DatasetSharedWith> sharedWith = datasetSharedWithFacade.findByDataset(ds);
for (DatasetSharedWith datasetSharedWith : sharedWith) {
updateSharePermission(datasetSharedWith, PermissionTransition.valueOf(datasetSharedWith.getPermission(), DatasetAccessPermission.READ_ONLY), project, user, dfso);
}
} catch (Exception e) {
// if rollback succeed remove DatasetPermissionOperation
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PERMISSION_ERROR, Level.FINE, e.getMessage());
} finally {
dfs.closeDfsClient(dfso);
}
}
Aggregations