Merge pull request #5511 from htynkn/upgrade-elastic

* pr/5511:
  Polish contribution
  Upgrade elasticsearch to 2.2.0
  Polish contribution
  Deprecate Undertow container's constructors that have a port parameter
  Remove unused unsatisfiedDependency.getInjectionPoint() call
  Polish contribution
  Allow Tomcat's minimum threads to be configured via the environment
pull/5561/merge
Stephane Nicoll 9 years ago
commit 63a3d003dd

@ -393,8 +393,7 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void elasticSearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs",
"spring.data.elasticsearch.properties.path.home:target",
"management.health.diskspace.enabled:false");
this.context.register(ElasticsearchAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
@ -411,8 +410,7 @@ public class HealthIndicatorAutoConfigurationTests {
public void notElasticSearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.elasticsearch.enabled:false",
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs",
"spring.data.elasticsearch.properties.path.home:target",
"management.health.diskspace.enabled:false");
this.context.register(ElasticsearchAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);

@ -23,13 +23,13 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.junit.Before;
@ -176,9 +176,9 @@ public class ElasticsearchHealthIndicatorTests {
private StubClusterHealthResponse(ClusterHealthStatus status) {
super("test-cluster", new String[0],
new ClusterState(null, 0, null, RoutingTable.builder().build(),
new ClusterState(null, 0, null, null, RoutingTable.builder().build(),
DiscoveryNodes.builder().build(),
ClusterBlocks.builder().build(), null));
ClusterBlocks.builder().build(), null, false));
this.status = status;
}

@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
@ -62,6 +62,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
Map<String, String> defaults = new LinkedHashMap<String, String>();
defaults.put("http.enabled", String.valueOf(false));
defaults.put("node.local", String.valueOf(true));
defaults.put("path.home", System.getProperty("user.dir"));
DEFAULTS = Collections.unmodifiableMap(defaults);
}
@ -95,7 +96,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
}
private Client createNodeClient() throws Exception {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
Settings.Builder settings = Settings.settingsBuilder();
for (Map.Entry<String, String> entry : DEFAULTS.entrySet()) {
if (!this.properties.getProperties().containsKey(entry.getKey())) {
settings.put(entry.getKey(), entry.getValue());

@ -72,6 +72,7 @@ import org.springframework.util.StringUtils;
* @author Ivan Sopov
* @author Marcos Barbero
* @author Eddú Meléndez
* @author Quinten De Swaef
*/
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties
@ -580,6 +581,11 @@ public class ServerProperties
*/
private int maxThreads = 0; // Number of threads in protocol handler
/**
* Minimum amount of worker threads.
*/
private int minSpareThreads = 0; // Minimum spare threads in protocol handler
/**
* Maximum size in bytes of the HTTP message header.
*/
@ -598,6 +604,14 @@ public class ServerProperties
this.maxThreads = maxThreads;
}
public int getMinSpareThreads() {
return this.minSpareThreads;
}
public void setMinSpareThreads(int minSpareThreads) {
this.minSpareThreads = minSpareThreads;
}
public int getMaxHttpHeaderSize() {
return this.maxHttpHeaderSize;
}
@ -684,6 +698,9 @@ public class ServerProperties
if (this.maxThreads > 0) {
customizeMaxThreads(factory);
}
if (this.minSpareThreads > 0) {
customizeMinThreads(factory);
}
if (this.maxHttpHeaderSize > 0) {
customizeMaxHttpHeaderSize(factory);
}
@ -747,6 +764,22 @@ public class ServerProperties
});
}
@SuppressWarnings("rawtypes")
private void customizeMinThreads(TomcatEmbeddedServletContainerFactory factory) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) {
AbstractProtocol protocol = (AbstractProtocol) handler;
protocol.setMinSpareThreads(Tomcat.this.minSpareThreads);
}
}
});
}
@SuppressWarnings("rawtypes")
private void customizeMaxHttpHeaderSize(
TomcatEmbeddedServletContainerFactory factory) {

@ -57,8 +57,7 @@ public class ElasticsearchAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.foo.bar:baz",
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs");
"spring.data.elasticsearch.properties.path.home:target");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.context.refresh();
@ -74,8 +73,7 @@ public class ElasticsearchAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.foo.bar:baz",
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs",
"spring.data.elasticsearch.properties.path.home:target",
"spring.data.elasticsearch.properties.node.local:false",
"spring.data.elasticsearch.properties.node.data:true",
"spring.data.elasticsearch.properties.http.enabled:true");
@ -109,8 +107,7 @@ public class ElasticsearchAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.cluster-nodes:localhost",
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs");
"spring.data.elasticsearch.properties.path.home:target");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.thrown.expect(BeanCreationException.class);

@ -89,8 +89,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
private void addElasticsearchProperties(AnnotationConfigApplicationContext context) {
EnvironmentTestUtils.addEnvironment(context,
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs");
"spring.data.elasticsearch.properties.path.home:target");
}
@Configuration

@ -62,6 +62,7 @@ import static org.mockito.Mockito.verify;
* @author Andy Wilkinson
* @author Phillip Webb
* @author Eddú Meléndez
* @author Quinten De Swaef
*/
public class ServerPropertiesTests {
@ -258,6 +259,14 @@ public class ServerPropertiesTests {
assertThat(this.properties.getTomcat().getMaxHttpHeaderSize()).isEqualTo(9999);
}
@Test
public void testCustomizeTomcatMinSpareThreads() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("server.tomcat.min-spare-threads", "10");
bindProperties(map);
assertThat(this.properties.getTomcat().getMinSpareThreads()).isEqualTo(10);
}
@Test
public void customizeTomcatDisplayName() throws Exception {
Map<String, String> map = new HashMap<String, String>();

@ -70,7 +70,7 @@
<embedded-mongo.version>1.50.2</embedded-mongo.version>
<flyway.version>3.2.1</flyway.version>
<freemarker.version>2.3.23</freemarker.version>
<elasticsearch.version>1.7.5</elasticsearch.version>
<elasticsearch.version>2.2.0</elasticsearch.version>
<gemfire.version>8.2.0</gemfire.version>
<glassfish-el.version>3.0.0</glassfish-el.version>
<gradle.version>1.12</gradle.version>
@ -105,6 +105,7 @@
<jetty.version>9.2.15.v20160210</jetty.version>
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
<jmustache.version>1.12</jmustache.version>
<jna.version>4.2.2</jna.version>
<joda-time.version>2.9.2</joda-time.version>
<jolokia.version>1.3.3</jolokia.version>
<jooq.version>3.7.2</jooq.version>
@ -951,6 +952,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${jna.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>

@ -204,6 +204,7 @@ content into your application; rather pick only the properties that you need.
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
server.tomcat.max-http-header-size=0 # Maximum size in bytes of the HTTP message header.
server.tomcat.max-threads=0 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL.

@ -3214,11 +3214,24 @@ dependencies in a convenient way.
[[boot-features-connecting-to-elasticsearch]]
==== Connecting to Elasticsearch
You can inject an auto-configured `ElasticsearchTemplate` or Elasticsearch `Client`
instance as you would any other Spring Bean. By default the instance will attempt to
connect to a local in-memory server (a `NodeClient` in Elasticsearch terms), but you can
switch to a remote server (i.e. a `TransportClient`) by setting
instance as you would any other Spring Bean. By default the instance will embed a
local in-memory server (a `Node` in ElasticSearch terms) and use the current working
directory as the home directory for the server. In this setup, the first thing to do
is to tell ElasticSearch were to store its files:
[source,properties,indent=0]
----
spring.data.elasticsearch.properties.path.home=/foo/bar
----
Alternatively, you can switch to a remote server (i.e. a `TransportClient`) by setting
`spring.data.elasticsearch.cluster-nodes` to a comma-separated '`host:port`' list.
[source,properties,indent=0]
----
spring.data.elasticsearch.cluster-nodes=localhost:9300
----
[source,java,indent=0]
----
@Component

@ -26,6 +26,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -0,0 +1,5 @@
#
# Home directory of the embedded elastic instance. Default to the
# current working directory.
#
spring.data.elasticsearch.properties.path.home=target/elastic

@ -33,19 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artur Konczak
*/
public class SampleElasticsearchApplicationTests {
private static final String[] PROPERTIES = {
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs" };
@Rule
public OutputCapture outputCapture = new OutputCapture();
@Test
public void testDefaultSettings() throws Exception {
try {
new SpringApplicationBuilder(SampleElasticsearchApplication.class)
.properties(PROPERTIES).run();
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
}
catch (IllegalStateException ex) {
if (serverNotRunning(ex)) {

@ -61,6 +61,7 @@ import org.springframework.util.StringUtils;
* @author Ivan Sopov
* @author Andy Wilkinson
* @author Eddú Meléndez
* @author Christoph Dreis
* @since 1.2.0
* @see UndertowEmbeddedServletContainerFactory
*/
@ -87,21 +88,105 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine
private boolean started = false;
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath root the context path
* @param port the port to listen on (not used)
* @param autoStart if the server should be started
* @param compression compression configuration
* @deprecated as of 1.4 in favor of
* {@link #UndertowEmbeddedServletContainer(Builder, DeploymentManager, String, boolean, Compression)}
*/
@Deprecated
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, int port, boolean autoStart, Compression compression) {
this(builder, manager, contextPath, port, false, autoStart, compression);
this(builder, manager, contextPath, false, autoStart, compression);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath root the context path
* @param port the port to listen on (not used)
* @param useForwardHeaders if x-forward headers should be used
* @param autoStart if the server should be started
* @param compression compression configuration
* @deprecated as of 1.4 in favor of
* {@link #UndertowEmbeddedServletContainer(Builder, DeploymentManager, String, boolean, boolean, Compression)}
*/
@Deprecated
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, int port, boolean useForwardHeaders, boolean autoStart,
Compression compression) {
this(builder, manager, contextPath, port, useForwardHeaders, autoStart,
compression, null);
this(builder, manager, contextPath, useForwardHeaders, autoStart, compression);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath root the context path
* @param port the port to listen on (not used)
* @param useForwardHeaders if x-forward headers should be used
* @param autoStart if the server should be started
* @param compression compression configuration
* @param serverHeader string to be used in http header
* @deprecated as of 1.4 in favor of
* {@link #UndertowEmbeddedServletContainer(Builder, DeploymentManager, String, boolean, boolean, Compression, String)}
*/
@Deprecated
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, int port, boolean useForwardHeaders, boolean autoStart,
Compression compression, String serverHeader) {
this(builder, manager, contextPath, useForwardHeaders, autoStart, compression,
serverHeader);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath root the context path
* @param autoStart if the server should be started
* @param compression compression configuration
*/
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, boolean autoStart, Compression compression) {
this(builder, manager, contextPath, false, autoStart, compression);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath root the context path
* @param useForwardHeaders if x-forward headers should be used
* @param autoStart if the server should be started
* @param compression compression configuration
*/
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, boolean useForwardHeaders, boolean autoStart,
Compression compression) {
this(builder, manager, contextPath, useForwardHeaders, autoStart, compression,
null);
}
/**
* Create a new {@link UndertowEmbeddedServletContainer} instance.
* @param builder the builder
* @param manager the deployment manager
* @param contextPath root the context path
* @param useForwardHeaders if x-forward headers should be used
* @param autoStart if the server should be started
* @param compression compression configuration
* @param serverHeader string to be used in http header
*/
public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager,
String contextPath, boolean useForwardHeaders, boolean autoStart,
Compression compression, String serverHeader) {
this.builder = builder;
this.manager = manager;
this.contextPath = contextPath;
@ -231,10 +316,10 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine
}
private Port getPortFromChannel(BoundChannel channel) {
String protocol = ReflectionUtils.findField(channel.getClass(), "ssl") != null
? "https" : "http";
SocketAddress socketAddress = channel.getLocalAddress();
if (socketAddress instanceof InetSocketAddress) {
String protocol = ReflectionUtils.findField(channel.getClass(), "ssl") != null
? "https" : "http";
return new Port(((InetSocketAddress) socketAddress).getPort(), protocol);
}
return null;

@ -501,8 +501,7 @@ public class UndertowEmbeddedServletContainerFactory
protected UndertowEmbeddedServletContainer getUndertowEmbeddedServletContainer(
Builder builder, DeploymentManager manager, int port) {
return new UndertowEmbeddedServletContainer(builder, manager, getContextPath(),
port, isUseForwardHeaders(), port >= 0, getCompression(),
getServerHeader());
isUseForwardHeaders(), port >= 0, getCompression(), getServerHeader());
}
@Override

@ -64,7 +64,6 @@ class NoUniqueBeanDefinitionExceptionFailureAnalyzer
message.append(String.format("%s required a single bean, but %d were found:%n",
getConsumerDescription(unsatisfiedDependency), beanNames.length));
for (String beanName : beanNames) {
unsatisfiedDependency.getInjectionPoint();
try {
BeanDefinition beanDefinition = this.beanFactory
.getMergedBeanDefinition(beanName);

Loading…
Cancel
Save