Search in sources :

Example 86 with ResourceRequest

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

the class XAttrsResource method put.

@ApiOperation(value = "Create or Update an extended attribute for a path.", response = XAttrDTO.class)
@PUT
@Path("{path: .+}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response put(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam("pathType") @DefaultValue("DATASET") DatasetType pathType, @QueryParam("name") String xattrName, String metaObj) throws DatasetException, MetadataException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Response.Status status = Response.Status.OK;
    String inodePath = datasetHelper.getDatasetPathIfFileExist(project, path, pathType).getFullPath().toString();
    if (xattrsController.addXAttr(project, user, inodePath, xattrName, metaObj)) {
        status = Response.Status.CREATED;
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.XATTRS);
    XAttrDTO dto = xattrsBuilder.build(uriInfo, resourceRequest, project, inodePath, xattrName);
    if (status == Response.Status.CREATED) {
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        return Response.created(builder.build()).entity(dto).build();
    } else {
        return Response.ok().entity(dto).build();
    }
}
Also used : Response(javax.ws.rs.core.Response) 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) Consumes(javax.ws.rs.Consumes) 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 87 with ResourceRequest

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

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

the class ModelRegistryResource method getAll.

@ApiOperation(value = "Get a list of all model registries accessible for this project", response = ModelRegistryDTO.class)
@GET
@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 getAll(@BeanParam ModelRegistryBeanParam modelRegistryBeanParam, @BeanParam Pagination pagination, @Context UriInfo uriInfo, @Context SecurityContext sc) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.MODELREGISTRIES);
    resourceRequest.setExpansions(modelRegistryBeanParam.getExpansions().getResources());
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    ModelRegistryDTO dto = modelRegistryBuilder.build(uriInfo, resourceRequest, user, project);
    return Response.ok().entity(dto).build();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO) 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 89 with ResourceRequest

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

the class ModelRegistryResource method get.

@ApiOperation(value = "Get a model registry", response = ModelDTO.class)
@GET
@Path("{modelRegistryId}")
@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("modelRegistryId") Integer modelRegistryId, @BeanParam ModelRegistryBeanParam modelRegistryBeanParam, @BeanParam Pagination pagination, @Context UriInfo uriInfo, @Context SecurityContext sc) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.MODELREGISTRIES);
    resourceRequest.setExpansions(modelRegistryBeanParam.getExpansions().getResources());
    Project modelRegistryProject = modelsController.verifyModelRegistryAccess(project, modelRegistryId).getParentProject();
    ModelRegistryDTO dto = modelRegistryBuilder.build(uriInfo, resourceRequest, user, project, modelRegistryProject);
    return Response.ok().entity(dto).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO) 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 90 with ResourceRequest

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

the class ApiKeyResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an api key.", response = ApiKeyDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "AGENT" })
public Response create(@QueryParam("name") String name, @QueryParam("scope") Set<ApiScope> scopes, @Context UriInfo uriInfo, @Context SecurityContext sc, @Context HttpServletRequest req) throws ApiKeyException, UserException {
    Users user = jwtHelper.getUserPrincipal(sc);
    Set<ApiScope> validatedScopes = validateScopes(user, scopes);
    String apiKey = apikeyController.createNewKey(user, name, validatedScopes, false);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.APIKEY);
    ApiKeyDTO dto = apikeyBuilder.build(uriInfo, resourceRequest, user, name);
    dto.setKey(apiKey);
    return Response.created(dto.getHref()).entity(dto).build();
}
Also used : ApiScope(io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

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