forked from cloudfoundry-samples/spring-music
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade dependencies and improve the health check
Upgrade SpringBoot to 1.5.4 Upgrade Spring Cloud Connectors to 1.2.4 Upgrade Java to 1.8 Upgrade gradle to version 3.5 Polish the gradle build file Create a a custom health aggregator that only reports on the health of the database being used. For example if Redis is used it does not report on the health of th SQL database and Redis, if a SQL db is used it does not report on the heath of mongodb and redis
- Loading branch information
Showing
10 changed files
with
118 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ target/ | |
build/ | ||
|
||
*.log* | ||
/classes/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jul 01 14:31:42 EDT 2016 | ||
#Sun Jun 18 20:18:18 EDT 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/cloudfoundry/samples/music/SpringMusicHealthAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.cloudfoundry.samples.music; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthAggregator; | ||
import org.springframework.boot.actuate.health.OrderedHealthAggregator; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
|
||
/** | ||
* Health Aggregator class that only considers the persistence provider that is used. | ||
* For example if H2 is used then it will not aggregate the health of redis and | ||
* mongodb. | ||
*/ | ||
@Component | ||
public class SpringMusicHealthAggregator implements HealthAggregator { | ||
|
||
private final List<String> excluded = new ArrayList<>(); | ||
private final OrderedHealthAggregator orderedHealthAggregator = new OrderedHealthAggregator(); | ||
|
||
@Autowired | ||
public SpringMusicHealthAggregator(Environment environment) { | ||
|
||
if(environment.acceptsProfiles("redis")){ | ||
excluded.add("mongo"); | ||
excluded.add("db"); | ||
} else if( environment.acceptsProfiles("mongodb")) { | ||
excluded.add("redis"); | ||
excluded.add("db"); | ||
} else { | ||
excluded.add("mongo"); | ||
excluded.add("redis"); | ||
} | ||
} | ||
|
||
@Override | ||
public Health aggregate(Map<String, Health> healths){ | ||
|
||
Map<String,Health> filtered = healths.entrySet().stream().filter( entry -> !excluded.contains(entry.getKey())). | ||
collect(toMap(entry -> entry.getKey(), entry -> entry.getValue())); | ||
|
||
Health filteredHealth = orderedHealthAggregator.aggregate(filtered); | ||
return filteredHealth; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters