Remove support for Elasticsearch transport client
The Elasticsearch transport client has been deprecated since Spring Boot 2.2.0 and is about to be removed from Spring Data Elasticsearch and Elasticsearch itself in their next major releases. The available REST client support variants are now the preferred way of using Elasticsearch features. Closes gh-19668pull/19681/head
parent
648e468c86
commit
b780e5247c
@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2019 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.elasticsearch;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.health.HealthContributor;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
|
||||||
* {@link ElasticsearchHealthIndicator} using the Elasticsearch {@link Client}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.1.0
|
|
||||||
* @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
|
|
||||||
* deprecated upstream
|
|
||||||
*/
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
@ConditionalOnClass(Client.class)
|
|
||||||
@ConditionalOnBean(Client.class)
|
|
||||||
@ConditionalOnEnabledHealthIndicator("elasticsearch")
|
|
||||||
@AutoConfigureAfter(ElasticsearchAutoConfiguration.class)
|
|
||||||
@EnableConfigurationProperties(ElasticsearchHealthIndicatorProperties.class)
|
|
||||||
@Deprecated
|
|
||||||
public class ElasticSearchClientHealthContributorAutoConfiguration
|
|
||||||
extends CompositeHealthContributorConfiguration<ElasticsearchHealthIndicator, Client> {
|
|
||||||
|
|
||||||
private final ElasticsearchHealthIndicatorProperties properties;
|
|
||||||
|
|
||||||
public ElasticSearchClientHealthContributorAutoConfiguration(ElasticsearchHealthIndicatorProperties properties) {
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
|
|
||||||
public HealthContributor elasticsearchHealthContributor(Map<String, Client> clients) {
|
|
||||||
return createContributor(clients);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ElasticsearchHealthIndicator createIndicator(Client client) {
|
|
||||||
Duration responseTimeout = this.properties.getResponseTimeout();
|
|
||||||
return new ElasticsearchHealthIndicator(client, (responseTimeout != null) ? responseTimeout.toMillis() : 100,
|
|
||||||
this.properties.getIndices());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2019 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.elasticsearch;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* External configuration properties for {@link ElasticsearchHealthIndicator}.
|
|
||||||
*
|
|
||||||
* @author Binwei Yang
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
|
|
||||||
* deprecated upstream
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "management.health.elasticsearch", ignoreUnknownFields = false)
|
|
||||||
@Deprecated
|
|
||||||
public class ElasticsearchHealthIndicatorProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Comma-separated index names.
|
|
||||||
*/
|
|
||||||
private List<String> indices = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Time to wait for a response from the cluster.
|
|
||||||
*/
|
|
||||||
private Duration responseTimeout = Duration.ofMillis(100);
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(reason = "Upstream elasticsearch transport is deprected")
|
|
||||||
public List<String> getIndices() {
|
|
||||||
return this.indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndices(List<String> indices) {
|
|
||||||
this.indices = indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(reason = "Upstream elasticsearch transport is deprected")
|
|
||||||
public Duration getResponseTimeout() {
|
|
||||||
return this.responseTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseTimeout(Duration responseTimeout) {
|
|
||||||
this.responseTimeout = responseTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2019 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
|
||||||
* Auto-configuration} for Elasticsearch.
|
|
||||||
*
|
|
||||||
* @author Artur Konczak
|
|
||||||
* @author Mohsin Husen
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @since 1.1.0
|
|
||||||
*/
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
@ConditionalOnClass({ Client.class, TransportClientFactoryBean.class })
|
|
||||||
@ConditionalOnProperty(prefix = "spring.data.elasticsearch", name = "cluster-nodes", matchIfMissing = false)
|
|
||||||
@EnableConfigurationProperties(ElasticsearchProperties.class)
|
|
||||||
public class ElasticsearchAutoConfiguration {
|
|
||||||
|
|
||||||
private final ElasticsearchProperties properties;
|
|
||||||
|
|
||||||
public ElasticsearchAutoConfiguration(ElasticsearchProperties properties) {
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public TransportClient elasticsearchClient() throws Exception {
|
|
||||||
TransportClientFactoryBean factory = new TransportClientFactoryBean();
|
|
||||||
factory.setClusterNodes(this.properties.getClusterNodes());
|
|
||||||
factory.setProperties(createProperties());
|
|
||||||
factory.afterPropertiesSet();
|
|
||||||
return factory.getObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Properties createProperties() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.put("cluster.name", this.properties.getClusterName());
|
|
||||||
properties.putAll(this.properties.getProperties());
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2019 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration properties for Elasticsearch.
|
|
||||||
*
|
|
||||||
* @author Artur Konczak
|
|
||||||
* @author Mohsin Husen
|
|
||||||
* @since 1.1.0
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "spring.data.elasticsearch")
|
|
||||||
public class ElasticsearchProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Elasticsearch cluster name.
|
|
||||||
*/
|
|
||||||
private String clusterName = "elasticsearch";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Comma-separated list of cluster node addresses.
|
|
||||||
*/
|
|
||||||
private String clusterNodes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional properties used to configure the client.
|
|
||||||
*/
|
|
||||||
private Map<String, String> properties = new HashMap<>();
|
|
||||||
|
|
||||||
public String getClusterName() {
|
|
||||||
return this.clusterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClusterName(String clusterName) {
|
|
||||||
this.clusterName = clusterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getClusterNodes() {
|
|
||||||
return this.clusterNodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClusterNodes(String clusterNodes) {
|
|
||||||
this.clusterNodes = clusterNodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getProperties() {
|
|
||||||
return this.properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProperties(Map<String, String> properties) {
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2020 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.
|
|
||||||
*/
|
|
||||||
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
|
||||||
import org.testcontainers.junit.jupiter.Container;
|
|
||||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ElasticsearchAutoConfiguration}.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
*/
|
|
||||||
@Testcontainers(disabledWithoutDocker = true)
|
|
||||||
class ElasticsearchAutoConfigurationTests {
|
|
||||||
|
|
||||||
@Container
|
|
||||||
public static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
|
|
||||||
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
System.setProperty("es.set.netty.runtime.available.processors", "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void close() {
|
|
||||||
if (this.context != null) {
|
|
||||||
this.context.close();
|
|
||||||
}
|
|
||||||
System.clearProperty("es.set.netty.runtime.available.processors");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void useExistingClient() {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(CustomConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
|
||||||
ElasticsearchAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertThat(this.context.getBeanNamesForType(Client.class)).hasSize(1);
|
|
||||||
assertThat(this.context.getBean("myClient")).isSameAs(this.context.getBean(Client.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
void createTransportClient() {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
TestPropertyValues
|
|
||||||
.of("spring.data.elasticsearch.cluster-nodes:" + elasticsearch.getTcpHost().getHostString() + ":"
|
|
||||||
+ elasticsearch.getTcpHost().getPort(), "spring.data.elasticsearch.cluster-name:docker-cluster")
|
|
||||||
.applyTo(this.context);
|
|
||||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
List<DiscoveryNode> connectedNodes = this.context.getBean(TransportClient.class).connectedNodes();
|
|
||||||
assertThat(connectedNodes).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class CustomConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Client myClient() {
|
|
||||||
return mock(Client.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue