forked from scottfrederick/spring-music
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #23 from asaikali/master
Upgrade dependencies and improve the health check
- Loading branch information
Showing
10 changed files
with
116 additions
and
64 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 21:47:36 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.1-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