Search in sources :

Example 16 with Dataset

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

the class PathValidator method buildProjectDsRelativePath.

private void buildProjectDsRelativePath(Project project, String[] pathComponents, DsPath dsPath) throws ProjectException, DatasetException {
    // Start by 1 as the first component is ""
    Project destProject = projectFacade.findByName(pathComponents[2]);
    if (project == null || destProject == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE);
    }
    Dataset ds = datasetController.getByProjectAndDsName(project, Utils.getProjectPath(pathComponents[2]), pathComponents[3]);
    if (ds == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
    }
    dsPath.setDs(ds);
    String dsRelativePathStr = buildRelativePath(pathComponents, 4, pathComponents.length);
    if (!dsRelativePathStr.isEmpty()) {
        dsPath.setDsRelativePath(new Path(dsRelativePathStr));
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Path(org.apache.hadoop.fs.Path) Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 17 with Dataset

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

the class PathValidator method buildFullPath.

private void buildFullPath(Project project, String path, DsPath dsPath) throws DatasetException {
    // Strip leading slashes.
    while (path.startsWith("/")) {
        path = path.substring(1);
    }
    String[] pathComponents = path.split(File.separator);
    String dsName = pathComponents[0];
    boolean shared = false;
    String parentProjectPath = null;
    if (pathComponents[0].contains(Settings.SHARED_FILE_SEPARATOR)) {
        // we can split the string and get the project name
        String[] shardDS = pathComponents[0].split(Settings.SHARED_FILE_SEPARATOR);
        if (shardDS.length != 2) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
        }
        parentProjectPath = Utils.getProjectPath(shardDS[0]);
        dsName = shardDS[1];
        shared = true;
    }
    Dataset ds = datasetController.getByProjectAndDsName(project, parentProjectPath, dsName);
    if (ds == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
    }
    // If the dataset is shared, make sure that the user can access it
    if (shared) {
        DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(project, ds);
        if (datasetSharedWith != null && !datasetSharedWith.getAccepted()) {
            throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PENDING, Level.FINE, "datasetId: " + ds.getId());
        }
    }
    dsPath.setDs(ds);
    String dsRelativePathStr = buildRelativePath(pathComponents, 1, pathComponents.length);
    if (dsRelativePathStr.isEmpty()) {
        dsPath.setFullPath(datasetController.getDatasetPath(ds));
    } else {
        Path dsRelativePath = new Path(dsRelativePathStr);
        dsPath.setDsRelativePath(dsRelativePath);
        Path fullPath = new Path(datasetController.getDatasetPath(ds), dsRelativePath);
        dsPath.setFullPath(fullPath);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 18 with Dataset

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

the class PathValidator method buildHiveDsRelativePath.

private void buildHiveDsRelativePath(Project project, String[] pathComponents, DsPath dsPath) throws DatasetException {
    String dsPathStr = File.separator + buildRelativePath(pathComponents, 1, 5);
    Inode dsInode = inodeController.getInodeAtPath(dsPathStr);
    if (dsInode == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.INODE_NOT_FOUND, Level.FINE);
    }
    Dataset originalDataset = datasetFacade.findByInode(dsInode);
    if (originalDataset == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
    }
    dsPath.setDs(originalDataset);
    String dsRelativePathStr = buildRelativePath(pathComponents, 5, pathComponents.length);
    if (!dsRelativePathStr.isEmpty()) {
        dsPath.setDsRelativePath(new Path(dsRelativePathStr));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 19 with Dataset

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

the class ProjectService method getDatasetInfo.

@GET
@Path("getDatasetInfo/{inodeId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getDatasetInfo(@PathParam("inodeId") Long inodeId, @Context SecurityContext sc) throws DatasetException {
    Inode inode = inodes.findById(inodeId);
    Project proj = datasetController.getOwningProject(inode);
    Dataset ds = datasetFacade.findByProjectAndInode(proj, inode);
    if (ds == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE, "inodeId: " + inodeId);
    }
    Collection<DatasetSharedWith> projectsContainingInode = proj.getDatasetSharedWithCollection();
    List<String> sharedWith = new ArrayList<>();
    for (DatasetSharedWith d : projectsContainingInode) {
        if (!d.getProject().getId().equals(proj.getId())) {
            sharedWith.add(d.getProject().getName());
        }
    }
    DataSetDTO dataset = new DataSetDTO(ds, proj, sharedWith);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(dataset).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) 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) ArrayList(java.util.ArrayList) DataSetDTO(io.hops.hopsworks.common.dao.dataset.DataSetDTO) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with Dataset

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

the class ProjectService method datasetInfo.

private MoreInfoDTO datasetInfo(Long inodeId) {
    Inode inode = inodes.findById(inodeId);
    if (inode == null) {
        return null;
    }
    Dataset ds = datasetFacade.findByInode(inode);
    if (ds != null && !ds.isSearchable()) {
        return null;
    }
    MoreInfoDTO info = new MoreInfoDTO(inode);
    Users user = userFacade.findByUsername(info.getUser());
    info.setUser(user.getFname() + " " + user.getLname());
    info.setSize(inodeController.getSize(inode));
    info.setPath(inodeController.getPath(inode));
    return info;
}
Also used : MoreInfoDTO(io.hops.hopsworks.common.project.MoreInfoDTO) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) Users(io.hops.hopsworks.persistence.entity.user.Users)

Aggregations

Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)63 DatasetException (io.hops.hopsworks.exceptions.DatasetException)20 Project (io.hops.hopsworks.persistence.entity.project.Project)19 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)18 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)13 DatasetSharedWith (io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith)12 Users (io.hops.hopsworks.persistence.entity.user.Users)12 ArrayList (java.util.ArrayList)11 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)10 Path (org.apache.hadoop.fs.Path)10 IOException (java.io.IOException)9 ProjectException (io.hops.hopsworks.exceptions.ProjectException)8 GET (javax.ws.rs.GET)8 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)7 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)7 GenericException (io.hops.hopsworks.exceptions.GenericException)7 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)7 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)6 POST (javax.ws.rs.POST)6