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();
}
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations