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