Skip to content

Commit 63a3d00

Browse files
committed
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
2 parents ca71656 + 05ef081 commit 63a3d00

File tree

16 files changed

+182
-36
lines changed

16 files changed

+182
-36
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ public void notJmsHealthIndicator() {
393393
@Test
394394
public void elasticSearchHealthIndicator() {
395395
EnvironmentTestUtils.addEnvironment(this.context,
396-
"spring.data.elasticsearch.properties.path.data:target/data",
397-
"spring.data.elasticsearch.properties.path.logs:target/logs",
396+
"spring.data.elasticsearch.properties.path.home:target",
398397
"management.health.diskspace.enabled:false");
399398
this.context.register(ElasticsearchAutoConfiguration.class,
400399
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
@@ -411,8 +410,7 @@ public void elasticSearchHealthIndicator() {
411410
public void notElasticSearchHealthIndicator() {
412411
EnvironmentTestUtils.addEnvironment(this.context,
413412
"management.health.elasticsearch.enabled:false",
414-
"spring.data.elasticsearch.properties.path.data:target/data",
415-
"spring.data.elasticsearch.properties.path.logs:target/logs",
413+
"spring.data.elasticsearch.properties.path.home:target",
416414
"management.health.diskspace.enabled:false");
417415
this.context.register(ElasticsearchAutoConfiguration.class,
418416
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import org.elasticsearch.ElasticsearchTimeoutException;
2424
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
2525
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
26-
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
2726
import org.elasticsearch.action.support.PlainActionFuture;
2827
import org.elasticsearch.client.AdminClient;
2928
import org.elasticsearch.client.Client;
3029
import org.elasticsearch.client.ClusterAdminClient;
3130
import org.elasticsearch.cluster.ClusterState;
3231
import org.elasticsearch.cluster.block.ClusterBlocks;
32+
import org.elasticsearch.cluster.health.ClusterHealthStatus;
3333
import org.elasticsearch.cluster.node.DiscoveryNodes;
3434
import org.elasticsearch.cluster.routing.RoutingTable;
3535
import org.junit.Before;
@@ -176,9 +176,9 @@ private StubClusterHealthResponse() {
176176

177177
private StubClusterHealthResponse(ClusterHealthStatus status) {
178178
super("test-cluster", new String[0],
179-
new ClusterState(null, 0, null, RoutingTable.builder().build(),
179+
new ClusterState(null, 0, null, null, RoutingTable.builder().build(),
180180
DiscoveryNodes.builder().build(),
181-
ClusterBlocks.builder().build(), null));
181+
ClusterBlocks.builder().build(), null, false));
182182
this.status = status;
183183
}
184184

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.elasticsearch.client.Client;
2727
import org.elasticsearch.client.transport.TransportClient;
2828
import org.elasticsearch.common.lease.Releasable;
29-
import org.elasticsearch.common.settings.ImmutableSettings;
29+
import org.elasticsearch.common.settings.Settings;
3030
import org.elasticsearch.node.Node;
3131
import org.elasticsearch.node.NodeBuilder;
3232

@@ -62,6 +62,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
6262
Map<String, String> defaults = new LinkedHashMap<String, String>();
6363
defaults.put("http.enabled", String.valueOf(false));
6464
defaults.put("node.local", String.valueOf(true));
65+
defaults.put("path.home", System.getProperty("user.dir"));
6566
DEFAULTS = Collections.unmodifiableMap(defaults);
6667
}
6768

@@ -95,7 +96,7 @@ private Client createClient() throws Exception {
9596
}
9697

9798
private Client createNodeClient() throws Exception {
98-
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
99+
Settings.Builder settings = Settings.settingsBuilder();
99100
for (Map.Entry<String, String> entry : DEFAULTS.entrySet()) {
100101
if (!this.properties.getProperties().containsKey(entry.getKey())) {
101102
settings.put(entry.getKey(), entry.getValue());

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
* @author Ivan Sopov
7373
* @author Marcos Barbero
7474
* @author Eddú Meléndez
75+
* @author Quinten De Swaef
7576
*/
7677
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
7778
public class ServerProperties
@@ -580,6 +581,11 @@ public static class Tomcat {
580581
*/
581582
private int maxThreads = 0; // Number of threads in protocol handler
582583

584+
/**
585+
* Minimum amount of worker threads.
586+
*/
587+
private int minSpareThreads = 0; // Minimum spare threads in protocol handler
588+
583589
/**
584590
* Maximum size in bytes of the HTTP message header.
585591
*/
@@ -598,6 +604,14 @@ public void setMaxThreads(int maxThreads) {
598604
this.maxThreads = maxThreads;
599605
}
600606

607+
public int getMinSpareThreads() {
608+
return this.minSpareThreads;
609+
}
610+
611+
public void setMinSpareThreads(int minSpareThreads) {
612+
this.minSpareThreads = minSpareThreads;
613+
}
614+
601615
public int getMaxHttpHeaderSize() {
602616
return this.maxHttpHeaderSize;
603617
}
@@ -684,6 +698,9 @@ void customizeTomcat(ServerProperties serverProperties,
684698
if (this.maxThreads > 0) {
685699
customizeMaxThreads(factory);
686700
}
701+
if (this.minSpareThreads > 0) {
702+
customizeMinThreads(factory);
703+
}
687704
if (this.maxHttpHeaderSize > 0) {
688705
customizeMaxHttpHeaderSize(factory);
689706
}
@@ -747,6 +764,22 @@ public void customize(Connector connector) {
747764
});
748765
}
749766

767+
@SuppressWarnings("rawtypes")
768+
private void customizeMinThreads(TomcatEmbeddedServletContainerFactory factory) {
769+
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
770+
@Override
771+
public void customize(Connector connector) {
772+
773+
ProtocolHandler handler = connector.getProtocolHandler();
774+
if (handler instanceof AbstractProtocol) {
775+
AbstractProtocol protocol = (AbstractProtocol) handler;
776+
protocol.setMinSpareThreads(Tomcat.this.minSpareThreads);
777+
}
778+
779+
}
780+
});
781+
}
782+
750783
@SuppressWarnings("rawtypes")
751784
private void customizeMaxHttpHeaderSize(
752785
TomcatEmbeddedServletContainerFactory factory) {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public void createNodeClientWithDefaults() {
5757
this.context = new AnnotationConfigApplicationContext();
5858
EnvironmentTestUtils.addEnvironment(this.context,
5959
"spring.data.elasticsearch.properties.foo.bar:baz",
60-
"spring.data.elasticsearch.properties.path.data:target/data",
61-
"spring.data.elasticsearch.properties.path.logs:target/logs");
60+
"spring.data.elasticsearch.properties.path.home:target");
6261
this.context.register(PropertyPlaceholderAutoConfiguration.class,
6362
ElasticsearchAutoConfiguration.class);
6463
this.context.refresh();
@@ -74,8 +73,7 @@ public void createNodeClientWithOverrides() {
7473
this.context = new AnnotationConfigApplicationContext();
7574
EnvironmentTestUtils.addEnvironment(this.context,
7675
"spring.data.elasticsearch.properties.foo.bar:baz",
77-
"spring.data.elasticsearch.properties.path.data:target/data",
78-
"spring.data.elasticsearch.properties.path.logs:target/logs",
76+
"spring.data.elasticsearch.properties.path.home:target",
7977
"spring.data.elasticsearch.properties.node.local:false",
8078
"spring.data.elasticsearch.properties.node.data:true",
8179
"spring.data.elasticsearch.properties.http.enabled:true");
@@ -109,8 +107,7 @@ public void createTransportClient() throws Exception {
109107
this.context = new AnnotationConfigApplicationContext();
110108
EnvironmentTestUtils.addEnvironment(this.context,
111109
"spring.data.elasticsearch.cluster-nodes:localhost",
112-
"spring.data.elasticsearch.properties.path.data:target/data",
113-
"spring.data.elasticsearch.properties.path.logs:target/logs");
110+
"spring.data.elasticsearch.properties.path.home:target");
114111
this.context.register(PropertyPlaceholderAutoConfiguration.class,
115112
ElasticsearchAutoConfiguration.class);
116113
this.thrown.expect(BeanCreationException.class);

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
8989

9090
private void addElasticsearchProperties(AnnotationConfigApplicationContext context) {
9191
EnvironmentTestUtils.addEnvironment(context,
92-
"spring.data.elasticsearch.properties.path.data:target/data",
93-
"spring.data.elasticsearch.properties.path.logs:target/logs");
92+
"spring.data.elasticsearch.properties.path.home:target");
9493
}
9594

9695
@Configuration

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* @author Andy Wilkinson
6363
* @author Phillip Webb
6464
* @author Eddú Meléndez
65+
* @author Quinten De Swaef
6566
*/
6667
public class ServerPropertiesTests {
6768

@@ -258,6 +259,14 @@ public void testCustomizeTomcatHeaderSize() throws Exception {
258259
assertThat(this.properties.getTomcat().getMaxHttpHeaderSize()).isEqualTo(9999);
259260
}
260261

262+
@Test
263+
public void testCustomizeTomcatMinSpareThreads() throws Exception {
264+
Map<String, String> map = new HashMap<String, String>();
265+
map.put("server.tomcat.min-spare-threads", "10");
266+
bindProperties(map);
267+
assertThat(this.properties.getTomcat().getMinSpareThreads()).isEqualTo(10);
268+
}
269+
261270
@Test
262271
public void customizeTomcatDisplayName() throws Exception {
263272
Map<String, String> map = new HashMap<String, String>();

spring-boot-dependencies/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<embedded-mongo.version>1.50.2</embedded-mongo.version>
7171
<flyway.version>3.2.1</flyway.version>
7272
<freemarker.version>2.3.23</freemarker.version>
73-
<elasticsearch.version>1.7.5</elasticsearch.version>
73+
<elasticsearch.version>2.2.0</elasticsearch.version>
7474
<gemfire.version>8.2.0</gemfire.version>
7575
<glassfish-el.version>3.0.0</glassfish-el.version>
7676
<gradle.version>1.12</gradle.version>
@@ -105,6 +105,7 @@
105105
<jetty.version>9.2.15.v20160210</jetty.version>
106106
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
107107
<jmustache.version>1.12</jmustache.version>
108+
<jna.version>4.2.2</jna.version>
108109
<joda-time.version>2.9.2</joda-time.version>
109110
<jolokia.version>1.3.3</jolokia.version>
110111
<jooq.version>3.7.2</jooq.version>
@@ -951,6 +952,11 @@
951952
<artifactId>mysql-connector-java</artifactId>
952953
<version>${mysql.version}</version>
953954
</dependency>
955+
<dependency>
956+
<groupId>net.java.dev.jna</groupId>
957+
<artifactId>jna</artifactId>
958+
<version>${jna.version}</version>
959+
</dependency>
954960
<dependency>
955961
<groupId>net.sf.ehcache</groupId>
956962
<artifactId>ehcache</artifactId>

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

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

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,11 +3214,24 @@ dependencies in a convenient way.
32143214
[[boot-features-connecting-to-elasticsearch]]
32153215
==== Connecting to Elasticsearch
32163216
You can inject an auto-configured `ElasticsearchTemplate` or Elasticsearch `Client`
3217-
instance as you would any other Spring Bean. By default the instance will attempt to
3218-
connect to a local in-memory server (a `NodeClient` in Elasticsearch terms), but you can
3219-
switch to a remote server (i.e. a `TransportClient`) by setting
3217+
instance as you would any other Spring Bean. By default the instance will embed a
3218+
local in-memory server (a `Node` in ElasticSearch terms) and use the current working
3219+
directory as the home directory for the server. In this setup, the first thing to do
3220+
is to tell ElasticSearch were to store its files:
3221+
3222+
[source,properties,indent=0]
3223+
----
3224+
spring.data.elasticsearch.properties.path.home=/foo/bar
3225+
----
3226+
3227+
Alternatively, you can switch to a remote server (i.e. a `TransportClient`) by setting
32203228
`spring.data.elasticsearch.cluster-nodes` to a comma-separated '`host:port`' list.
32213229

3230+
[source,properties,indent=0]
3231+
----
3232+
spring.data.elasticsearch.cluster-nodes=localhost:9300
3233+
----
3234+
32223235
[source,java,indent=0]
32233236
----
32243237
@Component

spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
<groupId>org.springframework.boot</groupId>
2727
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
2828
</dependency>
29+
30+
<dependency>
31+
<groupId>net.java.dev.jna</groupId>
32+
<artifactId>jna</artifactId>
33+
<scope>runtime</scope>
34+
</dependency>
35+
2936
<dependency>
3037
<groupId>org.springframework.boot</groupId>
3138
<artifactId>spring-boot-starter-test</artifactId>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Home directory of the embedded elastic instance. Default to the
3+
# current working directory.
4+
#
5+
spring.data.elasticsearch.properties.path.home=target/elastic

spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,13 @@
3333
* @author Artur Konczak
3434
*/
3535
public class SampleElasticsearchApplicationTests {
36-
37-
private static final String[] PROPERTIES = {
38-
"spring.data.elasticsearch.properties.path.data:target/data",
39-
"spring.data.elasticsearch.properties.path.logs:target/logs" };
40-
4136
@Rule
4237
public OutputCapture outputCapture = new OutputCapture();
4338

4439
@Test
4540
public void testDefaultSettings() throws Exception {
4641
try {
47-
new SpringApplicationBuilder(SampleElasticsearchApplication.class)
48-
.properties(PROPERTIES).run();
42+
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
4943
}
5044
catch (IllegalStateException ex) {
5145
if (serverNotRunning(ex)) {

0 commit comments

Comments
 (0)