Search in sources :

Example 1 with PermissionTransition

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);
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) PermissionTransition(io.hops.hopsworks.persistence.entity.dataset.PermissionTransition) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 2 with PermissionTransition

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);
    }
}
Also used : PermissionTransition(io.hops.hopsworks.persistence.entity.dataset.PermissionTransition) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 3 with PermissionTransition

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);
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) PermissionTransition(io.hops.hopsworks.persistence.entity.dataset.PermissionTransition) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 4 with PermissionTransition

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);
    }
}
Also used : PermissionTransition(io.hops.hopsworks.persistence.entity.dataset.PermissionTransition) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) ProjectException(io.hops.hopsworks.exceptions.ProjectException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) FileNotFoundException(java.io.FileNotFoundException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) AccessControlException(org.apache.hadoop.security.AccessControlException) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Aggregations

DatasetException (io.hops.hopsworks.exceptions.DatasetException)4 PermissionTransition (io.hops.hopsworks.persistence.entity.dataset.PermissionTransition)4 ProjectException (io.hops.hopsworks.exceptions.ProjectException)3 DatasetSharedWith (io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith)3 Project (io.hops.hopsworks.persistence.entity.project.Project)2 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)1 ServiceException (io.hops.hopsworks.exceptions.ServiceException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1