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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations