Search in sources :

Example 31 with ElasticException

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

the class ElasticClient method getClient.

public synchronized RestHighLevelClient getClient() throws ElasticException {
    if (elasticClient == null) {
        HttpHost[] elasticAddrs = getElasticIps();
        final boolean isSecurityEnabled = settings.isElasticOpenDistroSecurityEnabled();
        SSLContext sslCtx = null;
        CredentialsProvider credentialsProvider = null;
        if (isSecurityEnabled) {
            Path trustStore = Paths.get(clientsService.getSuperTrustStorePath());
            char[] trustStorePassword = clientsService.getSuperTrustStorePassword().toCharArray();
            try {
                sslCtx = SSLContexts.custom().loadTrustMaterial(trustStore.toFile(), trustStorePassword).build();
            } catch (GeneralSecurityException | IOException e) {
                throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_CONNECTION_ERROR, Level.INFO, "Error while setting up connections to " + "elasticsearch", e.getMessage(), e);
            }
            credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getElasticAdminUser(), settings.getElasticAdminPassword()));
        }
        final SSLContext finalSslCtx = sslCtx;
        final CredentialsProvider finalCredentialsProvider = credentialsProvider;
        elasticClient = new RestHighLevelClient(RestClient.builder(elasticAddrs).setHttpClientConfigCallback(httpAsyncClientBuilder -> {
            httpAsyncClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(Settings.ELASTIC_KIBANA_NO_CONNECTIONS).build());
            if (isSecurityEnabled) {
                return httpAsyncClientBuilder.setSSLContext(finalSslCtx).setDefaultCredentialsProvider(finalCredentialsProvider).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
            }
            return httpAsyncClientBuilder;
        }));
    }
    return elasticClient;
}
Also used : Path(java.nio.file.Path) ElasticException(io.hops.hopsworks.exceptions.ElasticException) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) GeneralSecurityException(java.security.GeneralSecurityException) SSLContext(javax.net.ssl.SSLContext) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) IOException(java.io.IOException) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HttpHost(org.apache.http.HttpHost)

Example 32 with ElasticException

use of io.hops.hopsworks.exceptions.ElasticException 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)

Aggregations

ElasticException (io.hops.hopsworks.exceptions.ElasticException)32 ServiceException (io.hops.hopsworks.exceptions.ServiceException)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)8 GenericException (io.hops.hopsworks.exceptions.GenericException)6 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)6 Project (io.hops.hopsworks.persistence.entity.project.Project)6 IOException (java.io.IOException)6 SearchHit (org.elasticsearch.search.SearchHit)6 ArrayList (java.util.ArrayList)5 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)5 Users (io.hops.hopsworks.persistence.entity.user.Users)4 Map (java.util.Map)4 TransactionAttribute (javax.ejb.TransactionAttribute)4 Try (com.lambdista.util.Try)3 ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)3 ElasticController (io.hops.hopsworks.common.elastic.ElasticController)3 ElasticFeaturestoreHit (io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit)3 FeaturestoreDocType (io.hops.hopsworks.common.elastic.FeaturestoreDocType)3 FeaturestoreXAttrsConstants (io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants)3 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)3