use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class XAttrsResource method get.
@ApiOperation(value = "Get extended attributes attached to a path.", response = XAttrDTO.class)
@GET
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam("pathType") @DefaultValue("DATASET") DatasetType pathType, @QueryParam("name") String xattrName) throws DatasetException, MetadataException {
Users user = jWTHelper.getUserPrincipal(sc);
Map<String, String> result = new HashMap<>();
DistributedFileSystemOps udfso = dfs.getDfsOps(hdfsUsersController.getHdfsUserName(project, user));
String inodePath = datasetHelper.getDatasetPathIfFileExist(project, path, pathType).getFullPath().toString();
try {
if (xattrName != null) {
String xattr = xattrsController.getXAttr(inodePath, xattrName, udfso);
if (Strings.isNullOrEmpty(xattr)) {
throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
}
result.put(xattrName, xattr);
} else {
result.putAll(xattrsController.getXAttrs(inodePath, udfso));
}
} finally {
dfs.closeDfsClient(udfso);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.XATTRS);
XAttrDTO dto = xattrsBuilder.build(uriInfo, resourceRequest, project, inodePath, result);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class ModelsResource method getAll.
@ApiOperation(value = "Get a list of all models for this project", response = ModelDTO.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 Pagination pagination, @BeanParam ModelsBeanParam modelsBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ModelRegistryException, GenericException, SchematizedTagException, MetadataException {
Users user = jwtHelper.getUserPrincipal(sc);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.MODELS);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setFilter(modelsBeanParam.getFilter());
resourceRequest.setSort(modelsBeanParam.getSortBySet());
resourceRequest.setExpansions(modelsBeanParam.getExpansions().getResources());
ModelDTO dto = modelsBuilder.build(uriInfo, resourceRequest, user, userProject, modelRegistryProject);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest 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();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class ModelRegistryBuilder method build.
// Build collection
public ModelRegistryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project project) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
ModelRegistryDTO dto = new ModelRegistryDTO();
uri(dto, uriInfo, project);
expand(dto, resourceRequest);
Collection<Dataset> dsInProject = project.getDatasetCollection();
// Add all datasets shared with the project
dsInProject.addAll(project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).map(DatasetSharedWith::getDataset).collect(Collectors.toList()));
Collection<Dataset> modelsDatasets = dsInProject.stream().filter(ds -> ds.getName().equals(Settings.HOPS_MODELS_DATASET)).collect(Collectors.toList());
dto.setCount((long) modelsDatasets.size());
for (Dataset ds : modelsDatasets) {
ModelRegistryDTO modelRegistryDTO = build(uriInfo, resourceRequest, user, project, ds.getProject());
if (modelRegistryDTO != null) {
dto.addItem(modelRegistryDTO);
}
}
return dto;
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class TestCommitBuilder method testBuildNullOffsetAndLimit.
@Test
public void testBuildNullOffsetAndLimit() throws Exception {
// arrange
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.COMMITS);
resourceRequest.setOffset(null);
resourceRequest.setLimit(null);
resourceRequest.setSort(new HashSet<SortBy>());
resourceRequest.setFilter(new HashSet<FilterBy>());
// act
CommitDTO commitDTO = commitBuilder.build(mockUriInfo, resourceRequest, project, featuregroup);
// assert
verify(featureGroupCommitController).getCommitDetails(featuregroup.getId(), 20, 0, resourceRequest.getSort(), resourceRequest.getFilter());
Assert.assertTrue(commitDTO.getCount().intValue() <= 20);
Assert.assertEquals(0, commitDTO.getCount().intValue());
}
Aggregations