mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-08 13:12:10 +00:00
Migrate to Spring JCL logging.
Original Pull Request #2001 Closes #2000
This commit is contained in:
parent
45b4c99e95
commit
0c7c686cb1
22
pom.xml
22
pom.xml
@ -147,21 +147,6 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
|
||||||
<version>${slf4j}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-core</artifactId>
|
|
||||||
<version>${log4j}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Jackson JSON Mapper -->
|
<!-- Jackson JSON Mapper -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
@ -223,13 +208,6 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-to-slf4j</artifactId>
|
|
||||||
<version>${log4j}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.projectreactor.tools</groupId>
|
<groupId>io.projectreactor.tools</groupId>
|
||||||
<artifactId>blockhound-junit-platform</artifactId>
|
<artifactId>blockhound-junit-platform</artifactId>
|
||||||
|
@ -24,6 +24,8 @@ import java.util.Map;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.DocWriteResponse;
|
import org.elasticsearch.action.DocWriteResponse;
|
||||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||||
@ -54,8 +56,6 @@ import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
|||||||
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
||||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.data.elasticsearch.BulkFailureException;
|
import org.springframework.data.elasticsearch.BulkFailureException;
|
||||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.cluster.ElasticsearchClusterOperations;
|
import org.springframework.data.elasticsearch.backend.elasticsearch7.cluster.ElasticsearchClusterOperations;
|
||||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.document.DocumentAdapters;
|
import org.springframework.data.elasticsearch.backend.elasticsearch7.document.DocumentAdapters;
|
||||||
@ -116,7 +116,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchRestTemplate.class);
|
private static final Log LOGGER = LogFactory.getLog(ElasticsearchRestTemplate.class);
|
||||||
|
|
||||||
private final RestHighLevelClient client;
|
private final RestHighLevelClient client;
|
||||||
private final ElasticsearchExceptionTranslator exceptionTranslator = new ElasticsearchExceptionTranslator();
|
private final ElasticsearchExceptionTranslator exceptionTranslator = new ElasticsearchExceptionTranslator();
|
||||||
@ -419,7 +419,7 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
|||||||
request.scrollIds(scrollIds);
|
request.scrollIds(scrollIds);
|
||||||
execute(client -> client.clearScroll(request, RequestOptions.DEFAULT));
|
execute(client -> client.clearScroll(request, RequestOptions.DEFAULT));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn("Could not clear scroll: {}", e.getMessage());
|
LOGGER.warn(String.format("Could not clear scroll: %s", e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ import java.util.Map;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.DocWriteResponse;
|
import org.elasticsearch.action.DocWriteResponse;
|
||||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||||
@ -47,8 +49,6 @@ import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
|||||||
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
@ -109,8 +109,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations, ApplicationContextAware {
|
public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations, ApplicationContextAware {
|
||||||
|
|
||||||
private static final Logger QUERY_LOGGER = LoggerFactory
|
private static final Log QUERY_LOGGER = LogFactory.getLog("org.springframework.data.elasticsearch.core.QUERY");
|
||||||
.getLogger("org.springframework.data.elasticsearch.core.QUERY");
|
|
||||||
|
|
||||||
private final ReactiveElasticsearchClient client;
|
private final ReactiveElasticsearchClient client;
|
||||||
private final ElasticsearchConverter converter;
|
private final ElasticsearchConverter converter;
|
||||||
@ -811,7 +810,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
protected Flux<AggregationContainer<?>> doAggregate(SearchRequest request) {
|
protected Flux<AggregationContainer<?>> doAggregate(SearchRequest request) {
|
||||||
|
|
||||||
if (QUERY_LOGGER.isDebugEnabled()) {
|
if (QUERY_LOGGER.isDebugEnabled()) {
|
||||||
QUERY_LOGGER.debug("Executing doCount: {}", request);
|
QUERY_LOGGER.debug(String.format("Executing doCount: %s", request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Flux.from(execute(client -> client.aggregate(request))) //
|
return Flux.from(execute(client -> client.aggregate(request))) //
|
||||||
@ -885,7 +884,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
protected Flux<SearchDocument> doFind(SearchRequest request) {
|
protected Flux<SearchDocument> doFind(SearchRequest request) {
|
||||||
|
|
||||||
if (QUERY_LOGGER.isDebugEnabled()) {
|
if (QUERY_LOGGER.isDebugEnabled()) {
|
||||||
QUERY_LOGGER.debug("Executing doFind: {}", request);
|
QUERY_LOGGER.debug(String.format("Executing doFind: %s", request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Flux.from(execute(client -> client.search(request))).map(DocumentAdapters::from) //
|
return Flux.from(execute(client -> client.search(request))).map(DocumentAdapters::from) //
|
||||||
@ -903,7 +902,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
Function<SearchDocument, ? extends Object> suggestEntityCreator) {
|
Function<SearchDocument, ? extends Object> suggestEntityCreator) {
|
||||||
|
|
||||||
if (QUERY_LOGGER.isDebugEnabled()) {
|
if (QUERY_LOGGER.isDebugEnabled()) {
|
||||||
QUERY_LOGGER.debug("Executing doFindForResponse: {}", request);
|
QUERY_LOGGER.debug(String.format("Executing doFindForResponse: %s", request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Mono.from(execute(client1 -> client1.searchForResponse(request))).map(searchResponse -> {
|
return Mono.from(execute(client1 -> client1.searchForResponse(request))).map(searchResponse -> {
|
||||||
@ -920,7 +919,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
protected Mono<Long> doCount(SearchRequest request) {
|
protected Mono<Long> doCount(SearchRequest request) {
|
||||||
|
|
||||||
if (QUERY_LOGGER.isDebugEnabled()) {
|
if (QUERY_LOGGER.isDebugEnabled()) {
|
||||||
QUERY_LOGGER.debug("Executing doCount: {}", request);
|
QUERY_LOGGER.debug(String.format("Executing doCount: %s", request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Mono.from(execute(client -> client.count(request))) //
|
return Mono.from(execute(client -> client.count(request))) //
|
||||||
@ -936,7 +935,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
protected Flux<SearchDocument> doScroll(SearchRequest request) {
|
protected Flux<SearchDocument> doScroll(SearchRequest request) {
|
||||||
|
|
||||||
if (QUERY_LOGGER.isDebugEnabled()) {
|
if (QUERY_LOGGER.isDebugEnabled()) {
|
||||||
QUERY_LOGGER.debug("Executing doScroll: {}", request);
|
QUERY_LOGGER.debug(String.format("Executing doScroll: %s", request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Flux.from(execute(client -> client.scroll(request))) //
|
return Flux.from(execute(client -> client.scroll(request))) //
|
||||||
|
@ -24,6 +24,8 @@ import reactor.core.publisher.Mono;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||||
@ -36,8 +38,6 @@ import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
|
|||||||
import org.elasticsearch.client.indices.GetMappingsRequest;
|
import org.elasticsearch.client.indices.GetMappingsRequest;
|
||||||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
||||||
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.data.elasticsearch.NoSuchIndexException;
|
import org.springframework.data.elasticsearch.NoSuchIndexException;
|
||||||
@ -69,7 +69,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
class ReactiveIndexTemplate implements ReactiveIndexOperations {
|
class ReactiveIndexTemplate implements ReactiveIndexOperations {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveIndexTemplate.class);
|
private static final Log LOGGER = LogFactory.getLog(ReactiveIndexTemplate.class);
|
||||||
|
|
||||||
@Nullable private final Class<?> boundClass;
|
@Nullable private final Class<?> boundClass;
|
||||||
private final IndexCoordinates boundIndex;
|
private final IndexCoordinates boundIndex;
|
||||||
@ -366,7 +366,7 @@ class ReactiveIndexTemplate implements ReactiveIndexOperations {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("path in {} has to be defined. Using default instead.", annotation);
|
LOGGER.info(String.format("path in %s has to be defined. Using default empty Document instead.", annotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Mono.just(Document.create());
|
return Mono.just(Document.create());
|
||||||
|
@ -20,6 +20,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||||
@ -38,8 +40,6 @@ import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
|
|||||||
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
||||||
import org.elasticsearch.client.indices.PutMappingRequest;
|
import org.elasticsearch.client.indices.PutMappingRequest;
|
||||||
import org.elasticsearch.cluster.metadata.MappingMetadata;
|
import org.elasticsearch.cluster.metadata.MappingMetadata;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.data.elasticsearch.core.AbstractIndexTemplate;
|
import org.springframework.data.elasticsearch.core.AbstractIndexTemplate;
|
||||||
import org.springframework.data.elasticsearch.core.IndexInformation;
|
import org.springframework.data.elasticsearch.core.IndexInformation;
|
||||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||||
@ -66,7 +66,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
class RestIndexTemplate extends AbstractIndexTemplate implements IndexOperations {
|
class RestIndexTemplate extends AbstractIndexTemplate implements IndexOperations {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestIndexTemplate.class);
|
private static final Log LOGGER = LogFactory.getLog(RestIndexTemplate.class);
|
||||||
|
|
||||||
private final ElasticsearchRestTemplate restTemplate;
|
private final ElasticsearchRestTemplate restTemplate;
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ package org.springframework.data.elasticsearch.backend.elasticsearch7.client;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.elasticsearch.client.RestClient;
|
import org.elasticsearch.client.RestClient;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
|
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
|
||||||
@ -38,7 +38,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class RestClientFactoryBean implements FactoryBean<RestHighLevelClient>, InitializingBean, DisposableBean {
|
public class RestClientFactoryBean implements FactoryBean<RestHighLevelClient>, InitializingBean, DisposableBean {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestClientFactoryBean.class);
|
private static final Log LOGGER = LogFactory.getLog(RestClientFactoryBean.class);
|
||||||
|
|
||||||
private @Nullable RestHighLevelClient client;
|
private @Nullable RestHighLevelClient client;
|
||||||
private String hosts = "http://localhost:9200";
|
private String hosts = "http://localhost:9200";
|
||||||
|
@ -17,16 +17,15 @@ package org.springframework.data.elasticsearch.client;
|
|||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logging Utility to log client requests and responses. Logs client requests and responses to Elasticsearch to a
|
* Logging Utility to log client requests and responses. Logs client requests and responses to Elasticsearch to a
|
||||||
* dedicated logger: {@code org.springframework.data.elasticsearch.client.WIRE} on {@link org.slf4j.event.Level#TRACE}
|
* dedicated logger: {@code org.springframework.data.elasticsearch.client.WIRE} on trace level.
|
||||||
* level.
|
|
||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
@ -35,8 +34,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
public abstract class ClientLogger {
|
public abstract class ClientLogger {
|
||||||
|
|
||||||
private static final String lineSeparator = System.getProperty("line.separator");
|
private static final String lineSeparator = System.getProperty("line.separator");
|
||||||
private static final Logger WIRE_LOGGER = LoggerFactory
|
private static final Log WIRE_LOGGER = LogFactory.getLog("org.springframework.data.elasticsearch.client.WIRE");
|
||||||
.getLogger("org.springframework.data.elasticsearch.client.WIRE");
|
|
||||||
|
|
||||||
private ClientLogger() {}
|
private ClientLogger() {}
|
||||||
|
|
||||||
@ -52,7 +50,7 @@ public abstract class ClientLogger {
|
|||||||
/**
|
/**
|
||||||
* Log an outgoing HTTP request.
|
* Log an outgoing HTTP request.
|
||||||
*
|
*
|
||||||
* @param logId the correlation Id, see {@link #newLogId()}.
|
* @param logId the correlation id, see {@link #newLogId()}.
|
||||||
* @param method HTTP method
|
* @param method HTTP method
|
||||||
* @param endpoint URI
|
* @param endpoint URI
|
||||||
* @param parameters optional parameters.
|
* @param parameters optional parameters.
|
||||||
@ -60,16 +58,15 @@ public abstract class ClientLogger {
|
|||||||
public static void logRequest(String logId, String method, String endpoint, Object parameters) {
|
public static void logRequest(String logId, String method, String endpoint, Object parameters) {
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
|
WIRE_LOGGER.trace(String.format("[%s] Sending request %s %s with parameters: %s", logId, method.toUpperCase(),
|
||||||
WIRE_LOGGER.trace("[{}] Sending request {} {} with parameters: {}", logId, method.toUpperCase(), endpoint,
|
endpoint, parameters));
|
||||||
parameters);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log an outgoing HTTP request with a request body.
|
* Log an outgoing HTTP request with a request body.
|
||||||
*
|
*
|
||||||
* @param logId the correlation Id, see {@link #newLogId()}.
|
* @param logId the correlation id, see {@link #newLogId()}.
|
||||||
* @param method HTTP method
|
* @param method HTTP method
|
||||||
* @param endpoint URI
|
* @param endpoint URI
|
||||||
* @param parameters optional parameters.
|
* @param parameters optional parameters.
|
||||||
@ -79,43 +76,43 @@ public abstract class ClientLogger {
|
|||||||
Supplier<Object> body) {
|
Supplier<Object> body) {
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
|
WIRE_LOGGER.trace(String.format("[%s] Sending request %s %s with parameters: %s%sRequest body: %s", logId,
|
||||||
WIRE_LOGGER.trace("[{}] Sending request {} {} with parameters: {}{}Request body: {}", logId, method.toUpperCase(),
|
method.toUpperCase(), endpoint, parameters, lineSeparator, body.get()));
|
||||||
endpoint, parameters, lineSeparator, body.get());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a raw HTTP response without logging the body.
|
* Log a raw HTTP response without logging the body.
|
||||||
*
|
*
|
||||||
* @param logId the correlation Id, see {@link #newLogId()}.
|
* @param logId the correlation id, see {@link #newLogId()}.
|
||||||
* @param statusCode the HTTP status code.
|
* @param statusCode the HTTP status code.
|
||||||
*/
|
*/
|
||||||
public static void logRawResponse(String logId, @Nullable HttpStatus statusCode) {
|
public static void logRawResponse(String logId, @Nullable HttpStatus statusCode) {
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
WIRE_LOGGER.trace("[{}] Received raw response: {}", logId, statusCode);
|
WIRE_LOGGER.trace(String.format("[%s] Received raw response: %s", logId, statusCode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a raw HTTP response along with the body.
|
* Log a raw HTTP response along with the body.
|
||||||
*
|
*
|
||||||
* @param logId the correlation Id, see {@link #newLogId()}.
|
* @param logId the correlation id, see {@link #newLogId()}.
|
||||||
* @param statusCode the HTTP status code.
|
* @param statusCode the HTTP status code.
|
||||||
* @param body body content.
|
* @param body body content.
|
||||||
*/
|
*/
|
||||||
public static void logResponse(String logId, HttpStatus statusCode, String body) {
|
public static void logResponse(String logId, HttpStatus statusCode, String body) {
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
WIRE_LOGGER.trace("[{}] Received response: {}{}Response body: {}", logId, statusCode, lineSeparator, body);
|
WIRE_LOGGER.trace(
|
||||||
|
String.format("[%s] Received response: %s%sResponse body: %s", logId, statusCode, lineSeparator, body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new, unique correlation Id to improve tracing across log events.
|
* Creates a new, unique correlation id to improve tracing across log events.
|
||||||
*
|
*
|
||||||
* @return a new, unique correlation Id.
|
* @return a new, unique correlation id.
|
||||||
*/
|
*/
|
||||||
public static String newLogId() {
|
public static String newLogId() {
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
||||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
|
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
|
||||||
import org.springframework.data.elasticsearch.client.NoReachableHostException;
|
import org.springframework.data.elasticsearch.client.NoReachableHostException;
|
||||||
@ -48,7 +48,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||||||
*/
|
*/
|
||||||
class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
||||||
|
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(MultiNodeHostProvider.class);
|
private final static Log LOGGER = LogFactory.getLog(MultiNodeHostProvider.class);
|
||||||
|
|
||||||
private final WebClientProvider clientProvider;
|
private final WebClientProvider clientProvider;
|
||||||
private final Map<InetSocketAddress, ElasticsearchHost> hosts;
|
private final Map<InetSocketAddress, ElasticsearchHost> hosts;
|
||||||
@ -61,7 +61,9 @@ class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
|||||||
this.hosts.put(endpoint, new ElasticsearchHost(endpoint, State.UNKNOWN));
|
this.hosts.put(endpoint, new ElasticsearchHost(endpoint, State.UNKNOWN));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("initialized with " + hosts);
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("initialized with " + hosts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -90,19 +92,27 @@ class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<InetSocketAddress> lookupActiveHost(Verification verification) {
|
public Mono<InetSocketAddress> lookupActiveHost(Verification verification) {
|
||||||
|
|
||||||
LOG.trace("lookupActiveHost " + verification + " from " + hosts());
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("lookupActiveHost " + verification + " from " + hosts());
|
||||||
|
}
|
||||||
|
|
||||||
if (Verification.LAZY.equals(verification)) {
|
if (Verification.LAZY.equals(verification)) {
|
||||||
for (ElasticsearchHost entry : hosts()) {
|
for (ElasticsearchHost entry : hosts()) {
|
||||||
if (entry.isOnline()) {
|
if (entry.isOnline()) {
|
||||||
LOG.trace("lookupActiveHost returning " + entry);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("lookupActiveHost returning " + entry);
|
||||||
|
}
|
||||||
return Mono.just(entry.getEndpoint());
|
return Mono.just(entry.getEndpoint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.trace("no online host found with LAZY");
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("no online host found with LAZY");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.trace("searching for active host");
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("searching for active host");
|
||||||
|
}
|
||||||
return findActiveHostInKnownActives() //
|
return findActiveHostInKnownActives() //
|
||||||
.switchIfEmpty(findActiveHostInUnresolved()) //
|
.switchIfEmpty(findActiveHostInUnresolved()) //
|
||||||
.switchIfEmpty(findActiveHostInDead()) //
|
.switchIfEmpty(findActiveHostInDead()) //
|
||||||
@ -127,13 +137,17 @@ class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
|||||||
|
|
||||||
private Mono<InetSocketAddress> findActiveForState(State state) {
|
private Mono<InetSocketAddress> findActiveForState(State state) {
|
||||||
|
|
||||||
LOG.trace("findActiveForState state " + state + ", current hosts: " + hosts);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("findActiveForState state " + state + ", current hosts: " + hosts);
|
||||||
|
}
|
||||||
|
|
||||||
return checkNodes(state) //
|
return checkNodes(state) //
|
||||||
.map(this::updateNodeState) //
|
.map(this::updateNodeState) //
|
||||||
.filter(ElasticsearchHost::isOnline) //
|
.filter(ElasticsearchHost::isOnline) //
|
||||||
.map(elasticsearchHost -> {
|
.map(elasticsearchHost -> {
|
||||||
LOG.trace("findActiveForState returning host " + elasticsearchHost);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("findActiveForState returning host " + elasticsearchHost);
|
||||||
|
}
|
||||||
return elasticsearchHost;
|
return elasticsearchHost;
|
||||||
}).map(ElasticsearchHost::getEndpoint) //
|
}).map(ElasticsearchHost::getEndpoint) //
|
||||||
.takeLast(1) //
|
.takeLast(1) //
|
||||||
@ -150,21 +164,27 @@ class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
|||||||
|
|
||||||
private Flux<Tuple2<InetSocketAddress, State>> checkNodes(@Nullable State state) {
|
private Flux<Tuple2<InetSocketAddress, State>> checkNodes(@Nullable State state) {
|
||||||
|
|
||||||
LOG.trace("checkNodes() with state " + state);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("checkNodes() with state " + state);
|
||||||
|
}
|
||||||
|
|
||||||
return Flux.fromIterable(hosts()) //
|
return Flux.fromIterable(hosts()) //
|
||||||
.filter(entry -> state == null || entry.getState().equals(state)) //
|
.filter(entry -> state == null || entry.getState().equals(state)) //
|
||||||
.map(ElasticsearchHost::getEndpoint) //
|
.map(ElasticsearchHost::getEndpoint) //
|
||||||
.concatMap(host -> {
|
.concatMap(host -> {
|
||||||
|
|
||||||
LOG.trace("checking host " + host);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("checking host " + host);
|
||||||
|
}
|
||||||
|
|
||||||
Mono<ClientResponse> clientResponseMono = createWebClient(host) //
|
Mono<ClientResponse> clientResponseMono = createWebClient(host) //
|
||||||
.head().uri("/") //
|
.head().uri("/") //
|
||||||
.exchangeToMono(Mono::just) //
|
.exchangeToMono(Mono::just) //
|
||||||
.timeout(Duration.ofSeconds(1)) //
|
.timeout(Duration.ofSeconds(1)) //
|
||||||
.doOnError(throwable -> {
|
.doOnError(throwable -> {
|
||||||
LOG.trace("error checking host " + host + ", " + throwable.getMessage());
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("error checking host " + host + ", " + throwable.getMessage());
|
||||||
|
}
|
||||||
hosts.put(host, new ElasticsearchHost(host, State.OFFLINE));
|
hosts.put(host, new ElasticsearchHost(host, State.OFFLINE));
|
||||||
clientProvider.getErrorListener().accept(throwable);
|
clientProvider.getErrorListener().accept(throwable);
|
||||||
});
|
});
|
||||||
@ -174,7 +194,9 @@ class MultiNodeHostProvider implements HostProvider<MultiNodeHostProvider> {
|
|||||||
.thenReturn(it.statusCode().isError() ? State.OFFLINE : State.ONLINE)));
|
.thenReturn(it.statusCode().isError() ? State.OFFLINE : State.ONLINE)));
|
||||||
}) //
|
}) //
|
||||||
.map(tuple -> {
|
.map(tuple -> {
|
||||||
LOG.trace("check result " + tuple);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace("check result " + tuple);
|
||||||
|
}
|
||||||
return tuple;
|
return tuple;
|
||||||
}).onErrorContinue((throwable, o) -> clientProvider.getErrorListener().accept(throwable));
|
}).onErrorContinue((throwable, o) -> clientProvider.getErrorListener().accept(throwable));
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||||
@ -38,7 +36,6 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public abstract class ReactiveResourceUtil {
|
public abstract class ReactiveResourceUtil {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveResourceUtil.class);
|
|
||||||
private static final int BUFFER_SIZE = 8_192;
|
private static final int BUFFER_SIZE = 8_192;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,8 +22,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.document.SearchDocumentResponse;
|
import org.springframework.data.elasticsearch.backend.elasticsearch7.document.SearchDocumentResponse;
|
||||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.document.Document;
|
import org.springframework.data.elasticsearch.core.document.Document;
|
||||||
@ -49,7 +49,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class SearchHitMapping<T> {
|
public class SearchHitMapping<T> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SearchHitMapping.class);
|
private static final Log LOGGER = LogFactory.getLog(SearchHitMapping.class);
|
||||||
|
|
||||||
private final Class<T> type;
|
private final Class<T> type;
|
||||||
private final ElasticsearchConverter converter;
|
private final ElasticsearchConverter converter;
|
||||||
|
@ -18,8 +18,8 @@ package org.springframework.data.elasticsearch.core.convert;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.mapping.PersistentProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ import org.springframework.data.mapping.PersistentProperty;
|
|||||||
*/
|
*/
|
||||||
public class DatePropertyValueConverter extends AbstractPropertyValueConverter {
|
public class DatePropertyValueConverter extends AbstractPropertyValueConverter {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DatePropertyValueConverter.class);
|
private static final Log LOGGER = LogFactory.getLog(DatePropertyValueConverter.class);
|
||||||
|
|
||||||
private final List<ElasticsearchDateConverter> dateConverters;
|
private final List<ElasticsearchDateConverter> dateConverters;
|
||||||
|
|
||||||
@ -47,7 +47,9 @@ public class DatePropertyValueConverter extends AbstractPropertyValueConverter {
|
|||||||
try {
|
try {
|
||||||
return dateConverter.parse(s);
|
return dateConverter.parse(s);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ package org.springframework.data.elasticsearch.core.convert;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.mapping.PersistentProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ import org.springframework.data.mapping.PersistentProperty;
|
|||||||
*/
|
*/
|
||||||
public class DateRangePropertyValueConverter extends AbstractRangePropertyValueConverter<Date> {
|
public class DateRangePropertyValueConverter extends AbstractRangePropertyValueConverter<Date> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DateRangePropertyValueConverter.class);
|
private static final Log LOGGER = LogFactory.getLog(DateRangePropertyValueConverter.class);
|
||||||
|
|
||||||
private final List<ElasticsearchDateConverter> dateConverters;
|
private final List<ElasticsearchDateConverter> dateConverters;
|
||||||
|
|
||||||
@ -51,7 +51,9 @@ public class DateRangePropertyValueConverter extends AbstractRangePropertyValueC
|
|||||||
try {
|
try {
|
||||||
return converters.parse(value);
|
return converters.parse(value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ import java.util.Map.Entry;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
@ -91,7 +91,7 @@ public class MappingElasticsearchConverter
|
|||||||
private static final String INCOMPATIBLE_TYPES = "Cannot convert %1$s of type %2$s into an instance of %3$s! Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions.";
|
private static final String INCOMPATIBLE_TYPES = "Cannot convert %1$s of type %2$s into an instance of %3$s! Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions.";
|
||||||
private static final String INVALID_TYPE_TO_READ = "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter!";
|
private static final String INVALID_TYPE_TO_READ = "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter!";
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MappingElasticsearchConverter.class);
|
private static final Log LOGGER = LogFactory.getLog(MappingElasticsearchConverter.class);
|
||||||
|
|
||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
private final GenericConversionService conversionService;
|
private final GenericConversionService conversionService;
|
||||||
@ -436,10 +436,10 @@ public class MappingElasticsearchConverter
|
|||||||
String key = propertyName + "-read";
|
String key = propertyName + "-read";
|
||||||
int count = propertyWarnings.computeIfAbsent(key, k -> 0);
|
int count = propertyWarnings.computeIfAbsent(key, k -> 0);
|
||||||
if (count < 5) {
|
if (count < 5) {
|
||||||
LOGGER.warn(
|
LOGGER.warn(String.format(
|
||||||
"Type {} of property {} is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for reading!"
|
"Type %s of property %s is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for reading!"
|
||||||
+ " It cannot be mapped from a complex object in Elasticsearch!",
|
+ " It cannot be mapped from a complex object in Elasticsearch!",
|
||||||
property.getType().getSimpleName(), propertyName);
|
property.getType().getSimpleName(), propertyName));
|
||||||
propertyWarnings.put(key, count + 1);
|
propertyWarnings.put(key, count + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -909,10 +909,10 @@ public class MappingElasticsearchConverter
|
|||||||
String key = propertyName + "-write";
|
String key = propertyName + "-write";
|
||||||
int count = propertyWarnings.computeIfAbsent(key, k -> 0);
|
int count = propertyWarnings.computeIfAbsent(key, k -> 0);
|
||||||
if (count < 5) {
|
if (count < 5) {
|
||||||
LOGGER.warn(
|
LOGGER.warn(String.format(
|
||||||
"Type {} of property {} is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for writing!"
|
"Type %s of property %s is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for writing!"
|
||||||
+ " It will be mapped to a complex object in Elasticsearch!",
|
+ " It will be mapped to a complex object in Elasticsearch!",
|
||||||
property.getType().getSimpleName(), propertyName);
|
property.getType().getSimpleName(), propertyName));
|
||||||
propertyWarnings.put(key, count + 1);
|
propertyWarnings.put(key, count + 1);
|
||||||
}
|
}
|
||||||
} else if (!isSimpleType(value)) {
|
} else if (!isSimpleType(value)) {
|
||||||
|
@ -18,8 +18,8 @@ package org.springframework.data.elasticsearch.core.convert;
|
|||||||
import java.time.temporal.TemporalAccessor;
|
import java.time.temporal.TemporalAccessor;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.mapping.PersistentProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ import org.springframework.data.mapping.PersistentProperty;
|
|||||||
*/
|
*/
|
||||||
public class TemporalPropertyValueConverter extends AbstractPropertyValueConverter {
|
public class TemporalPropertyValueConverter extends AbstractPropertyValueConverter {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TemporalPropertyValueConverter.class);
|
private static final Log LOGGER = LogFactory.getLog(TemporalPropertyValueConverter.class);
|
||||||
|
|
||||||
private final List<ElasticsearchDateConverter> dateConverters;
|
private final List<ElasticsearchDateConverter> dateConverters;
|
||||||
|
|
||||||
@ -50,7 +50,10 @@ public class TemporalPropertyValueConverter extends AbstractPropertyValueConvert
|
|||||||
try {
|
try {
|
||||||
return dateConverter.parse(s, (Class<? extends TemporalAccessor>) actualType);
|
return dateConverter.parse(s, (Class<? extends TemporalAccessor>) actualType);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ package org.springframework.data.elasticsearch.core.convert;
|
|||||||
import java.time.temporal.TemporalAccessor;
|
import java.time.temporal.TemporalAccessor;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.mapping.PersistentProperty;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class TemporalRangePropertyValueConverter extends AbstractRangePropertyValueConverter<TemporalAccessor> {
|
public class TemporalRangePropertyValueConverter extends AbstractRangePropertyValueConverter<TemporalAccessor> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TemporalRangePropertyValueConverter.class);
|
private static final Log LOGGER = LogFactory.getLog(TemporalRangePropertyValueConverter.class);
|
||||||
|
|
||||||
private final List<ElasticsearchDateConverter> dateConverters;
|
private final List<ElasticsearchDateConverter> dateConverters;
|
||||||
|
|
||||||
@ -55,7 +55,9 @@ public class TemporalRangePropertyValueConverter extends AbstractRangePropertyVa
|
|||||||
try {
|
try {
|
||||||
return converters.parse(value, (Class<? extends TemporalAccessor>) type);
|
return converters.parse(value, (Class<? extends TemporalAccessor>) type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
|
LOGGER.trace(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
import org.springframework.data.elasticsearch.annotations.*;
|
import org.springframework.data.elasticsearch.annotations.*;
|
||||||
@ -71,7 +71,7 @@ import com.fasterxml.jackson.databind.util.RawValue;
|
|||||||
*/
|
*/
|
||||||
public class MappingBuilder {
|
public class MappingBuilder {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchRestTemplate.class);
|
private static final Log LOGGER = LogFactory.getLog(ElasticsearchRestTemplate.class);
|
||||||
|
|
||||||
private static final String FIELD_INDEX = "index";
|
private static final String FIELD_INDEX = "index";
|
||||||
private static final String FIELD_PROPERTIES = "properties";
|
private static final String FIELD_PROPERTIES = "properties";
|
||||||
@ -265,16 +265,16 @@ public class MappingBuilder {
|
|||||||
|
|
||||||
if (property.isSeqNoPrimaryTermProperty()) {
|
if (property.isSeqNoPrimaryTermProperty()) {
|
||||||
if (property.isAnnotationPresent(Field.class)) {
|
if (property.isAnnotationPresent(Field.class)) {
|
||||||
logger.warn("Property {} of {} is annotated for inclusion in mapping, but its type is " + //
|
LOGGER.warn(String.format("Property %s of %s is annotated for inclusion in mapping, but its type is " + //
|
||||||
"SeqNoPrimaryTerm that is never mapped, so it is skipped", //
|
"SeqNoPrimaryTerm that is never mapped, so it is skipped", //
|
||||||
property.getFieldName(), entity.getType());
|
property.getFieldName(), entity.getType()));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildPropertyMapping(propertiesNode, isRootObject, property);
|
buildPropertyMapping(propertiesNode, isRootObject, property);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("error mapping property with name {}", property.getName(), e);
|
LOGGER.warn(String.format("error mapping property with name %s", property.getName()), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -491,9 +491,9 @@ public class MappingBuilder {
|
|||||||
JoinTypeRelation[] joinTypeRelations = property.getRequiredAnnotation(JoinTypeRelations.class).relations();
|
JoinTypeRelation[] joinTypeRelations = property.getRequiredAnnotation(JoinTypeRelations.class).relations();
|
||||||
|
|
||||||
if (joinTypeRelations.length == 0) {
|
if (joinTypeRelations.length == 0) {
|
||||||
logger.warn("Property {}s type is JoinField but its annotation JoinTypeRelation is " + //
|
LOGGER.warn(String.format("Property %s's type is JoinField but its annotation JoinTypeRelation is " + //
|
||||||
"not properly maintained", //
|
"not properly maintained", //
|
||||||
property.getFieldName());
|
property.getFieldName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
@ -63,7 +63,7 @@ import org.springframework.util.Assert;
|
|||||||
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
||||||
implements ElasticsearchPersistentEntity<T> {
|
implements ElasticsearchPersistentEntity<T> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleElasticsearchPersistentEntity.class);
|
private static final Log LOGGER = LogFactory.getLog(SimpleElasticsearchPersistentEntity.class);
|
||||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||||
|
|
||||||
private @Nullable final Document document;
|
private @Nullable final Document document;
|
||||||
@ -235,9 +235,9 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void warnAboutBothSeqNoPrimaryTermAndVersionProperties() {
|
private void warnAboutBothSeqNoPrimaryTermAndVersionProperties() {
|
||||||
LOGGER.warn(
|
LOGGER.warn(String.format(
|
||||||
"Both SeqNoPrimaryTerm and @Version properties are defined on {}. Version will not be sent in index requests when seq_no is sent!",
|
"Both SeqNoPrimaryTerm and @Version properties are defined on %s. Version will not be sent in index requests when seq_no is sent!",
|
||||||
getType());
|
getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -21,8 +21,8 @@ import java.util.Arrays;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
@ -69,7 +69,7 @@ import org.springframework.util.StringUtils;
|
|||||||
public class SimpleElasticsearchPersistentProperty extends
|
public class SimpleElasticsearchPersistentProperty extends
|
||||||
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements ElasticsearchPersistentProperty {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleElasticsearchPersistentProperty.class);
|
private static final Log LOGGER = LogFactory.getLog(SimpleElasticsearchPersistentProperty.class);
|
||||||
|
|
||||||
private static final List<String> SUPPORTED_ID_PROPERTY_NAMES = Arrays.asList("id", "document");
|
private static final List<String> SUPPORTED_ID_PROPERTY_NAMES = Arrays.asList("id", "document");
|
||||||
private static final PropertyNameFieldNamingStrategy DEFAULT_FIELD_NAMING_STRATEGY = PropertyNameFieldNamingStrategy.INSTANCE;
|
private static final PropertyNameFieldNamingStrategy DEFAULT_FIELD_NAMING_STRATEGY = PropertyNameFieldNamingStrategy.INSTANCE;
|
||||||
@ -161,7 +161,7 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
case Date_Nanos: {
|
case Date_Nanos: {
|
||||||
List<ElasticsearchDateConverter> dateConverters = getDateConverters(field, actualType);
|
List<ElasticsearchDateConverter> dateConverters = getDateConverters(field, actualType);
|
||||||
if (dateConverters.isEmpty()) {
|
if (dateConverters.isEmpty()) {
|
||||||
LOGGER.warn("No date formatters configured for property '{}'.", getName());
|
LOGGER.warn(String.format("No date formatters configured for property '%s'.", getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
} else if (Date.class.isAssignableFrom(actualType)) {
|
} else if (Date.class.isAssignableFrom(actualType)) {
|
||||||
propertyValueConverter = new DatePropertyValueConverter(this, dateConverters);
|
propertyValueConverter = new DatePropertyValueConverter(this, dateConverters);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Unsupported type '{}' for date property '{}'.", actualType, getName());
|
LOGGER.warn(String.format("Unsupported type '%s' for date property '%s'.", actualType, getName()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
|
|
||||||
List<ElasticsearchDateConverter> dateConverters = getDateConverters(field, actualType);
|
List<ElasticsearchDateConverter> dateConverters = getDateConverters(field, actualType);
|
||||||
if (dateConverters.isEmpty()) {
|
if (dateConverters.isEmpty()) {
|
||||||
LOGGER.warn("No date formatters configured for property '{}'.", getName());
|
LOGGER.warn(String.format("No date formatters configured for property '%s'.", getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,8 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
} else if (Date.class.isAssignableFrom(genericType)) {
|
} else if (Date.class.isAssignableFrom(genericType)) {
|
||||||
propertyValueConverter = new DateRangePropertyValueConverter(this, dateConverters);
|
propertyValueConverter = new DateRangePropertyValueConverter(this, dateConverters);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Unsupported generic type '{}' for date range property '{}'.", genericType, getName());
|
LOGGER.warn(
|
||||||
|
String.format("Unsupported generic type '{%s' for date range property '%s'.", genericType, getName()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -208,8 +209,8 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
|| (field.type() == FieldType.Float_Range && !Float.class.isAssignableFrom(genericType))
|
|| (field.type() == FieldType.Float_Range && !Float.class.isAssignableFrom(genericType))
|
||||||
|| (field.type() == FieldType.Long_Range && !Long.class.isAssignableFrom(genericType))
|
|| (field.type() == FieldType.Long_Range && !Long.class.isAssignableFrom(genericType))
|
||||||
|| (field.type() == FieldType.Double_Range && !Double.class.isAssignableFrom(genericType))) {
|
|| (field.type() == FieldType.Double_Range && !Double.class.isAssignableFrom(genericType))) {
|
||||||
LOGGER.warn("Unsupported generic type '{}' for range field type '{}' of property '{}'.", genericType,
|
LOGGER.warn(String.format("Unsupported generic type '%s' for range field type '%s' of property '%s'.",
|
||||||
field.type(), getName());
|
genericType, field.type(), getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,9 +252,9 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
List<ElasticsearchDateConverter> converters = new ArrayList<>();
|
List<ElasticsearchDateConverter> converters = new ArrayList<>();
|
||||||
|
|
||||||
if (dateFormats.length == 0 && dateFormatPatterns.length == 0) {
|
if (dateFormats.length == 0 && dateFormatPatterns.length == 0) {
|
||||||
LOGGER.warn(
|
LOGGER.warn(String.format(
|
||||||
"Property '{}' has @Field type '{}' but has no built-in format or custom date pattern defined. Make sure you have a converter registered for type {}.",
|
"Property '%s' has @Field type '%s' but has no built-in format or custom date pattern defined. Make sure you have a converter registered for type %s.",
|
||||||
getName(), field.type().name(), actualType.getSimpleName());
|
getName(), field.type().name(), actualType.getSimpleName()));
|
||||||
return converters;
|
return converters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,8 +267,9 @@ public class SimpleElasticsearchPersistentProperty extends
|
|||||||
case weekyear:
|
case weekyear:
|
||||||
case weekyear_week:
|
case weekyear_week:
|
||||||
case weekyear_week_day:
|
case weekyear_week_day:
|
||||||
LOGGER.warn("No default converter available for '{}' and date format '{}'. Use a custom converter instead.",
|
LOGGER.warn(String.format(
|
||||||
actualType.getName(), dateFormat.name());
|
"No default converter available for '%s' and date format '%s'. Use a custom converter instead.",
|
||||||
|
actualType.getName(), dateFormat.name()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
converters.add(ElasticsearchDateConverter.of(dateFormat));
|
converters.add(ElasticsearchDateConverter.of(dateFormat));
|
||||||
|
@ -24,13 +24,13 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQuery;
|
||||||
|
import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||||
@ -43,8 +43,6 @@ import org.springframework.data.elasticsearch.core.SearchPage;
|
|||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQuery;
|
|
||||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQueryBuilder;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.util.StreamUtils;
|
import org.springframework.data.util.StreamUtils;
|
||||||
@ -71,8 +69,6 @@ import org.springframework.util.Assert;
|
|||||||
*/
|
*/
|
||||||
public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchRepository<T, ID> {
|
public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchRepository<T, ID> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleElasticsearchRepository.class);
|
|
||||||
|
|
||||||
protected ElasticsearchOperations operations;
|
protected ElasticsearchOperations operations;
|
||||||
protected IndexOperations indexOperations;
|
protected IndexOperations indexOperations;
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.logging.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +33,7 @@ import org.springframework.lang.Nullable;
|
|||||||
*/
|
*/
|
||||||
public final class VersionInfo {
|
public final class VersionInfo {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(VersionInfo.class);
|
private static final Log LOGGER = LogFactory.getLog(VersionInfo.class);
|
||||||
|
|
||||||
private static final String VERSION_PROPERTIES = "versions.properties";
|
private static final String VERSION_PROPERTIES = "versions.properties";
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public final class VersionInfo {
|
|||||||
try {
|
try {
|
||||||
versionProperties = loadVersionProperties();
|
versionProperties = loadVersionProperties();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Could not load {}", VERSION_PROPERTIES, e);
|
LOGGER.error("Could not load " + VERSION_PROPERTIES, e);
|
||||||
versionProperties = new Properties();
|
versionProperties = new Properties();
|
||||||
versionProperties.put(VERSION_SPRING_DATA_ELASTICSEARCH, "0.0.0");
|
versionProperties.put(VERSION_SPRING_DATA_ELASTICSEARCH, "0.0.0");
|
||||||
versionProperties.put(VERSION_ELASTICSEARCH_CLIENT, "0.0.0");
|
versionProperties.put(VERSION_ELASTICSEARCH_CLIENT, "0.0.0");
|
||||||
@ -70,25 +70,25 @@ public final class VersionInfo {
|
|||||||
Version versionRuntimeLibrary = Version.fromString(runtimeLibraryVersion);
|
Version versionRuntimeLibrary = Version.fromString(runtimeLibraryVersion);
|
||||||
Version versionCluster = clusterVersion != null ? Version.fromString(clusterVersion) : null;
|
Version versionCluster = clusterVersion != null ? Version.fromString(clusterVersion) : null;
|
||||||
|
|
||||||
LOG.info("Version Spring Data Elasticsearch: {}", versionSpringDataElasticsearch.toString());
|
LOGGER.info(String.format("Version Spring Data Elasticsearch: %s", versionSpringDataElasticsearch));
|
||||||
LOG.info("Version Elasticsearch client in build: {}", versionBuiltLibraryES.toString());
|
LOGGER.info(String.format("Version Elasticsearch client in build: %s", versionBuiltLibraryES));
|
||||||
LOG.info("Version runtime client used: {} - {}", vendor, versionRuntimeLibrary.toString());
|
LOGGER.info(String.format("Version runtime client used: %s - %s", vendor, versionRuntimeLibrary));
|
||||||
|
|
||||||
if (differInMajorOrMinor(versionBuiltLibraryES, versionRuntimeLibrary)) {
|
if (differInMajorOrMinor(versionBuiltLibraryES, versionRuntimeLibrary)) {
|
||||||
LOG.warn("Version mismatch in between Elasticsearch Clients build/use: {} - {}", versionBuiltLibraryES,
|
LOGGER.warn(String.format("Version mismatch in between Elasticsearch Clients build/use: %s - %s",
|
||||||
versionRuntimeLibrary);
|
versionBuiltLibraryES, versionRuntimeLibrary));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versionCluster != null) {
|
if (versionCluster != null) {
|
||||||
LOG.info("Version cluster: {} - {}", vendor, versionCluster.toString());
|
LOGGER.info(String.format("Version cluster: %s - %s", vendor, versionCluster));
|
||||||
|
|
||||||
if (differInMajorOrMinor(versionRuntimeLibrary, versionCluster)) {
|
if (differInMajorOrMinor(versionRuntimeLibrary, versionCluster)) {
|
||||||
LOG.warn("Version mismatch in between Client and Cluster: {} - {} - {}", vendor, versionRuntimeLibrary,
|
LOGGER.warn(String.format("Version mismatch in between Client and Cluster: %s - %s - %s", vendor,
|
||||||
versionCluster);
|
versionRuntimeLibrary, versionCluster));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Could not log version info: {} - {}", e.getClass().getSimpleName(), e.getMessage());
|
LOGGER.warn(String.format("Could not log version info: %s - %s", e.getClass().getSimpleName(), e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,8 +13,6 @@ import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTes
|
|||||||
@Foobar
|
@Foobar
|
||||||
public abstract class FoobarIntegrationTest {
|
public abstract class FoobarIntegrationTest {
|
||||||
|
|
||||||
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("should run test")
|
@DisplayName("should run test")
|
||||||
void shouldRunTest() {
|
void shouldRunTest() {
|
||||||
|
@ -21,9 +21,9 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||||
import org.testcontainers.utility.DockerImageName;
|
import org.testcontainers.utility.DockerImageName;
|
||||||
@ -38,7 +38,7 @@ import org.testcontainers.utility.DockerImageName;
|
|||||||
*/
|
*/
|
||||||
public class ClusterConnection implements ExtensionContext.Store.CloseableResource {
|
public class ClusterConnection implements ExtensionContext.Store.CloseableResource {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterConnection.class);
|
private static final Log LOGGER = LogFactory.getLog(ClusterConnection.class);
|
||||||
|
|
||||||
private static final String SDE_TESTCONTAINER_IMAGE_NAME = "sde.testcontainers.image-name";
|
private static final String SDE_TESTCONTAINER_IMAGE_NAME = "sde.testcontainers.image-name";
|
||||||
private static final String SDE_TESTCONTAINER_IMAGE_VERSION = "sde.testcontainers.image-version";
|
private static final String SDE_TESTCONTAINER_IMAGE_VERSION = "sde.testcontainers.image-version";
|
||||||
@ -55,10 +55,14 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
|
|||||||
clusterConnectionInfo = startElasticsearchContainer();
|
clusterConnectionInfo = startElasticsearchContainer();
|
||||||
|
|
||||||
if (clusterConnectionInfo != null) {
|
if (clusterConnectionInfo != null) {
|
||||||
LOGGER.debug(clusterConnectionInfo.toString());
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug(clusterConnectionInfo.toString());
|
||||||
|
}
|
||||||
clusterConnectionInfoThreadLocal.set(clusterConnectionInfo);
|
clusterConnectionInfoThreadLocal.set(clusterConnectionInfo);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("could not create ClusterConnectionInfo");
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.error("could not create ClusterConnectionInfo");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +86,7 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
IntegrationtestEnvironment integrationtestEnvironment = IntegrationtestEnvironment.get();
|
IntegrationtestEnvironment integrationtestEnvironment = IntegrationtestEnvironment.get();
|
||||||
LOGGER.info("Integration test environment: {}", integrationtestEnvironment);
|
LOGGER.info("Integration test environment: " + integrationtestEnvironment);
|
||||||
if (integrationtestEnvironment == IntegrationtestEnvironment.UNDEFINED) {
|
if (integrationtestEnvironment == IntegrationtestEnvironment.UNDEFINED) {
|
||||||
throw new IllegalArgumentException(IntegrationtestEnvironment.SYSTEM_PROPERTY + " property not set");
|
throw new IllegalArgumentException(IntegrationtestEnvironment.SYSTEM_PROPERTY + " property not set");
|
||||||
}
|
}
|
||||||
@ -128,13 +132,13 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
|
|||||||
String configuredImageName = imageName + ':' + imageVersion;
|
String configuredImageName = imageName + ':' + imageVersion;
|
||||||
DockerImageName dockerImageName = DockerImageName.parse(configuredImageName)
|
DockerImageName dockerImageName = DockerImageName.parse(configuredImageName)
|
||||||
.asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");
|
.asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch");
|
||||||
LOGGER.info("Docker image: {}", dockerImageName);
|
LOGGER.info("Docker image: " + dockerImageName);
|
||||||
return dockerImageName;
|
return dockerImageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> testcontainersProperties(String propertiesFile) {
|
private Map<String, String> testcontainersProperties(String propertiesFile) {
|
||||||
|
|
||||||
LOGGER.info("load configuration from {}", propertiesFile);
|
LOGGER.info("load configuration from " + propertiesFile);
|
||||||
|
|
||||||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) {
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
@ -155,10 +159,14 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
|
|||||||
public void close() {
|
public void close() {
|
||||||
|
|
||||||
if (clusterConnectionInfo != null && clusterConnectionInfo.getElasticsearchContainer() != null) {
|
if (clusterConnectionInfo != null && clusterConnectionInfo.getElasticsearchContainer() != null) {
|
||||||
LOGGER.debug("Stopping container");
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("Stopping container");
|
||||||
|
}
|
||||||
clusterConnectionInfo.getElasticsearchContainer().stop();
|
clusterConnectionInfo.getElasticsearchContainer().stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.debug("closed");
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@ import java.util.List;
|
|||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
import org.junit.jupiter.api.extension.ParameterContext;
|
import org.junit.jupiter.api.extension.ParameterContext;
|
||||||
import org.junit.jupiter.api.extension.ParameterResolutionException;
|
import org.junit.jupiter.api.extension.ParameterResolutionException;
|
||||||
import org.junit.jupiter.api.extension.ParameterResolver;
|
import org.junit.jupiter.api.extension.ParameterResolver;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.test.context.ContextConfigurationAttributes;
|
import org.springframework.test.context.ContextConfigurationAttributes;
|
||||||
import org.springframework.test.context.ContextCustomizer;
|
import org.springframework.test.context.ContextCustomizer;
|
||||||
@ -46,7 +46,7 @@ import org.springframework.test.context.MergedContextConfiguration;
|
|||||||
public class SpringDataElasticsearchExtension
|
public class SpringDataElasticsearchExtension
|
||||||
implements BeforeAllCallback, ParameterResolver, ContextCustomizerFactory {
|
implements BeforeAllCallback, ParameterResolver, ContextCustomizerFactory {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataElasticsearchExtension.class);
|
private static final Log LOGGER = LogFactory.getLog(SpringDataElasticsearchExtension.class);
|
||||||
|
|
||||||
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace
|
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace
|
||||||
.create(SpringDataElasticsearchExtension.class.getName());
|
.create(SpringDataElasticsearchExtension.class.getName());
|
||||||
@ -61,7 +61,9 @@ public class SpringDataElasticsearchExtension
|
|||||||
try {
|
try {
|
||||||
ExtensionContext.Store store = getStore(extensionContext);
|
ExtensionContext.Store store = getStore(extensionContext);
|
||||||
ClusterConnection clusterConnection = store.getOrComputeIfAbsent(STORE_KEY_CLUSTER_CONNECTION, key -> {
|
ClusterConnection clusterConnection = store.getOrComputeIfAbsent(STORE_KEY_CLUSTER_CONNECTION, key -> {
|
||||||
LOGGER.debug("creating ClusterConnection");
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("creating ClusterConnection");
|
||||||
|
}
|
||||||
return createClusterConnection();
|
return createClusterConnection();
|
||||||
}, ClusterConnection.class);
|
}, ClusterConnection.class);
|
||||||
store.getOrComputeIfAbsent(STORE_KEY_CLUSTER_CONNECTION_INFO,
|
store.getOrComputeIfAbsent(STORE_KEY_CLUSTER_CONNECTION_INFO,
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright 2021 the original author or authors.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user