Search in sources :

Example 1 with AttachTagResult

use of io.hops.hopsworks.common.tags.AttachTagResult 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 2 with AttachTagResult

use of io.hops.hopsworks.common.tags.AttachTagResult in project hopsworks by logicalclocks.

the class ModelsResource method bulkPutTags.

@ApiOperation(value = "Create or update tags(bulk) for a model", response = TagsDTO.class)
@PUT
@Path("/{id}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@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.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response bulkPutTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, TagsDTO tags) throws MetadataException, SchematizedTagException, DatasetException, ProvenanceException, ModelRegistryException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
    AttachTagResult result;
    if (tags.getItems().size() == 0) {
        result = tagController.upsert(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), tags.getName(), tags.getValue());
    } else {
        Map<String, String> newTags = new HashMap<>();
        for (TagsDTO tag : tags.getItems()) {
            newTags.put(tag.getName(), tag.getValue());
        }
        result = tagController.upsertAll(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), newTags);
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), 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 : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) HashMap(java.util.HashMap) AttachTagResult(io.hops.hopsworks.common.tags.AttachTagResult) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriBuilder(javax.ws.rs.core.UriBuilder) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) 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 3 with AttachTagResult

use of io.hops.hopsworks.common.tags.AttachTagResult in project hopsworks by logicalclocks.

the class TrainingDatasetService method bulkPutTags.

@ApiOperation(value = "Create or update tags(bulk) for a training dataset", response = TagsDTO.class)
@PUT
@Path("/{trainingDatasetId}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@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, @ApiParam(value = "Id of the training dataset", required = true) @PathParam("trainingDatasetId") Integer trainingDatasetId, TagsDTO tags) throws MetadataException, FeaturestoreException, SchematizedTagException, DatasetException {
    verifyIdProvided(trainingDatasetId);
    Users user = jWTHelper.getUserPrincipal(sc);
    TrainingDataset trainingDataset = trainingDatasetController.getTrainingDatasetById(featurestore, trainingDatasetId);
    AttachTagResult result;
    if (tags.getItems().size() == 0) {
        result = tagController.upsert(project, user, featurestore, trainingDataset, tags.getName(), tags.getValue());
    } else {
        Map<String, String> newTags = new HashMap<>();
        for (TagsDTO tag : tags.getItems()) {
            newTags.put(tag.getName(), tag.getValue());
        }
        result = tagController.upsert(project, user, featurestore, trainingDataset, newTags);
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, project, featurestore.getId(), ResourceRequest.Name.TRAININGDATASETS.name(), trainingDatasetId, 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) TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) AttachTagResult(io.hops.hopsworks.common.tags.AttachTagResult) 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) Consumes(javax.ws.rs.Consumes) 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 4 with AttachTagResult

use of io.hops.hopsworks.common.tags.AttachTagResult in project hopsworks by logicalclocks.

the class ModelsResource method putTag.

@ApiOperation(value = "Create or update one tag for a model", response = TagsDTO.class)
@PUT
@Path("/{id}/tags/{name}")
@Consumes(MediaType.APPLICATION_JSON)
@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.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response putTag(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name, @ApiParam(value = "Value to set for the tag") String value) throws MetadataException, SchematizedTagException, DatasetException, ProvenanceException, ModelRegistryException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
    AttachTagResult result = tagController.upsert(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), name, value);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), 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 : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) AttachTagResult(io.hops.hopsworks.common.tags.AttachTagResult) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriBuilder(javax.ws.rs.core.UriBuilder) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) 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 5 with AttachTagResult

use of io.hops.hopsworks.common.tags.AttachTagResult in project hopsworks by logicalclocks.

the class FeaturegroupService method putTag.

@ApiOperation(value = "Create or update one tag for a featuregroup", response = TagsDTO.class)
@PUT
@Path("/{featuregroupId}/tags/{name}")
@Consumes(MediaType.APPLICATION_JSON)
@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 putTag(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the featuregroup", required = true) @PathParam("featuregroupId") Integer featuregroupId, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name, @ApiParam(value = "Value to set for the tag") String value) throws MetadataException, FeaturestoreException, SchematizedTagException, DatasetException {
    verifyIdProvided(featuregroupId);
    Users user = jWTHelper.getUserPrincipal(sc);
    Featuregroup featuregroup = featuregroupController.getFeaturegroupById(featurestore, featuregroupId);
    AttachTagResult result = tagController.upsert(project, user, featurestore, featuregroup, name, value);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, project, featurestore.getId(), ResourceRequest.Name.FEATUREGROUPS.name(), featuregroupId, 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) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) AttachTagResult(io.hops.hopsworks.common.tags.AttachTagResult) 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) Consumes(javax.ws.rs.Consumes) 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

AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)8 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)8 AttachTagResult (io.hops.hopsworks.common.tags.AttachTagResult)8 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)8 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)8 Users (io.hops.hopsworks.persistence.entity.user.Users)8 ApiOperation (io.swagger.annotations.ApiOperation)8 PUT (javax.ws.rs.PUT)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 UriBuilder (javax.ws.rs.core.UriBuilder)8 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)7 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)6 Consumes (javax.ws.rs.Consumes)6 HashMap (java.util.HashMap)4 ModelDTO (io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO)2 ProvStateDTO (io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO)2 Featuregroup (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup)2 TrainingDataset (io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset)2