Search in sources :

Example 1 with ProvStateDTO

use of io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO in project hopsworks by logicalclocks.

the class ModelsResource method get.

@ApiOperation(value = "Get a model", response = ModelDTO.class)
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@PathParam("id") String id, @BeanParam ModelsBeanParam modelsBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProvenanceException, ModelRegistryException, DatasetException, GenericException, SchematizedTagException, MetadataException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.MODELS);
    resourceRequest.setExpansions(modelsBeanParam.getExpansions().getResources());
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    if (fileState != null) {
        ModelDTO dto = modelsBuilder.build(uriInfo, resourceRequest, user, userProject, modelRegistryProject, fileState, modelUtils.getModelsDatasetPath(userProject, modelRegistryProject));
        if (dto == null) {
            throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.FINE);
        } else {
            return Response.ok().entity(dto).build();
        }
    } else {
        throw new ModelRegistryException(RESTCodes.ModelRegistryErrorCode.MODEL_NOT_FOUND, Level.FINE);
    }
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) GenericException(io.hops.hopsworks.exceptions.GenericException) ModelRegistryException(io.hops.hopsworks.exceptions.ModelRegistryException) Path(javax.ws.rs.Path) 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 2 with ProvStateDTO

use of io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO 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 ProvStateDTO

use of io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO in project hopsworks by logicalclocks.

the class ModelsResource method deleteTag.

@ApiOperation(value = "Delete tag attached to a model")
@DELETE
@Path("/{id}/tags/{name}")
@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 deleteTag(@Context SecurityContext sc, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name) throws DatasetException, MetadataException, ProvenanceException, ModelRegistryException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
    tagController.delete(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), name);
    return Response.noContent().build();
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) Path(javax.ws.rs.Path) 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 4 with ProvStateDTO

use of io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO in project hopsworks by logicalclocks.

the class ModelsResource method getTags.

@ApiOperation(value = "Get all tags attached to a model", response = TagsDTO.class)
@GET
@Path("/{id}/tags")
@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 getTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException, ProvenanceException, ModelRegistryException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
    Map<String, String> result = tagController.getAll(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()));
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), result);
    return Response.status(Response.Status.OK).entity(dto).build();
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) Path(javax.ws.rs.Path) 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 ProvStateDTO

use of io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO in project hopsworks by logicalclocks.

the class ModelsController method getModel.

public ProvStateDTO getModel(Project project, String mlId) throws ProvenanceException {
    ProvStateParamBuilder provFilesParamBuilder = new ProvStateParamBuilder().filterByField(ProvStateParser.FieldsP.PROJECT_I_ID, project.getInode().getId()).filterByField(ProvStateParser.FieldsP.ML_TYPE, Provenance.MLType.MODEL.name()).filterByField(ProvStateParser.FieldsP.ML_ID, mlId).paginate(0, 1);
    ProvStateDTO fileState = provenanceController.provFileStateList(project, provFilesParamBuilder);
    if (fileState != null) {
        List<ProvStateDTO> experiments = fileState.getItems();
        if (experiments != null && !experiments.isEmpty()) {
            return experiments.iterator().next();
        }
    }
    return null;
}
Also used : ProvStateParamBuilder(io.hops.hopsworks.common.provenance.state.ProvStateParamBuilder) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO)

Aggregations

ProvStateDTO (io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO)17 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)9 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)9 Users (io.hops.hopsworks.persistence.entity.user.Users)9 ApiOperation (io.swagger.annotations.ApiOperation)9 Path (javax.ws.rs.Path)9 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)8 ModelDTO (io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO)8 Produces (javax.ws.rs.Produces)8 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)6 ProvStateParamBuilder (io.hops.hopsworks.common.provenance.state.ProvStateParamBuilder)4 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)4 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)4 HashMap (java.util.HashMap)4 GET (javax.ws.rs.GET)4 ExperimentDTO (io.hops.hopsworks.api.experiments.dto.ExperimentDTO)3 GenericException (io.hops.hopsworks.exceptions.GenericException)3 DELETE (javax.ws.rs.DELETE)3 AttachTagResult (io.hops.hopsworks.common.tags.AttachTagResult)2 DatasetException (io.hops.hopsworks.exceptions.DatasetException)2