diff --git a/src/main/java/org/gridsuite/modification/server/elasticsearch/ESConfig.java b/src/main/java/org/gridsuite/modification/server/elasticsearch/ESConfig.java deleted file mode 100644 index 3a77882d5..000000000 --- a/src/main/java/org/gridsuite/modification/server/elasticsearch/ESConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (c) 2021, RTE (http://www.rte-france.com) - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.modification.server.elasticsearch; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.elasticsearch.client.ClientConfiguration; -import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration; -import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; - -import javax.annotation.Nonnull; -import java.util.Optional; - -/** - * A class to configure DB elasticsearch client for indexation - * - * @author Slimane Amar - */ - -@Configuration -@EnableElasticsearchRepositories -public class ESConfig extends ElasticsearchConfiguration { - - @Value("#{'${spring.data.elasticsearch.embedded:false}' ? 'localhost' : '${spring.data.elasticsearch.host}'}") - private String esHost; - - @Value("#{'${spring.data.elasticsearch.embedded:false}' ? '${spring.data.elasticsearch.embedded.port:}' : '${spring.data.elasticsearch.port}'}") - private int esPort; - - @Value("${spring.data.elasticsearch.client.timeout:60}") - int timeout; - - @Value("${spring.data.elasticsearch.username:#{null}}") - private Optional username; - - @Value("${spring.data.elasticsearch.password:#{null}}") - private Optional password; - - //It should be detected without specifying the name, but it isn't. To investigate. - @Bean(name = "elasticsearchClientConfiguration") - @Override - @SuppressWarnings("squid:S2095") - @Nonnull - public ClientConfiguration clientConfiguration() { - var clientConfiguration = ClientConfiguration.builder() - .connectedTo(esHost + ":" + esPort) - .withConnectTimeout(timeout * 1000L).withSocketTimeout(timeout * 1000L); - - if (username.isPresent() && password.isPresent()) { - clientConfiguration.withBasicAuth(username.get(), password.get()); - } - - return clientConfiguration.build(); - } -} diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index dd5e686f9..af261c85b 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -19,12 +19,12 @@ gridsuite: spring: rabbitmq: addresses: localhost - data: - elasticsearch: - host: localhost - ## to fill if authentication is needed - # user: - # password: + elasticsearch: + uris: + - http://localhost:9200 + ## to fill if authentication is needed + # username: + # password: powsybl-ws: database: diff --git a/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/EmbeddedElasticsearch.java b/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/EmbeddedElasticsearch.java index 1145fe567..73e5221b7 100644 --- a/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/EmbeddedElasticsearch.java +++ b/src/test/java/org/gridsuite/modification/server/utils/elasticsearch/EmbeddedElasticsearch.java @@ -42,8 +42,7 @@ public void postConstruct() { envMap.put("action.auto_create_index", "false"); elasticsearchContainer.start(); - System.setProperty("spring.data.elasticsearch.embedded", Boolean.toString(true)); - System.setProperty("spring.data.elasticsearch.embedded.port", Integer.toString(elasticsearchContainer.getMappedPort(9200))); + System.setProperty("spring.elasticsearch.uris", "localhost:".concat(Integer.toString(elasticsearchContainer.getMappedPort(9200)))); } @PreDestroy