use of io.hops.hopsworks.persistence.entity.dataset.PermissionTransition in project hopsworks by logicalclocks.
the class DatasetController method updateSharePermission.
public void updateSharePermission(Dataset ds, DatasetAccessPermission datasetPermissions, Project project, String targetProjectName, Users user, DistributedFileSystemOps dfso) 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, dfso);
}
use of io.hops.hopsworks.persistence.entity.dataset.PermissionTransition in project hopsworks by logicalclocks.
the class DatasetController method updatePermission.
public void updatePermission(Dataset ds, DatasetAccessPermission datasetPermissions, Project project, Project targetProject, Users user) throws DatasetException {
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);
}
PermissionTransition permissionTransition = PermissionTransition.valueOf(ds.getPermission(), datasetPermissions);
changePermissions(ds, permissionTransition, targetProject);
if (!permissionTransition.noop()) {
activityFacade.persistActivity(ActivityFacade.CHANGE_DATASET_PERMISSION + " of " + ds.getName() + " from " + permissionTransition.getFrom().getDescription() + " to " + permissionTransition.getTo().getDescription(), project, user, ActivityFlag.DATASET);
}
}
use of io.hops.hopsworks.persistence.entity.dataset.PermissionTransition 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.PermissionTransition 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