From 51a26a4d5a5bcea6aebe4b518aa8dde02fb94b74 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 22 Jul 2020 17:01:19 -0700 Subject: [PATCH 1/4] Polish --- .../actuate/redis/RedisHealthIndicator.java | 30 ++++++++--------- .../redis/RedisReactiveHealthIndicator.java | 32 +++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java index 83648a9f59..cca6d7c867 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java @@ -16,8 +16,6 @@ package org.springframework.boot.actuate.redis; -import java.util.Properties; - import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; @@ -38,9 +36,7 @@ import org.springframework.util.Assert; */ public class RedisHealthIndicator extends AbstractHealthIndicator { - static final String VERSION = "version"; - - static final String REDIS_VERSION = "redis_version"; + private static final String REDIS_VERSION_PROPERTY = "redis_version"; private final RedisConnectionFactory redisConnectionFactory; @@ -54,20 +50,24 @@ public class RedisHealthIndicator extends AbstractHealthIndicator { protected void doHealthCheck(Health.Builder builder) throws Exception { RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory); try { - if (connection instanceof RedisClusterConnection) { - ClusterInfo clusterInfo = ((RedisClusterConnection) connection).clusterGetClusterInfo(); - builder.up().withDetail("cluster_size", clusterInfo.getClusterSize()) - .withDetail("slots_up", clusterInfo.getSlotsOk()) - .withDetail("slots_fail", clusterInfo.getSlotsFail()); - } - else { - Properties info = connection.info(); - builder.up().withDetail(VERSION, info.getProperty(REDIS_VERSION)); - } + doHealthCheck(builder, connection); } finally { RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory, false); } } + private void doHealthCheck(Health.Builder builder, RedisConnection connection) { + if (connection instanceof RedisClusterConnection) { + ClusterInfo clusterInfo = ((RedisClusterConnection) connection).clusterGetClusterInfo(); + builder.up().withDetail("cluster_size", clusterInfo.getClusterSize()) + .withDetail("slots_up", clusterInfo.getSlotsOk()) + .withDetail("slots_fail", clusterInfo.getSlotsFail()); + } + else { + String version = connection.info().getProperty(REDIS_VERSION_PROPERTY); + builder.up().withDetail("version", version); + } + } + } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java index c708246320..d981cde76c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java @@ -39,6 +39,8 @@ import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory; */ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicator { + private static final String REDIS_VERSION_PROPERTY = "redis_version"; + private final ReactiveRedisConnectionFactory connectionFactory; public RedisReactiveHealthIndicator(ReactiveRedisConnectionFactory connectionFactory) { @@ -52,8 +54,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato } private Mono doHealthCheck(Health.Builder builder, ReactiveRedisConnection connection) { - return connection.serverCommands().info() - .map((info) -> up(builder, info, (connection instanceof ReactiveRedisClusterConnection))) + boolean isClusterConnection = connection instanceof ReactiveRedisClusterConnection; + return connection.serverCommands().info().map((info) -> up(builder, info, isClusterConnection)) .onErrorResume((ex) -> Mono.just(down(builder, ex))) .flatMap((health) -> connection.closeLater().thenReturn(health)); } @@ -64,24 +66,22 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato } private Health up(Health.Builder builder, Properties info, boolean isClusterConnection) { - if (isClusterConnection) { - return builder.up().withDetail(RedisHealthIndicator.VERSION, getClusterVersionProperty(info)).build(); - } - else { - return builder.up() - .withDetail(RedisHealthIndicator.VERSION, info.getProperty(RedisHealthIndicator.REDIS_VERSION)) - .build(); - } - } - - private Object getClusterVersionProperty(Properties info) { - return info.keySet().stream().map(String.class::cast) - .filter((key) -> key.endsWith(RedisHealthIndicator.REDIS_VERSION)).findFirst().map(info::get) - .orElse(""); + String version = isClusterConnection ? getClusterVersionProperty(info) + : info.getProperty(REDIS_VERSION_PROPERTY); + return builder.up().withDetail("version", version).build(); } private Health down(Health.Builder builder, Throwable cause) { return builder.down(cause).build(); } + private String getClusterVersionProperty(Properties info) { + for (String propertyName : info.stringPropertyNames()) { + if (propertyName.endsWith(REDIS_VERSION_PROPERTY)) { + return info.getProperty(propertyName); + } + } + return ""; + } + } From b5e70157dcb7b7346918adf4d067cc91df6a2712 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 22 Jul 2020 17:01:36 -0700 Subject: [PATCH 2/4] Update copyright year of changed files --- .../releasescripts/artifactory/ArtifactoryService.java | 2 +- .../releasescripts/artifactory/payload/BuildInfoResponse.java | 2 +- .../spring/concourse/releasescripts/bintray/BintrayService.java | 2 +- .../io/spring/concourse/releasescripts/bintray/PackageFile.java | 2 +- .../concourse/releasescripts/command/CommandProcessor.java | 2 +- .../concourse/releasescripts/command/DistributeCommand.java | 2 +- .../spring/concourse/releasescripts/command/PromoteCommand.java | 2 +- .../concourse/releasescripts/command/PublishGradlePlugin.java | 2 +- .../concourse/releasescripts/command/SyncToCentralCommand.java | 2 +- .../concourse/releasescripts/sonatype/SonatypeService.java | 2 +- .../releasescripts/artifactory/ArtifactoryServiceTests.java | 2 +- .../concourse/releasescripts/bintray/BintrayServiceTests.java | 2 +- .../releasescripts/command/DistributeCommandTests.java | 2 +- .../concourse/releasescripts/sonatype/SonatypeServiceTests.java | 2 +- .../boot/actuate/redis/RedisHealthIndicator.java | 2 +- .../boot/actuate/redis/RedisReactiveHealthIndicator.java | 2 +- .../boot/actuate/redis/RedisReactiveHealthIndicatorTests.java | 2 +- .../autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java | 2 +- .../autoconfigure/session/SessionAutoConfigurationTests.java | 2 +- .../boot/test/mock/mockito/DefinitionsParser.java | 2 +- .../java/org/springframework/boot/web/server/ErrorPage.java | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java index 32141710ad..811eedd636 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/payload/BuildInfoResponse.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/payload/BuildInfoResponse.java index 0c340e8d04..149d2c56fd 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/payload/BuildInfoResponse.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/payload/BuildInfoResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java index b2ef96d506..80ca5fa41f 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/PackageFile.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/PackageFile.java index 4a6f3ad8cb..ee7728e812 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/PackageFile.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/PackageFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/CommandProcessor.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/CommandProcessor.java index eea33a5666..50a0b2132a 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/CommandProcessor.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/CommandProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/DistributeCommand.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/DistributeCommand.java index d22aa974d3..cbd828710e 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/DistributeCommand.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/DistributeCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PromoteCommand.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PromoteCommand.java index ef5ecc2d87..dc8f80ceba 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PromoteCommand.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PromoteCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishGradlePlugin.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishGradlePlugin.java index a00d6d340f..aa3f42c510 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishGradlePlugin.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishGradlePlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/SyncToCentralCommand.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/SyncToCentralCommand.java index 0a7a02de76..e2a5cab5a8 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/SyncToCentralCommand.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/SyncToCentralCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java index 0ef88e5639..789e4ba6a3 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryServiceTests.java b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryServiceTests.java index 8105c8bf5e..6ce710ebdd 100644 --- a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryServiceTests.java +++ b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/bintray/BintrayServiceTests.java b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/bintray/BintrayServiceTests.java index 67c4369c8e..e88780cf2c 100644 --- a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/bintray/BintrayServiceTests.java +++ b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/bintray/BintrayServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/command/DistributeCommandTests.java b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/command/DistributeCommandTests.java index 3fcaf5dc7e..ef949b0ada 100644 --- a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/command/DistributeCommandTests.java +++ b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/command/DistributeCommandTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sonatype/SonatypeServiceTests.java b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sonatype/SonatypeServiceTests.java index ae0a257ecd..d8e09f70e1 100644 --- a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sonatype/SonatypeServiceTests.java +++ b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sonatype/SonatypeServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java index cca6d7c867..45eaff9619 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java index d981cde76c..386700d568 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java index 078962266d..1717c2e60e 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java index a38d8fd62b..8aa4b6e8a6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java index 83c7dcfde3..c7e30efaab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/DefinitionsParser.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/DefinitionsParser.java index 8b73e40d7e..656aa46d01 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/DefinitionsParser.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/DefinitionsParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java index 10d10a86d3..dd89f5a00b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. From d2a78080987de1411f992632c8f3e35bde92e2ba Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 22 Jul 2020 17:25:04 -0700 Subject: [PATCH 3/4] Polish --- .../ElasticsearchReactiveHealthIndicator.java | 47 ++++++++++--------- .../spring-boot-docs/build.gradle | 2 +- .../transport/LocalHttpClientTransport.java | 6 ++- .../platform/io/ZipFileTarArchive.java | 2 +- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java index 1c4272c8e0..a71b0d199c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java @@ -23,8 +23,11 @@ import reactor.core.publisher.Mono; import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.actuate.health.Status; import org.springframework.core.ParameterizedTypeReference; import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; /** * {@link HealthIndicator} for an Elasticsearch cluster using a @@ -50,28 +53,28 @@ public class ElasticsearchReactiveHealthIndicator extends AbstractReactiveHealth @Override protected Mono doHealthCheck(Health.Builder builder) { - return this.client.execute((callback) -> callback.get().uri("/_cluster/health/").exchange()) - .flatMap((response) -> { - if (response.statusCode().is2xxSuccessful()) { - return response.bodyToMono(STRING_OBJECT_MAP).map((body) -> { - String status = (String) body.get("status"); - if (RED_STATUS.equals(status)) { - builder.outOfService(); - } - else { - builder.up(); - } - builder.withDetails(body); - return builder.build(); - }); - } - else { - builder.down(); - builder.withDetail("statusCode", response.rawStatusCode()); - builder.withDetail("reasonPhrase", response.statusCode().getReasonPhrase()); - return response.releaseBody().thenReturn(builder.build()); - } - }); + return this.client.execute(this::getHealth).flatMap((response) -> doHealthCheck(builder, response)); + } + + private Mono getHealth(WebClient webClient) { + return webClient.get().uri("/_cluster/health/").exchange(); + } + + private Mono doHealthCheck(Health.Builder builder, ClientResponse response) { + if (response.statusCode().is2xxSuccessful()) { + return response.bodyToMono(STRING_OBJECT_MAP).map((body) -> getHealth(builder, body)); + } + builder.down(); + builder.withDetail("statusCode", response.rawStatusCode()); + builder.withDetail("reasonPhrase", response.statusCode().getReasonPhrase()); + return response.releaseBody().thenReturn(builder.build()); + } + + private Health getHealth(Health.Builder builder, Map body) { + String status = (String) body.get("status"); + builder.status(RED_STATUS.equals(status) ? Status.OUT_OF_SERVICE : Status.UP); + builder.withDetails(body); + return builder.build(); } } diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index c52cfaa211..a080ef8028 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -95,7 +95,7 @@ dependencies { testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) testImplementation("org.assertj:assertj-core") testImplementation("org.junit.jupiter:junit-jupiter") - + testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) testRuntimeOnly("com.h2database:h2") testRuntimeOnly("org.springframework:spring-jdbc") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java index fbe3914528..9861f4d45a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java @@ -69,8 +69,10 @@ final class LocalHttpClientTransport extends HttpClientTransport { private static String socketFilePath(Environment environment) { String host = environment.get(DOCKER_HOST); - return (host != null && host.startsWith(UNIX_SOCKET_PREFIX)) ? host.substring(UNIX_SOCKET_PREFIX.length()) - : host; + if (host != null && host.startsWith(UNIX_SOCKET_PREFIX)) { + return host.substring(UNIX_SOCKET_PREFIX.length()); + } + return host; } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchive.java index 0555eb979a..90d543b0d6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchive.java @@ -76,7 +76,7 @@ public class ZipFileTarArchive implements TarArchive { private void assertArchiveHasEntries(File jarFile) { try (ZipFile zipFile = new ZipFile(jarFile)) { - Assert.state(zipFile.getEntries().hasMoreElements(), "File '" + jarFile.toString() + Assert.state(zipFile.getEntries().hasMoreElements(), () -> "File '" + jarFile + "' is not compatible with buildpacks; ensure jar file is valid and launch script is not enabled"); } catch (IOException ex) { From 187d3af7fc4581b1c55c367e64a87510be5a785c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 22 Jul 2020 17:25:17 -0700 Subject: [PATCH 4/4] Update copyright year of changed files --- .../kafka/KafkaStreamsAnnotationDrivenConfiguration.java | 2 +- .../autoconfigure/mustache/MustacheEnvironmentCollector.java | 2 +- .../mustache/MustacheStandaloneIntegrationTests.java | 2 +- .../springframework/boot/web/client/RestTemplateBuilder.java | 2 +- .../org/springframework/boot/BeanDefinitionLoaderTests.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaStreamsAnnotationDrivenConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaStreamsAnnotationDrivenConfiguration.java index d052adddc0..1a5a106392 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaStreamsAnnotationDrivenConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaStreamsAnnotationDrivenConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java index c9d0cebfbd..373a1d6364 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java index 7c1efa729c..66e1b85ef8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java index 51c1e9dee7..3dc439dd57 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BeanDefinitionLoaderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BeanDefinitionLoaderTests.java index 7ddf590749..eacf0a150a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BeanDefinitionLoaderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BeanDefinitionLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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.