Search in sources :

Example 26 with DatasetPath

use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.

the class UploadService method configureUploader.

private void configureUploader(SecurityContext sc) throws DatasetException, ProjectException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Project project = this.getProject();
    this.username = hdfsUsersBean.getHdfsUserName(project, user);
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, this.datasetType);
    Project owning = datasetController.getOwningProject(datasetPath.getDataset());
    // Is user a member of this project? If so get their role
    boolean isMember = projectTeamFacade.isUserMemberOfProject(owning, user);
    this.role = null;
    if (isMember) {
        role = projectTeamFacade.findCurrentRole(owning, user);
    }
    confFileUpload(datasetPath);
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath)

Example 27 with DatasetPath

use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.

the class DownloadService method getDownloadToken.

@GET
@javax.ws.rs.Path("token/{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a one time download token.", response = RESTApiJsonResponse.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response getDownloadToken(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, ProjectException {
    if (!settings.isDownloadAllowed()) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DOWNLOAD_NOT_ALLOWED, Level.FINEST);
    }
    Users user = jWTHelper.getUserPrincipal(sc);
    DatasetPath datasetPath = datasetHelper.getDatasetPathIfFileExist(this.getProject(), path, datasetType);
    Project owningProject = datasetController.getOwningProject(datasetPath.getDataset());
    RESTApiJsonResponse response = new RESTApiJsonResponse();
    String username = hdfsUsersController.getHdfsUserName(this.getProject(), user);
    // For example, DS1 of project1 is shared with project2. User must be a member of project1 to download files
    if (owningProject.equals(this.getProject()) && datasetController.isDownloadAllowed(this.getProject(), user, datasetPath.getFullPath().toString())) {
        datasetController.checkFileExists(datasetPath.getFullPath(), username);
        String token = jWTHelper.createOneTimeToken(user, datasetPath.getFullPath().toString(), null);
        if (token != null && !token.isEmpty()) {
            response.setData(token);
            return Response.status(Response.Status.OK).entity(response).build();
        }
    }
    response.setErrorMsg(ResponseMessages.DOWNLOAD_PERMISSION_ERROR);
    return Response.status(Response.Status.FORBIDDEN).entity(response).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 28 with DatasetPath

use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.

the class DatasetResource method getByPath.

@GET
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get or list files in path.", response = InodeDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_VIEW }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response getByPath(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Get action, @QueryParam("mode") FilePreviewMode mode, @BeanParam Pagination pagination, @BeanParam InodeBeanParam inodeBeanParam, @BeanParam DatasetExpansionBeanParam datasetExpansionBeanParam, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, ProjectException, MetadataException, SchematizedTagException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.INODES);
    resourceRequest.setExpansions(datasetExpansionBeanParam.getResources());
    Project project = this.getProject();
    DatasetPath datasetPath = datasetHelper.getDatasetPathIfFileExist(project, path, datasetType);
    InodeDTO dto;
    switch(action == null ? DatasetActions.Get.STAT : action) {
        case BLOB:
            dto = inodeBuilder.buildBlob(uriInfo, resourceRequest, user, datasetPath, mode);
            break;
        case LISTING:
            resourceRequest.setOffset(pagination.getOffset());
            resourceRequest.setLimit(pagination.getLimit());
            resourceRequest.setSort(inodeBeanParam.getSortBySet());
            resourceRequest.setFilter(inodeBeanParam.getFilter());
            dto = inodeBuilder.buildItems(uriInfo, resourceRequest, user, datasetPath);
            break;
        case STAT:
            if (datasetPath.isTopLevelDataset()) {
                ResourceRequest datasetResourceRequest = new ResourceRequest(ResourceRequest.Name.DATASET);
                datasetResourceRequest.setExpansions(datasetExpansionBeanParam.getResources());
                DatasetDTO datasetDTO = datasetBuilder.build(uriInfo, datasetResourceRequest, user, datasetPath, null, null, true);
                return Response.ok().entity(datasetDTO).build();
            } else {
                dto = inodeBuilder.buildStat(uriInfo, resourceRequest, user, datasetPath);
            }
            break;
        default:
            throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
    }
    return Response.ok().entity(dto).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) WebApplicationException(javax.ws.rs.WebApplicationException) InodeDTO(io.hops.hopsworks.api.dataset.inode.InodeDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 29 with DatasetPath

use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.

the class DatasetResource method delete.

@DELETE
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@ApiOperation(value = "Delete/unshare dataset")
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_DELETE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response delete(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Delete action, @QueryParam("target_project") String targetProject, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, ProjectException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(this.getProject(), path, datasetType);
    Users user = jwtHelper.getUserPrincipal(sc);
    Project project = this.getProject();
    if (action == null) {
        datasetController.delete(project, user, datasetPath.getFullPath(), datasetPath.getDataset(), datasetPath.isTopLevelDataset());
    } else {
        switch(action) {
            case UNSHARE:
                checkIfDataOwner(project, user);
                datasetController.unshare(project, user, datasetPath.getDataset(), targetProject);
                break;
            case CORRUPTED:
                if (datasetPath.isTopLevelDataset()) {
                    throw new IllegalArgumentException("Use DELETE /{datasetName} to delete top level dataset)");
                }
                datasetController.deleteCorrupted(project, user, datasetPath.getFullPath(), datasetPath.getDataset());
                break;
            default:
                throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
        }
    }
    return Response.noContent().build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) WebApplicationException(javax.ws.rs.WebApplicationException) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 30 with DatasetPath

use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.

the class DatasetResource method update.

@PUT
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@ApiOperation(value = "Set permissions (potentially with sticky bit) for datasets", notes = "Allow data scientists to create and modify own files in dataset.", response = DatasetDTO.class)
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_CREATE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response update(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Put action, @QueryParam("description") String description, @DefaultValue("READ_ONLY") @QueryParam("permissions") DatasetAccessPermission datasetPermissions, @QueryParam("target_project") String targetProjectName, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ProjectException, MetadataException, SchematizedTagException, FeaturestoreException {
    Project project = this.getProject();
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.DATASET);
    Users user = jwtHelper.getUserPrincipal(sc);
    DatasetDTO dto;
    switch(action == null ? DatasetActions.Put.DESCRIPTION : action) {
        case PERMISSION:
            checkIfDataOwner(project, user);
            datasetController.updatePermission(datasetPath.getDataset(), datasetPermissions, project, project, user);
            dto = datasetBuilder.build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
            break;
        case SHARE_PERMISSION:
            checkIfDataOwner(project, user);
            datasetController.updateSharePermission(datasetPath.getDataset(), datasetPermissions, project, targetProjectName, user);
            dto = datasetBuilder.build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
            break;
        case DESCRIPTION:
            datasetController.updateDescription(project, user, datasetPath.getDataset(), description);
            dto = datasetBuilder.build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
            break;
        default:
            throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
    }
    return Response.ok(dto).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) WebApplicationException(javax.ws.rs.WebApplicationException) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Aggregations

DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)38 Users (io.hops.hopsworks.persistence.entity.user.Users)25 Produces (javax.ws.rs.Produces)25 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)24 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)24 ApiOperation (io.swagger.annotations.ApiOperation)23 Path (javax.ws.rs.Path)23 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)18 Project (io.hops.hopsworks.persistence.entity.project.Project)15 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)13 GET (javax.ws.rs.GET)13 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)9 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 DELETE (javax.ws.rs.DELETE)6 InodeDTO (io.hops.hopsworks.api.dataset.inode.InodeDTO)5 GenericException (io.hops.hopsworks.exceptions.GenericException)4 PUT (javax.ws.rs.PUT)4 Path (org.apache.hadoop.fs.Path)3