Search in sources :

Example 36 with DatasetException

use of io.hops.hopsworks.exceptions.DatasetException in project hopsworks by logicalclocks.

the class ProjectService method getReadmeByInodeId.

@GET
@Path("/readme/byInodeId/{inodeId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getReadmeByInodeId(@PathParam("inodeId") Long inodeId, @Context SecurityContext sc) throws DatasetException {
    if (inodeId == null) {
        throw new IllegalArgumentException("No inodeId provided.");
    }
    Inode inode = inodes.findById(inodeId);
    Inode parent = inodes.findParent(inode);
    Project proj = projectFacade.findByName(parent.getInodePK().getName());
    Dataset ds = datasetFacade.findByProjectAndInode(proj, inode);
    if (ds != null && !ds.isSearchable()) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.README_NOT_ACCESSIBLE, Level.FINE);
    }
    DistributedFileSystemOps dfso = dfs.getDfsOps();
    FilePreviewDTO filePreviewDTO;
    String path = inodeController.getPath(inode);
    try {
        filePreviewDTO = datasetController.getReadme(path + "/README.md", dfso);
    } catch (IOException ex) {
        filePreviewDTO = new FilePreviewDTO();
        filePreviewDTO.setContent("No README file found for this dataset.");
        return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(filePreviewDTO).build();
    }
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(filePreviewDTO).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) FilePreviewDTO(io.hops.hopsworks.common.dataset.FilePreviewDTO) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) IOException(java.io.IOException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with DatasetException

use of io.hops.hopsworks.exceptions.DatasetException in project hopsworks by logicalclocks.

the class ProvUsageBuilder method buildAccessible.

public ProvArtifactUsageParentDTO buildAccessible(UriInfo uriInfo, Users user, DatasetPath targetEndpoint, String artifactId, Set<ProvUsageType> type) throws ProvenanceException, GenericException, DatasetException, MetadataException, SchematizedTagException {
    if (!accessController.hasAccess(targetEndpoint.getAccessProject(), targetEndpoint.getDataset())) {
        throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.FINE);
    }
    ProvArtifactUsageParentDTO usage = new ProvArtifactUsageParentDTO();
    usage.setArtifactId(artifactId);
    DatasetDTO datasetDTO = datasetBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.DATASET), user, targetEndpoint);
    usage.setDataset(datasetDTO);
    usage.setProjectId(targetEndpoint.getDataset().getProject().getId());
    usage.setProjectName(targetEndpoint.getDataset().getProject().getName());
    ProvOpsParamBuilder params = getBasicUsageOpsParams(targetEndpoint.getDataset(), artifactId);
    ProvOpsDTO ops = opsBuilder.build(targetEndpoint.getDataset().getProject(), params, ProvOpsReturnType.AGGREGATIONS);
    Optional<ProvOpsDTO> aggregation = ops.getItems().stream().filter(agg -> agg.getAggregation() != null && agg.getAggregation().equals(ProvOpsAggregations.APP_USAGE.toString())).findFirst();
    if (!aggregation.isPresent()) {
        return usage;
    }
    Optional<ProvOpsDTO> artifact = aggregation.get().getItems().stream().filter(art -> art.getMlId().equals(artifactId)).findFirst();
    if (!artifact.isPresent()) {
        return usage;
    }
    for (ProvUsageType t : type) {
        switch(t) {
            case READ_CURRENT:
                usage.setReadCurrent(usage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA, true));
                break;
            case WRITE_CURRENT:
                usage.setWriteCurrent(usage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA, true));
                break;
            case READ_LAST:
                lastUsage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA).ifPresent(usage::setReadLast);
                break;
            case WRITE_LAST:
                lastUsage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA).ifPresent(usage::setWriteLast);
                break;
            case READ_HISTORY:
                usage.setReadHistory(usage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA, false));
                break;
            case WRITE_HISTORY:
                usage.setWriteHistory(usage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA, false));
                break;
        }
    }
    return usage;
}
Also used : DatasetDTO(io.hops.hopsworks.api.dataset.DatasetDTO) UserFacade(io.hops.hopsworks.common.dao.user.UserFacade) ProvOps(io.hops.hopsworks.common.provenance.ops.ProvOps) AccessController(io.hops.hopsworks.common.util.AccessController) ExecutionFacade(io.hops.hopsworks.common.dao.jobhistory.ExecutionFacade) ExecutionsBuilder(io.hops.hopsworks.api.jobs.executions.ExecutionsBuilder) HdfsUsersFacade(io.hops.hopsworks.common.dao.hdfsUser.HdfsUsersFacade) Provenance(io.hops.hopsworks.common.provenance.core.Provenance) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Execution(io.hops.hopsworks.persistence.entity.jobs.history.Execution) Level(java.util.logging.Level) UsersBuilder(io.hops.hopsworks.api.user.UsersBuilder) TransactionAttributeType(javax.ejb.TransactionAttributeType) MetadataException(io.hops.hopsworks.exceptions.MetadataException) TransactionAttribute(javax.ejb.TransactionAttribute) ProvOpsAggregations(io.hops.hopsworks.common.provenance.ops.ProvOpsAggregations) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UserDTO(io.hops.hopsworks.api.user.UserDTO) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) JobsBuilder(io.hops.hopsworks.api.jobs.JobsBuilder) EJB(javax.ejb.EJB) ExecutionDTO(io.hops.hopsworks.api.jobs.executions.ExecutionDTO) Stateless(javax.ejb.Stateless) Longs(com.google.common.primitives.Longs) ProvArtifactUsageParentDTO(io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO) ProvOpsDTO(io.hops.hopsworks.common.provenance.ops.dto.ProvOpsDTO) DatasetDTO(io.hops.hopsworks.api.dataset.DatasetDTO) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Set(java.util.Set) ProvArtifactUsageDTO(io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageDTO) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) ProvOpsParamBuilder(io.hops.hopsworks.common.provenance.ops.ProvOpsParamBuilder) List(java.util.List) ProvUsageType(io.hops.hopsworks.common.provenance.ops.ProvUsageType) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) GenericException(io.hops.hopsworks.exceptions.GenericException) ProvOpsReturnType(io.hops.hopsworks.common.provenance.ops.ProvOpsReturnType) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) JobDTO(io.hops.hopsworks.api.jobs.JobDTO) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) Users(io.hops.hopsworks.persistence.entity.user.Users) Comparator(java.util.Comparator) DatasetBuilder(io.hops.hopsworks.api.dataset.DatasetBuilder) SchematizedTagException(io.hops.hopsworks.exceptions.SchematizedTagException) ProvArtifactUsageParentDTO(io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO) ProvOpsParamBuilder(io.hops.hopsworks.common.provenance.ops.ProvOpsParamBuilder) ProvOpsDTO(io.hops.hopsworks.common.provenance.ops.dto.ProvOpsDTO) ProvUsageType(io.hops.hopsworks.common.provenance.ops.ProvUsageType) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) GenericException(io.hops.hopsworks.exceptions.GenericException)

Example 38 with DatasetException

use of io.hops.hopsworks.exceptions.DatasetException in project hopsworks by logicalclocks.

the class TrainingDatasetService method provenance.

@Path("/{trainingDatasetId}/provenance")
public ProvArtifactResource provenance(@PathParam("trainingDatasetId") Integer trainingDatasetId) throws FeaturestoreException, GenericException {
    String tdName = featurestore.getProject().getName() + "_" + Settings.ServiceDataset.TRAININGDATASETS.getName();
    DatasetPath targetEndpointPath;
    try {
        Dataset targetEndpoint = datasetController.getByName(featurestore.getProject(), tdName);
        targetEndpointPath = datasetHelper.getTopLevelDatasetPath(project, targetEndpoint);
    } catch (DatasetException ex) {
        throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "training dataset not found");
    }
    this.provenanceResource.setContext(project, targetEndpointPath);
    TrainingDataset td = trainingDatasetController.getTrainingDatasetById(featurestore, trainingDatasetId);
    this.provenanceResource.setArtifactId(td.getName(), td.getVersion());
    return provenanceResource;
}
Also used : TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) GenericException(io.hops.hopsworks.exceptions.GenericException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath)

Example 39 with DatasetException

use of io.hops.hopsworks.exceptions.DatasetException in project hopsworks by logicalclocks.

the class FeaturegroupService method provenance.

@Path("/{featureGroupId}/provenance")
public ProvArtifactResource provenance(@PathParam("featureGroupId") Integer featureGroupId) throws FeaturestoreException, GenericException {
    DatasetPath targetEndpointPath;
    try {
        Dataset targetEndpoint = featurestoreController.getProjectFeaturestoreDataset(featurestore.getProject());
        targetEndpointPath = datasetHelper.getTopLevelDatasetPath(project, targetEndpoint);
    } catch (DatasetException ex) {
        throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "training dataset not found");
    }
    this.provenanceResource.setContext(project, targetEndpointPath);
    Featuregroup fg = featuregroupController.getFeaturegroupById(featurestore, featureGroupId);
    this.provenanceResource.setArtifactId(fg.getName(), fg.getVersion());
    return provenanceResource;
}
Also used : Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) GenericException(io.hops.hopsworks.exceptions.GenericException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath)

Example 40 with DatasetException

use of io.hops.hopsworks.exceptions.DatasetException in project hopsworks by logicalclocks.

the class DatasetController method changePermissions.

public void changePermissions(Dataset ds, PermissionTransition permissionTransition, Project targetProject) throws DatasetException {
    if (permissionTransition.noop()) {
        datasetFacade.update(ds);
        return;
    }
    ds.setPermission(permissionTransition.getTo());
    try {
        hdfsUsersController.changePermission(ds, targetProject, permissionTransition);
    } catch (IOException e) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PERMISSION_ERROR, Level.WARNING, "dataset: " + ds.getName(), e.getMessage(), e);
    }
    datasetFacade.update(ds);
}
Also used : IOException(java.io.IOException) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Aggregations

DatasetException (io.hops.hopsworks.exceptions.DatasetException)66 Project (io.hops.hopsworks.persistence.entity.project.Project)28 IOException (java.io.IOException)27 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)24 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)20 Produces (javax.ws.rs.Produces)15 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)13 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)13 Users (io.hops.hopsworks.persistence.entity.user.Users)13 Path (org.apache.hadoop.fs.Path)13 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)12 ProjectException (io.hops.hopsworks.exceptions.ProjectException)12 DatasetSharedWith (io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith)12 Path (javax.ws.rs.Path)11 GET (javax.ws.rs.GET)10 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)9 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)9 GenericException (io.hops.hopsworks.exceptions.GenericException)9 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)9 ApiOperation (io.swagger.annotations.ApiOperation)9