use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class Register method createRemoteUser.
private void createRemoteUser(HttpServletRequest httpServletRequest) {
try {
RemoteUserDTO userDTO = ldapConfigHelper.getLdapHelper().getRemoteUserByUuid(this.uuid);
if (email == null || email.isEmpty()) {
// email is needed for audit
email = userDTO.getEmail().isEmpty() ? null : userDTO.getEmail().get(0);
}
if (email == null || email.isEmpty()) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "Email not provided.");
}
auditedUserAdministration.createRemoteUser(userDTO, email, firstName, lastName, UserAccountStatus.fromValue(status), RemoteUserType.fromValue(remoteUserType), httpServletRequest);
restAll();
MessagesController.addInfoMessage("Success", "User created.", "msg");
} catch (UserException | GenericException e) {
showErrorMsg("Create remote user failed.", e);
}
}
use of io.hops.hopsworks.exceptions.GenericException 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;
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class ExperimentsResource method get.
@ApiOperation(value = "Get an experiment", response = ExperimentDTO.class)
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@PathParam("id") String id, @BeanParam ExpansionBeanParam expansions, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ExperimentsException, DatasetException, ProvenanceException, MetadataException, GenericException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXPERIMENTS);
resourceRequest.setExpansions(expansions.getResources());
ProvStateDTO fileState = experimentsController.getExperiment(project, id);
Users user = jwtHelper.getUserPrincipal(sc);
if (fileState != null) {
Map<Long, ExperimentsEndpointDTO> endpoints = new HashMap<>();
endpoints.put(project.getInode().getId(), experimentsController.getExperimentsEndpoint(project));
ExperimentDTO dto = experimentsBuilder.build(uriInfo, resourceRequest, project, user, endpoints, fileState);
if (dto == null) {
throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.FINE);
} else {
return Response.ok().entity(dto).build();
}
} else {
throw new ExperimentsException(RESTCodes.ExperimentsErrorCode.EXPERIMENT_NOT_FOUND, Level.FINE);
}
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class ElasticFeaturestoreBuilder method setFeatureDescriptionHighlights.
private void setFeatureDescriptionHighlights(SearchHit hitAux, ElasticFeaturestoreDTO result, DatasetAccessController.DatasetAccessCtrl accessCtrl) throws ElasticException, GenericException {
ElasticFeaturestoreHit hit = ElasticFeaturestoreHit.instance(hitAux);
Map<String, HighlightField> highlightFields = hitAux.getHighlightFields();
String featureDescriptionField = FeaturestoreXAttrsConstants.getFeaturestoreElasticKey(FeaturestoreXAttrsConstants.FG_FEATURES, FeaturestoreXAttrsConstants.DESCRIPTION);
// <highlighted text, name, description>
Function<Triplet<String, String, String>, Boolean> matcher = (state) -> {
// check if highlighted description equals feature description
return removeHighlightTags(state.getValue0()).equals(state.getValue2());
};
BiConsumer<ElasticFeaturestoreItemDTO.Highlights, String> highlighter = ElasticFeaturestoreItemDTO.Highlights::setDescription;
setFeatureHighlights(highlightFields.get(featureDescriptionField), hit, matcher, highlighter, result, accessCtrl);
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class ElasticFeaturestoreBuilder method setFeatureHighlights.
private void setFeatureHighlights(HighlightField hField, ElasticFeaturestoreHit hit, Function<Triplet<String, String, String>, Boolean> matcher, BiConsumer<ElasticFeaturestoreItemDTO.Highlights, String> highlighter, ElasticFeaturestoreDTO result, DatasetAccessController.DatasetAccessCtrl accessCtrl) throws GenericException {
if (hField != null) {
// highlights only return the field that matched the search, we will check the xattr for the omologue for
// complete info
@SuppressWarnings("unchecked") Map<String, Object> featurestore = (Map) (hit.getXattrs().get(FeaturestoreXAttrsConstants.FEATURESTORE));
@SuppressWarnings("unchecked") ArrayList<Map<String, String>> hit_fg_features = (ArrayList<Map<String, String>>) featurestore.get(FeaturestoreXAttrsConstants.FG_FEATURES);
for (Text ee : hField.fragments()) {
// looking through all highligths
for (Map<String, String> hit_fg_feature : hit_fg_features) {
// comparing to each feature (from xattr)
String featureNameAux = null;
String featureDescriptionAux = "";
// features are stored as an array of hashes [{name:<>, description:<>}]
for (Map.Entry<String, String> hit_fg_feature_e : hit_fg_feature.entrySet()) {
switch(hit_fg_feature_e.getKey()) {
case FeaturestoreXAttrsConstants.NAME:
featureNameAux = hit_fg_feature_e.getValue();
break;
case FeaturestoreXAttrsConstants.DESCRIPTION:
featureDescriptionAux = hit_fg_feature_e.getValue();
break;
}
}
if (featureNameAux == null) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_STATE, Level.WARNING, "elastic indices might contain malformed entries");
}
// does the feature match the highlight (name/description)
if (matcher.apply(Triplet.with(ee.toString(), featureNameAux, featureDescriptionAux))) {
ElasticFeaturestoreItemDTO.Feature feature = result.getFeature(hit.getProjectName(), featureNameAux);
if (feature == null) {
ElasticFeaturestoreItemDTO.Base fgParent = elasticFeaturestoreItemBuilder.fromFeaturegroup(hit, converter);
feature = elasticFeaturestoreItemBuilder.fromFeature(featureNameAux, featureDescriptionAux, fgParent);
result.addFeature(feature);
accessCtrl.accept(inputWrapper(hit), collectorWrapper(feature));
}
ElasticFeaturestoreItemDTO.Highlights highlights = feature.getHighlights();
if (highlights == null) {
highlights = new ElasticFeaturestoreItemDTO.Highlights();
feature.setHighlights(highlights);
}
// set the appropriate highlight (name/description)
highlighter.accept(highlights, ee.toString());
}
}
}
}
}
Aggregations