Search in sources :

Example 1 with DatasetDTO

use of io.hops.hopsworks.api.dataset.DatasetDTO 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)

Aggregations

Longs (com.google.common.primitives.Longs)1 DatasetBuilder (io.hops.hopsworks.api.dataset.DatasetBuilder)1 DatasetDTO (io.hops.hopsworks.api.dataset.DatasetDTO)1 JobDTO (io.hops.hopsworks.api.jobs.JobDTO)1 JobsBuilder (io.hops.hopsworks.api.jobs.JobsBuilder)1 ExecutionDTO (io.hops.hopsworks.api.jobs.executions.ExecutionDTO)1 ExecutionsBuilder (io.hops.hopsworks.api.jobs.executions.ExecutionsBuilder)1 ProvArtifactUsageDTO (io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageDTO)1 ProvArtifactUsageParentDTO (io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO)1 UserDTO (io.hops.hopsworks.api.user.UserDTO)1 UsersBuilder (io.hops.hopsworks.api.user.UsersBuilder)1 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)1 HdfsUsersFacade (io.hops.hopsworks.common.dao.hdfsUser.HdfsUsersFacade)1 ExecutionFacade (io.hops.hopsworks.common.dao.jobhistory.ExecutionFacade)1 UserFacade (io.hops.hopsworks.common.dao.user.UserFacade)1 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)1 Provenance (io.hops.hopsworks.common.provenance.core.Provenance)1 ProvOps (io.hops.hopsworks.common.provenance.ops.ProvOps)1 ProvOpsAggregations (io.hops.hopsworks.common.provenance.ops.ProvOpsAggregations)1 ProvOpsParamBuilder (io.hops.hopsworks.common.provenance.ops.ProvOpsParamBuilder)1