Search in sources :

Example 1 with DatasetPath

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

the class DatasetTagsResource method deleteTags.

@ApiOperation(value = "Delete all attached tags to a dataset")
@DELETE
@Path("/all/{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response deleteTags(@Context SecurityContext sc, @PathParam("path") String path, @QueryParam("datasetType") DatasetType datasetType) throws DatasetException, MetadataException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    Users user = jWTHelper.getUserPrincipal(sc);
    tagsController.deleteAll(user, datasetPath);
    return Response.noContent().build();
}
Also used : 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 2 with DatasetPath

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

the class DatasetTagsResource method deleteTag.

@ApiOperation(value = "Delete tag attached to a dataset")
@DELETE
@Path("/schema/{schemaName}/{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response deleteTag(@Context SecurityContext sc, @ApiParam(value = "Name of the tag", required = true) @PathParam("schemaName") String schemaName, @PathParam("path") String path, @QueryParam("datasetType") DatasetType datasetType) throws DatasetException, MetadataException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    Users user = jWTHelper.getUserPrincipal(sc);
    tagsController.delete(user, datasetPath, schemaName);
    return Response.noContent().build();
}
Also used : 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 3 with DatasetPath

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

the class DatasetTagsResource method putTag.

@ApiOperation(value = "Create or update tag for a dataset", response = TagsDTO.class)
@PUT
@Path("/schema/{schemaName}/{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response putTag(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Name of the tag", required = true) @PathParam("schemaName") String schemaName, @PathParam("path") String path, @QueryParam("datasetType") DatasetType datasetType, @ApiParam(value = "Value to set for the tag") String value) throws DatasetException, MetadataException, SchematizedTagException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    Users user = jWTHelper.getUserPrincipal(sc);
    AttachTagResult result = tagsController.upsert(user, datasetPath, schemaName, value);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    TagsDTO dto = tagsBuilder.build(uriInfo, resourceRequest, datasetPath, result.getItems());
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    if (result.isCreated()) {
        return Response.created(builder.build()).entity(dto).build();
    } else {
        return Response.ok(builder.build()).entity(dto).build();
    }
}
Also used : TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) AttachTagResult(io.hops.hopsworks.common.tags.AttachTagResult) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriBuilder(javax.ws.rs.core.UriBuilder) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 4 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" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_VIEW }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_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 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 5 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" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_DELETE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response delete(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Delete action, @QueryParam("target_project") String targetProject, @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)

Aggregations

DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)26 Users (io.hops.hopsworks.persistence.entity.user.Users)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)13 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)13 ApiOperation (io.swagger.annotations.ApiOperation)13 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)10 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)9 DatasetException (io.hops.hopsworks.exceptions.DatasetException)9 Project (io.hops.hopsworks.persistence.entity.project.Project)9 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)8 GET (javax.ws.rs.GET)7 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)5 GenericException (io.hops.hopsworks.exceptions.GenericException)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 InodeDTO (io.hops.hopsworks.api.dataset.inode.InodeDTO)3 DELETE (javax.ws.rs.DELETE)3 PUT (javax.ws.rs.PUT)3 ProvArtifactUsageParentDTO (io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO)2