Search in sources :

Example 6 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class ModelsBuilder method build.

// Build specific
public ModelDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project userProject, Project modelRegistryProject, ProvStateDTO fileProvenanceHit, String modelsFolder) throws DatasetException, ModelRegistryException, SchematizedTagException, MetadataException {
    ModelDTO modelDTO = new ModelDTO();
    uri(modelDTO, uriInfo, userProject, modelRegistryProject, fileProvenanceHit);
    if (expand(modelDTO, resourceRequest).isExpand()) {
        if (fileProvenanceHit.getXattrs() != null && fileProvenanceHit.getXattrs().containsKey(MODEL_SUMMARY_XATTR_NAME)) {
            ModelDTO modelSummary = modelUtils.convertProvenanceHitToModel(fileProvenanceHit);
            modelDTO.setId(fileProvenanceHit.getMlId());
            modelDTO.setName(modelSummary.getName());
            modelDTO.setVersion(modelSummary.getVersion());
            modelDTO.setUserFullName(modelSummary.getUserFullName());
            modelDTO.setCreated(fileProvenanceHit.getCreateTime());
            modelDTO.setMetrics(modelSummary.getMetrics());
            modelDTO.setDescription(modelSummary.getDescription());
            modelDTO.setProgram(modelSummary.getProgram());
            modelDTO.setFramework(modelSummary.getFramework());
            modelDTO.setTags(tagsBuilder.build(uriInfo, resourceRequest, user, userProject, modelRegistryProject, modelDTO));
            String modelVersionPath = modelsFolder + "/" + modelDTO.getName() + "/" + modelDTO.getVersion() + "/";
            DatasetPath modelSchemaPath = datasetHelper.getDatasetPath(userProject, modelVersionPath + Settings.HOPS_MODELS_SCHEMA, DatasetType.DATASET);
            if (resourceRequest.contains(ResourceRequest.Name.MODELSCHEMA) && modelSchemaPath.getInode() != null) {
                InodeDTO modelSchemaDTO = inodeBuilder.buildBlob(uriInfo, new ResourceRequest(ResourceRequest.Name.INODES), user, modelSchemaPath, modelSchemaPath.getInode(), FilePreviewMode.HEAD);
                modelDTO.setModelSchema(modelSchemaDTO);
            } else {
                InodeDTO modelSchemaDTO = inodeBuilder.buildResource(uriInfo, modelRegistryProject, modelSchemaPath);
                modelDTO.setModelSchema(modelSchemaDTO);
            }
            DatasetPath inputExamplePath = datasetHelper.getDatasetPath(userProject, modelVersionPath + Settings.HOPS_MODELS_INPUT_EXAMPLE, DatasetType.DATASET);
            if (resourceRequest.contains(ResourceRequest.Name.INPUTEXAMPLE) && inputExamplePath.getInode() != null) {
                InodeDTO inputExampleDTO = inodeBuilder.buildBlob(uriInfo, new ResourceRequest(ResourceRequest.Name.INODES), user, inputExamplePath, inputExamplePath.getInode(), FilePreviewMode.HEAD);
                modelDTO.setInputExample(inputExampleDTO);
            } else {
                InodeDTO inputExampleDTO = inodeBuilder.buildResource(uriInfo, modelRegistryProject, inputExamplePath);
                modelDTO.setInputExample(inputExampleDTO);
            }
            modelDTO.setEnvironment(modelSummary.getEnvironment());
            modelDTO.setExperimentId(modelSummary.getExperimentId());
            modelDTO.setExperimentProjectName(modelSummary.getExperimentProjectName());
            modelDTO.setProjectName(modelSummary.getProjectName());
            modelDTO.setModelRegistryId(modelRegistryProject.getId());
        }
    }
    return modelDTO;
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) InodeDTO(io.hops.hopsworks.api.dataset.inode.InodeDTO) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest)

Example 7 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest 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 8 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest 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 9 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class KafkaResource method getTopicAcls.

@ApiOperation(value = "Get all ACLs for a specified topic.")
@GET
@Path("/topics/{topic}/acls")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopicAcls(@Context UriInfo uriInfo, @PathParam("topic") String topicName, @BeanParam Pagination pagination, @BeanParam AclsBeanParam aclsBeanParam, @Context SecurityContext sc) {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(aclsBeanParam.getSortBySet());
    resourceRequest.setFilter(aclsBeanParam.getFilter());
    AclDTO dto = aclBuilder.build(uriInfo, project, topicName, resourceRequest);
    return Response.ok().entity(dto).build();
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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 10 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class KafkaResource method getTopics.

@ApiOperation(value = "Retrieve Kafka topics metadata .")
@GET
@Path("/topics")
@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.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopics(@Context UriInfo uriInfo, @BeanParam Pagination pagination, @BeanParam TopicsBeanParam topicsBeanParam, @Context SecurityContext sc) {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(topicsBeanParam.getSortBySet());
    resourceRequest.setFilter(topicsBeanParam.getFilter());
    TopicDTO dto = topicsBuilder.build(uriInfo, resourceRequest, project);
    return Response.ok().entity(dto).build();
}
Also used : TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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)

Aggregations

ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)171 ApiOperation (io.swagger.annotations.ApiOperation)163 Produces (javax.ws.rs.Produces)157 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)151 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)127 GET (javax.ws.rs.GET)107 Path (javax.ws.rs.Path)99 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)94 Users (io.hops.hopsworks.persistence.entity.user.Users)75 Consumes (javax.ws.rs.Consumes)37 POST (javax.ws.rs.POST)30 PUT (javax.ws.rs.PUT)27 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)20 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)17 AlertException (io.hops.hopsworks.exceptions.AlertException)14 Project (io.hops.hopsworks.persistence.entity.project.Project)14 UriBuilder (javax.ws.rs.core.UriBuilder)12 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)11 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)11 HashMap (java.util.HashMap)9