Search in sources :

Example 26 with DatasetSharedWith

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

the class DatasetController method getByProjectAndFullPath.

public Dataset getByProjectAndFullPath(Project project, String fullPath) throws DatasetException {
    Inode inode = inodeController.getInodeAtPath(fullPath);
    if (project == null || inode == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE, "path: " + fullPath);
    }
    Dataset dataset = datasetFacade.findByProjectAndInode(project, inode);
    if (dataset == null) {
        // not owned by project check shared
        dataset = datasetFacade.findByInode(inode);
        if (dataset == null) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE, "path: " + fullPath);
        }
        DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(project, dataset);
        if (datasetSharedWith == null) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE, "path: " + fullPath);
        }
        return datasetSharedWith.getDataset();
    }
    return dataset;
}
Also used : Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 27 with DatasetSharedWith

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

the class ProjectController method getProjectByName.

/**
 * Project info as data transfer object that can be sent to the user.
 *
 * @param name
 * @return project DTO that contains team members and services
 */
public ProjectDTO getProjectByName(String name) throws ProjectException {
    // find the project entity from hopsworks database
    Project project = projectFacade.findByName(name);
    if (project == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "project: " + name);
    }
    // find the project as an inode from hops database
    Inode inode = inodeController.getInodeAtPath(Utils.getProjectPath(name));
    List<ProjectTeam> projectTeam = projectTeamFacade.findMembersByProject(project);
    List<ProjectServiceEnum> projectServices = projectServicesFacade.findEnabledServicesForProject(project);
    List<String> services = new ArrayList<>();
    for (ProjectServiceEnum s : projectServices) {
        services.add(s.toString());
    }
    Inode parent;
    List<InodeView> kids = new ArrayList<>();
    Collection<Dataset> dsInProject = project.getDatasetCollection();
    Collection<DatasetSharedWith> dsSharedWithProject = project.getDatasetSharedWithCollection();
    for (Dataset ds : dsInProject) {
        parent = inodes.findParent(ds.getInode());
        kids.add(new InodeView(parent, ds, inodeController.getPath(ds.getInode())));
    }
    for (DatasetSharedWith ds : dsSharedWithProject) {
        parent = inodes.findParent(ds.getDataset().getInode());
        kids.add(new InodeView(parent, ds, inodeController.getPath(ds.getDataset().getInode())));
    }
    // send the project back to client
    return new ProjectDTO(project, inode.getId(), services, projectTeam, kids, projectUtils.dockerImageIsPreinstalled(project.getDockerImage()), projectUtils.isOldDockerImage(project.getDockerImage()));
}
Also used : InodeView(io.hops.hopsworks.persistence.entity.hdfs.inode.InodeView) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ArrayList(java.util.ArrayList) ProjectServiceEnum(io.hops.hopsworks.persistence.entity.project.service.ProjectServiceEnum) ProjectException(io.hops.hopsworks.exceptions.ProjectException) JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)

Example 28 with DatasetSharedWith

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

the class ProjectController method fixSharedDatasets.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void fixSharedDatasets(Project project, DistributedFileSystemOps dfso) throws IOException {
    List<DatasetSharedWith> sharedDataSets = datasetSharedWithFacade.findByProject(project);
    for (DatasetSharedWith dataSet : sharedDataSets) {
        String owner = dataSet.getDataset().getInode().getHdfsUser().getName();
        String group = dataSet.getDataset().getInode().getHdfsGroup().getName();
        List<Inode> children = new ArrayList<>();
        inodeController.getAllChildren(dataSet.getDataset().getInode(), children);
        for (Inode child : children) {
            if (child.getHdfsUser().getName().startsWith(project.getName() + "__")) {
                Path childPath = new Path(inodeController.getPath(child));
                dfso.setOwner(childPath, owner, group);
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ArrayList(java.util.ArrayList) TransactionAttribute(javax.ejb.TransactionAttribute)

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