use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.
the class UploadService method configureUploader.
private void configureUploader(SecurityContext sc) throws DatasetException, ProjectException {
Users user = jWTHelper.getUserPrincipal(sc);
Project project = this.getProject();
this.username = hdfsUsersBean.getHdfsUserName(project, user);
DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, this.datasetType);
Project owning = datasetController.getOwningProject(datasetPath.getDataset());
// Is user a member of this project? If so get their role
boolean isMember = projectTeamFacade.isUserMemberOfProject(owning, user);
this.role = null;
if (isMember) {
role = projectTeamFacade.findCurrentRole(owning, user);
}
confFileUpload(datasetPath);
}
use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.
the class DownloadService method getDownloadToken.
@GET
@javax.ws.rs.Path("token/{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a one time download token.", response = RESTApiJsonResponse.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response getDownloadToken(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, ProjectException {
if (!settings.isDownloadAllowed()) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DOWNLOAD_NOT_ALLOWED, Level.FINEST);
}
Users user = jWTHelper.getUserPrincipal(sc);
DatasetPath datasetPath = datasetHelper.getDatasetPathIfFileExist(this.getProject(), path, datasetType);
Project owningProject = datasetController.getOwningProject(datasetPath.getDataset());
RESTApiJsonResponse response = new RESTApiJsonResponse();
String username = hdfsUsersController.getHdfsUserName(this.getProject(), user);
// For example, DS1 of project1 is shared with project2. User must be a member of project1 to download files
if (owningProject.equals(this.getProject()) && datasetController.isDownloadAllowed(this.getProject(), user, datasetPath.getFullPath().toString())) {
datasetController.checkFileExists(datasetPath.getFullPath(), username);
String token = jWTHelper.createOneTimeToken(user, datasetPath.getFullPath().toString(), null);
if (token != null && !token.isEmpty()) {
response.setData(token);
return Response.status(Response.Status.OK).entity(response).build();
}
}
response.setErrorMsg(ResponseMessages.DOWNLOAD_PERMISSION_ERROR);
return Response.status(Response.Status.FORBIDDEN).entity(response).build();
}
use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.
the class DatasetResource method getByPath.
@GET
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get or list files in path.", response = InodeDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_VIEW }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response getByPath(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Get action, @QueryParam("mode") FilePreviewMode mode, @BeanParam Pagination pagination, @BeanParam InodeBeanParam inodeBeanParam, @BeanParam DatasetExpansionBeanParam datasetExpansionBeanParam, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, ProjectException, MetadataException, SchematizedTagException {
Users user = jwtHelper.getUserPrincipal(sc);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.INODES);
resourceRequest.setExpansions(datasetExpansionBeanParam.getResources());
Project project = this.getProject();
DatasetPath datasetPath = datasetHelper.getDatasetPathIfFileExist(project, path, datasetType);
InodeDTO dto;
switch(action == null ? DatasetActions.Get.STAT : action) {
case BLOB:
dto = inodeBuilder.buildBlob(uriInfo, resourceRequest, user, datasetPath, mode);
break;
case LISTING:
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(inodeBeanParam.getSortBySet());
resourceRequest.setFilter(inodeBeanParam.getFilter());
dto = inodeBuilder.buildItems(uriInfo, resourceRequest, user, datasetPath);
break;
case STAT:
if (datasetPath.isTopLevelDataset()) {
ResourceRequest datasetResourceRequest = new ResourceRequest(ResourceRequest.Name.DATASET);
datasetResourceRequest.setExpansions(datasetExpansionBeanParam.getResources());
DatasetDTO datasetDTO = datasetBuilder.build(uriInfo, datasetResourceRequest, user, datasetPath, null, null, true);
return Response.ok().entity(datasetDTO).build();
} else {
dto = inodeBuilder.buildStat(uriInfo, resourceRequest, user, datasetPath);
}
break;
default:
throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
}
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.
the class DatasetResource method delete.
@DELETE
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@ApiOperation(value = "Delete/unshare dataset")
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_DELETE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response delete(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Delete action, @QueryParam("target_project") String targetProject, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, ProjectException {
DatasetPath datasetPath = datasetHelper.getDatasetPath(this.getProject(), path, datasetType);
Users user = jwtHelper.getUserPrincipal(sc);
Project project = this.getProject();
if (action == null) {
datasetController.delete(project, user, datasetPath.getFullPath(), datasetPath.getDataset(), datasetPath.isTopLevelDataset());
} else {
switch(action) {
case UNSHARE:
checkIfDataOwner(project, user);
datasetController.unshare(project, user, datasetPath.getDataset(), targetProject);
break;
case CORRUPTED:
if (datasetPath.isTopLevelDataset()) {
throw new IllegalArgumentException("Use DELETE /{datasetName} to delete top level dataset)");
}
datasetController.deleteCorrupted(project, user, datasetPath.getFullPath(), datasetPath.getDataset());
break;
default:
throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
}
}
return Response.noContent().build();
}
use of io.hops.hopsworks.common.dataset.util.DatasetPath in project hopsworks by logicalclocks.
the class DatasetResource method update.
@PUT
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@ApiOperation(value = "Set permissions (potentially with sticky bit) for datasets", notes = "Allow data scientists to create and modify own files in dataset.", response = DatasetDTO.class)
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.DATASET_CREATE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response update(@PathParam("path") String path, @QueryParam("type") DatasetType datasetType, @QueryParam("action") DatasetActions.Put action, @QueryParam("description") String description, @DefaultValue("READ_ONLY") @QueryParam("permissions") DatasetAccessPermission datasetPermissions, @QueryParam("target_project") String targetProjectName, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ProjectException, MetadataException, SchematizedTagException, FeaturestoreException {
Project project = this.getProject();
DatasetPath datasetPath = datasetHelper.getDatasetPath(project, path, datasetType);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.DATASET);
Users user = jwtHelper.getUserPrincipal(sc);
DatasetDTO dto;
switch(action == null ? DatasetActions.Put.DESCRIPTION : action) {
case PERMISSION:
checkIfDataOwner(project, user);
datasetController.updatePermission(datasetPath.getDataset(), datasetPermissions, project, project, user);
dto = datasetBuilder.build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
break;
case SHARE_PERMISSION:
checkIfDataOwner(project, user);
datasetController.updateSharePermission(datasetPath.getDataset(), datasetPermissions, project, targetProjectName, user);
dto = datasetBuilder.build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
break;
case DESCRIPTION:
datasetController.updateDescription(project, user, datasetPath.getDataset(), description);
dto = datasetBuilder.build(uriInfo, resourceRequest, user, datasetPath, null, null, false);
break;
default:
throw new WebApplicationException("Action not valid.", Response.Status.NOT_FOUND);
}
return Response.ok(dto).build();
}
Aggregations