Search in sources :

Example 16 with ProvenanceException

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

the class ProvStateController method provFileStateCount.

private ProvStateDTO provFileStateCount(Long projectIId, Map<ProvParser.Field, ProvParser.FilterVal> fileStateFilters, Map<String, String> xAttrsFilters, Map<String, String> likeXAttrsFilters, Set<String> hasXAttrsFilters) throws ProvenanceException {
    CheckedSupplier<SearchRequest, ProvenanceException> srF = ElasticHelper.countSearchRequest(settings.getProvFileIndex(projectIId)).andThen(filterByStateParams(fileStateFilters, xAttrsFilters, likeXAttrsFilters, hasXAttrsFilters));
    SearchRequest request = srF.get();
    Long searchResult;
    try {
        searchResult = client.searchCount(request);
    } catch (ElasticException e) {
        String msg = "provenance - elastic query problem";
        throw ProvHelper.fromElastic(e, msg, msg + " - file state count");
    }
    ProvStateDTO container = new ProvStateDTO();
    container.setCount(searchResult);
    return container;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ElasticException(io.hops.hopsworks.exceptions.ElasticException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO)

Example 17 with ProvenanceException

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

the class ProvenanceCleanerController method getProject.

private Project getProject(String indexName) throws ProvenanceException {
    int endIndex = indexName.indexOf(Settings.PROV_FILE_INDEX_SUFFIX);
    String sInodeId = indexName.substring(0, endIndex);
    long inodeId;
    try {
        inodeId = Long.parseLong(sInodeId);
    } catch (NumberFormatException e) {
        throw new ProvenanceException(RESTCodes.ProvenanceErrorCode.INTERNAL_ERROR, Level.WARNING, "error extracting project from prov index name - format error", e.getMessage(), e);
    }
    Inode inode = inodeFacade.findById(inodeId);
    if (inode == null) {
        return null;
    }
    return projectFacade.findByInodeId(inode.getInodePK().getParentId(), inode.getInodePK().getName());
}
Also used : ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)

Example 18 with ProvenanceException

use of io.hops.hopsworks.exceptions.ProvenanceException 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 19 with ProvenanceException

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

the class ProvAppStateElastic method instance.

public static ProvAppStateElastic instance(BasicElasticHit hit) throws ProvenanceException {
    ProvAppStateElastic result = new ProvAppStateElastic();
    result.id = hit.getId();
    result.score = hit.getScore();
    result.map = hit.getSource();
    Map<String, Object> map = new HashMap<>(result.map);
    try {
        // Even though we define in the elastic mapping a Long,
        // if the value is small, it seems to be retrieved as an Integer
        // so we need to do the complicated castings lambda
        result.appId = ProvHelper.extractElasticField(map, ProvAParser.Field.APP_ID);
        result.appState = ProvHelper.extractElasticField(map, ProvAParser.Field.APP_STATE);
        result.appStateTimestamp = ProvHelper.extractElasticField(map, ProvAParser.Field.TIMESTAMP);
        result.appName = ProvHelper.extractElasticField(map, ProvAParser.Field.APP_NAME);
        result.appUser = ProvHelper.extractElasticField(map, ProvAParser.Field.APP_USER);
        result.readableTimestamp = ProvHelper.extractElasticField(map, ProvAParser.Field.R_TIMESTAMP);
        if (!map.isEmpty()) {
            LOGGER.log(Level.FINE, "fields:{0} not managed in file state return", map.keySet());
        }
    } catch (ClassCastException e) {
        String msg = "mismatch between DTO class and ProvAParser field types (elastic)";
        throw new ProvenanceException(RESTCodes.ProvenanceErrorCode.INTERNAL_ERROR, Level.WARNING, msg, msg, e);
    }
    return result;
}
Also used : ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) HashMap(java.util.HashMap)

Example 20 with ProvenanceException

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

the class ExperimentsBuilder method build.

// Build collection
public ExperimentDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, Users user) throws ExperimentsException {
    ExperimentDTO dto = new ExperimentDTO();
    uri(dto, uriInfo, project);
    expand(dto, resourceRequest);
    dto.setCount(0l);
    validatePagination(resourceRequest);
    if (dto.isExpand()) {
        try {
            Pair<ProvStateParamBuilder, Map<Long, ExperimentsEndpointDTO>> provFilesParamBuilder = buildExperimentProvenanceParams(project, resourceRequest);
            if (provFilesParamBuilder.getValue1().isEmpty()) {
                // no endpoint - no results
                return dto;
            }
            ProvStateDTO fileState = provenanceController.provFileStateList(project, provFilesParamBuilder.getValue0());
            if (fileState != null) {
                List<ProvStateDTO> experiments = fileState.getItems();
                dto.setCount(fileState.getCount());
                if (experiments != null && !experiments.isEmpty()) {
                    for (ProvStateDTO fileProvStateHit : experiments) {
                        ExperimentDTO experimentDTO = build(uriInfo, resourceRequest, project, user, provFilesParamBuilder.getValue1(), fileProvStateHit);
                        if (experimentDTO != null) {
                            dto.addItem(experimentDTO);
                        }
                    }
                }
            }
        } catch (ExperimentsException | DatasetException | ProvenanceException | MetadataException | GenericException e) {
            if (e instanceof ProvenanceException && ProvHelper.missingMappingForField((ProvenanceException) e)) {
                LOGGER.log(Level.WARNING, "Could not find elastic mapping for experiments query", e);
                return dto;
            } else {
                throw new ExperimentsException(RESTCodes.ExperimentsErrorCode.EXPERIMENT_LIST_FAILED, Level.FINE, "Unable to list experiments for project " + project.getName(), e.getMessage(), e);
            }
        }
    }
    return dto;
}
Also used : ProvStateParamBuilder(io.hops.hopsworks.common.provenance.state.ProvStateParamBuilder) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) ExperimentDTO(io.hops.hopsworks.api.experiments.dto.ExperimentDTO) Map(java.util.Map) HashMap(java.util.HashMap) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) GenericException(io.hops.hopsworks.exceptions.GenericException) MetadataException(io.hops.hopsworks.exceptions.MetadataException) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Aggregations

ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)20 DatasetException (io.hops.hopsworks.exceptions.DatasetException)7 ElasticException (io.hops.hopsworks.exceptions.ElasticException)6 GenericException (io.hops.hopsworks.exceptions.GenericException)6 ProvStateDTO (io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO)4 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)4 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)4 MetadataException (io.hops.hopsworks.exceptions.MetadataException)4 Users (io.hops.hopsworks.persistence.entity.user.Users)4 IOException (java.io.IOException)4 Produces (javax.ws.rs.Produces)4 Try (com.lambdista.util.Try)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)3 ProjectException (io.hops.hopsworks.exceptions.ProjectException)3 ServiceException (io.hops.hopsworks.exceptions.ServiceException)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 Project (io.hops.hopsworks.persistence.entity.project.Project)3 ApiOperation (io.swagger.annotations.ApiOperation)3 SQLException (java.sql.SQLException)3