Skip to content

Commit d2a7808

Browse files
committed
Polish
1 parent 217b2ef commit d2a7808

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
2424
import org.springframework.boot.actuate.health.Health;
2525
import org.springframework.boot.actuate.health.HealthIndicator;
26+
import org.springframework.boot.actuate.health.Status;
2627
import org.springframework.core.ParameterizedTypeReference;
2728
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
29+
import org.springframework.web.reactive.function.client.ClientResponse;
30+
import org.springframework.web.reactive.function.client.WebClient;
2831

2932
/**
3033
* {@link HealthIndicator} for an Elasticsearch cluster using a
@@ -50,28 +53,28 @@ public ElasticsearchReactiveHealthIndicator(ReactiveElasticsearchClient client)
5053

5154
@Override
5255
protected Mono<Health> doHealthCheck(Health.Builder builder) {
53-
return this.client.execute((callback) -> callback.get().uri("/_cluster/health/").exchange())
54-
.flatMap((response) -> {
55-
if (response.statusCode().is2xxSuccessful()) {
56-
return response.bodyToMono(STRING_OBJECT_MAP).map((body) -> {
57-
String status = (String) body.get("status");
58-
if (RED_STATUS.equals(status)) {
59-
builder.outOfService();
60-
}
61-
else {
62-
builder.up();
63-
}
64-
builder.withDetails(body);
65-
return builder.build();
66-
});
67-
}
68-
else {
69-
builder.down();
70-
builder.withDetail("statusCode", response.rawStatusCode());
71-
builder.withDetail("reasonPhrase", response.statusCode().getReasonPhrase());
72-
return response.releaseBody().thenReturn(builder.build());
73-
}
74-
});
56+
return this.client.execute(this::getHealth).flatMap((response) -> doHealthCheck(builder, response));
57+
}
58+
59+
private Mono<ClientResponse> getHealth(WebClient webClient) {
60+
return webClient.get().uri("/_cluster/health/").exchange();
61+
}
62+
63+
private Mono<Health> doHealthCheck(Health.Builder builder, ClientResponse response) {
64+
if (response.statusCode().is2xxSuccessful()) {
65+
return response.bodyToMono(STRING_OBJECT_MAP).map((body) -> getHealth(builder, body));
66+
}
67+
builder.down();
68+
builder.withDetail("statusCode", response.rawStatusCode());
69+
builder.withDetail("reasonPhrase", response.statusCode().getReasonPhrase());
70+
return response.releaseBody().thenReturn(builder.build());
71+
}
72+
73+
private Health getHealth(Health.Builder builder, Map<String, Object> body) {
74+
String status = (String) body.get("status");
75+
builder.status(RED_STATUS.equals(status) ? Status.OUT_OF_SERVICE : Status.UP);
76+
builder.withDetails(body);
77+
return builder.build();
7578
}
7679

7780
}

spring-boot-project/spring-boot-docs/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ dependencies {
9595
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
9696
testImplementation("org.assertj:assertj-core")
9797
testImplementation("org.junit.jupiter:junit-jupiter")
98-
98+
9999
testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
100100
testRuntimeOnly("com.h2database:h2")
101101
testRuntimeOnly("org.springframework:spring-jdbc")

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ static LocalHttpClientTransport create(Environment environment) {
6969

7070
private static String socketFilePath(Environment environment) {
7171
String host = environment.get(DOCKER_HOST);
72-
return (host != null && host.startsWith(UNIX_SOCKET_PREFIX)) ? host.substring(UNIX_SOCKET_PREFIX.length())
73-
: host;
72+
if (host != null && host.startsWith(UNIX_SOCKET_PREFIX)) {
73+
return host.substring(UNIX_SOCKET_PREFIX.length());
74+
}
75+
return host;
7476
}
7577

7678
/**

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchive.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void writeTo(OutputStream outputStream) throws IOException {
7676

7777
private void assertArchiveHasEntries(File jarFile) {
7878
try (ZipFile zipFile = new ZipFile(jarFile)) {
79-
Assert.state(zipFile.getEntries().hasMoreElements(), "File '" + jarFile.toString()
79+
Assert.state(zipFile.getEntries().hasMoreElements(), () -> "File '" + jarFile
8080
+ "' is not compatible with buildpacks; ensure jar file is valid and launch script is not enabled");
8181
}
8282
catch (IOException ex) {

0 commit comments

Comments
 (0)