Search in sources :

Example 36 with GenericException

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);
    }
}
Also used : UserException(io.hops.hopsworks.exceptions.UserException) RemoteUserDTO(io.hops.hopsworks.common.remote.RemoteUserDTO) GenericException(io.hops.hopsworks.exceptions.GenericException)

Example 37 with GenericException

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

Example 38 with GenericException

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);
    }
}
Also used : ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) HashMap(java.util.HashMap) ExperimentDTO(io.hops.hopsworks.api.experiments.dto.ExperimentDTO) ExperimentsEndpointDTO(io.hops.hopsworks.api.experiments.dto.ExperimentsEndpointDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Users(io.hops.hopsworks.persistence.entity.user.Users) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) GenericException(io.hops.hopsworks.exceptions.GenericException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 39 with GenericException

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);
}
Also used : HopsworksJAXBContext(io.hops.hopsworks.common.util.HopsworksJAXBContext) ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) FeaturestoreXAttrsConstants(io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants) Function(java.util.function.Function) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) TransactionAttributeType(javax.ejb.TransactionAttributeType) Triplet(org.javatuples.Triplet) Text(org.elasticsearch.common.text.Text) TransactionAttribute(javax.ejb.TransactionAttribute) Map(java.util.Map) ElasticException(io.hops.hopsworks.exceptions.ElasticException) SearchResponse(org.elasticsearch.action.search.SearchResponse) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) BiConsumer(java.util.function.BiConsumer) EJB(javax.ejb.EJB) SearchHit(org.elasticsearch.search.SearchHit) Stateless(javax.ejb.Stateless) Set(java.util.Set) ElasticController(io.hops.hopsworks.common.elastic.ElasticController) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) ServiceException(io.hops.hopsworks.exceptions.ServiceException) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) GenericException(io.hops.hopsworks.exceptions.GenericException) FeaturestoreDocType(io.hops.hopsworks.common.elastic.FeaturestoreDocType) Users(io.hops.hopsworks.persistence.entity.user.Users) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) Triplet(org.javatuples.Triplet) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField)

Example 40 with GenericException

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());
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Text(org.elasticsearch.common.text.Text) GenericException(io.hops.hopsworks.exceptions.GenericException) Map(java.util.Map)

Aggregations

GenericException (io.hops.hopsworks.exceptions.GenericException)43 Users (io.hops.hopsworks.persistence.entity.user.Users)17 Project (io.hops.hopsworks.persistence.entity.project.Project)16 ProjectException (io.hops.hopsworks.exceptions.ProjectException)13 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 ServiceException (io.hops.hopsworks.exceptions.ServiceException)12 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)11 ElasticException (io.hops.hopsworks.exceptions.ElasticException)10 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)10 JobException (io.hops.hopsworks.exceptions.JobException)9 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)9 Produces (javax.ws.rs.Produces)9 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)8 ArrayList (java.util.ArrayList)8 TransactionAttribute (javax.ejb.TransactionAttribute)8 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)6 UserException (io.hops.hopsworks.exceptions.UserException)6 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)6