Search in sources :

Example 21 with DatasetPath

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

the class DatasetTagsResource method getTag.

@ApiOperation(value = "Get tag attached to a dataset", response = TagsDTO.class)
@GET
@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 getTag(@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, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    Users user = jWTHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
    TagsDTO dto = tagsBuilder.build(uriInfo, resourceRequest, user, datasetPath, schemaName);
    return Response.status(Response.Status.OK).entity(dto).build();
}
Also used : TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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 22 with DatasetPath

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

the class DatasetTagsResource method getTags.

@ApiOperation(value = "Get all tags attached to a dataset", response = TagsDTO.class)
@GET
@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 getTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam("datasetType") DatasetType datasetType, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    Users user = jWTHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
    TagsDTO dto = tagsBuilder.build(uriInfo, resourceRequest, user, datasetPath);
    return Response.status(Response.Status.OK).entity(dto).build();
}
Also used : TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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 23 with DatasetPath

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

the class DatasetTagsResource method bulkPutTags.

@ApiOperation(value = "Create or update tags(bulk) for a featuregroup", response = TagsDTO.class)
@PUT
@Path("/bulk/{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 bulkPutTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam("datasetType") DatasetType datasetType, TagsDTO tags) throws DatasetException, MetadataException, SchematizedTagException {
    DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
    Users user = jWTHelper.getUserPrincipal(sc);
    AttachTagResult result;
    if (tags.getItems().size() == 0) {
        result = tagsController.upsert(user, datasetPath, tags.getName(), tags.getValue());
    } else {
        Map<String, String> newTags = new HashMap<>();
        for (TagsDTO tag : tags.getItems()) {
            newTags.put(tag.getName(), tag.getValue());
        }
        result = tagsController.upsert(user, datasetPath, newTags);
    }
    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) HashMap(java.util.HashMap) 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) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 24 with DatasetPath

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

the class DatasetBuilder method build.

/**
 * Build a single Dataset
 *
 * @param uriInfo
 * @param resourceRequest
 * @param name
 * @return
 */
public DatasetDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project accessProject, Users user, String name) throws DatasetException, MetadataException, SchematizedTagException {
    Dataset dataset = datasetController.getByProjectAndDsName(accessProject, null, name);
    if (dataset == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
    }
    DatasetPath datasetPath = datasetHelper.getTopLevelDatasetPath(accessProject, dataset);
    return build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
}
Also used : Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 25 with DatasetPath

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

the class TrainingDatasetService method provenance.

@Path("/{trainingDatasetId}/provenance")
public ProvArtifactResource provenance(@PathParam("trainingDatasetId") Integer trainingDatasetId) throws FeaturestoreException, GenericException {
    String tdName = featurestore.getProject().getName() + "_" + Settings.ServiceDataset.TRAININGDATASETS.getName();
    DatasetPath targetEndpointPath;
    try {
        Dataset targetEndpoint = datasetController.getByName(featurestore.getProject(), tdName);
        targetEndpointPath = datasetHelper.getTopLevelDatasetPath(project, targetEndpoint);
    } catch (DatasetException ex) {
        throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "training dataset not found");
    }
    this.provenanceResource.setContext(project, targetEndpointPath);
    TrainingDataset td = trainingDatasetController.getTrainingDatasetById(featurestore, trainingDatasetId);
    this.provenanceResource.setArtifactId(td.getName(), td.getVersion());
    return provenanceResource;
}
Also used : TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) GenericException(io.hops.hopsworks.exceptions.GenericException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath)

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