Skip to content

[backend] Update dependency co.elastic.clients:elasticsearch-java to v9 (release/current) #3114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: release/current
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ services:
POSTGRES_PASSWORD: openbas
POSTGRES_DB: openbas
- name: elastic
image: docker.elastic.co/elasticsearch/elasticsearch:8.18.0
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
environment:
discovery.type: single-node
xpack.security.enabled: false
Expand Down
1 change: 0 additions & 1 deletion openbas-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<apache-poi.version>5.4.1</apache-poi.version>
<opentelemetry.version>1.50.0</opentelemetry.version>
<opentelemetry-semconv.version>1.32.0</opentelemetry-semconv.version>
<elasticsearch.version>8.18.1</elasticsearch.version>
</properties>

<profiles>
Expand Down
4 changes: 2 additions & 2 deletions openbas-dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ services:
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
openbas-dev-elasticsearch:
container_name: openbas-dev-elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:8.18.0
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
volumes:
- esdata:/usr/share/elasticsearch/data
- essnapshots:/usr/share/elasticsearch/snapshots
Expand All @@ -106,7 +106,7 @@ services:
- 9300:9300
openbas-dev-kibana:
container_name: openbas-dev-kibana
image: docker.elastic.co/kibana/kibana:8.18.0
image: docker.elastic.co/kibana/kibana:9.0.1
environment:
- ELASTICSEARCH_HOSTS=http://openbas-dev-elasticsearch:9200
restart: unless-stopped
Expand Down
4 changes: 0 additions & 4 deletions openbas-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
<name>OpenBAS model</name>
<description>OpenBAS model</description>

<properties>
<elasticsearch.version>8.18.1</elasticsearch.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
49 changes: 29 additions & 20 deletions openbas-model/src/main/java/io/openbas/driver/ElasticDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import co.elastic.clients.transport.rest5_client.Rest5ClientTransport;
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
import co.elastic.clients.transport.rest5_client.low_level.Rest5ClientBuilder;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand All @@ -24,6 +26,7 @@
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.net.URISyntaxException;
import java.security.cert.X509Certificate;
import java.time.Instant;
import java.util.HashMap;
Expand All @@ -34,15 +37,16 @@
import javax.net.ssl.SSLContext;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.annotation.Backoff;
Expand All @@ -68,14 +72,15 @@ public void setEsEngine(EsEngine esEngine) {
this.esEngine = esEngine;
}

public ElasticsearchClient getElasticClient() {
RestClientBuilder restClientBuilder = RestClient.builder(HttpHost.create(config.getUrl()));
public ElasticsearchClient getElasticClient() throws URISyntaxException {
Rest5ClientBuilder restClientBuilder = Rest5Client.builder(HttpHost.create(config.getUrl()));
HttpAsyncClientBuilder clientBuilder = HttpAsyncClientBuilder.create();
if (config.getUsername() != null) {
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
credsProv.setCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials(config.getUsername(), config.getPassword()));
new AuthScope(null, -1),
new UsernamePasswordCredentials(
config.getUsername(), config.getPassword().toCharArray()));
clientBuilder.setDefaultCredentialsProvider(credsProv);
}
if (!config.isRejectUnauthorized()) {
Expand All @@ -85,20 +90,24 @@ public ElasticsearchClient getElasticClient() {
SSLContextBuilder.create()
.loadTrustMaterial(null, (X509Certificate[] chain, String authType) -> true)
.build();
clientBuilder
.setSSLContext(sslContext)
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
PoolingAsyncClientConnectionManager connectionManager =
PoolingAsyncClientConnectionManagerBuilder.create()
.setTlsStrategy(
new DefaultClientTlsStrategy(sslContext, NoopHostnameVerifier.INSTANCE))
.build();

clientBuilder.setConnectionManager(connectionManager);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
restClientBuilder.setHttpClientConfigCallback(hc -> clientBuilder);
RestClient restClient = restClientBuilder.build();
restClientBuilder.setHttpClient(clientBuilder.build());
Rest5Client restClient = restClientBuilder.build();
JacksonJsonpMapper jsonpMapper = new JacksonJsonpMapper();
jsonpMapper.objectMapper().registerModule(new JavaTimeModule());
jsonpMapper.objectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
jsonpMapper.objectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ElasticsearchTransport transport = new RestClientTransport(restClient, jsonpMapper);
ElasticsearchTransport transport = new Rest5ClientTransport(restClient, jsonpMapper);
return new ElasticsearchClient(transport);
}

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<jacoco-plugin.version>0.8.13</jacoco-plugin.version>
<pyroscope.version>2.1.2</pyroscope.version>
<spring-security-crypto.version>6.4.5</spring-security-crypto.version>
<elasticsearch.version>9.0.1</elasticsearch.version>
</properties>

<distributionManagement>
Expand Down