davsclaus commented on code in PR #1010:
URL: 
https://github.com/apache/camel-spring-boot/pull/1010#discussion_r1397323705


##########
core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/readiness/CamelReadinessStateHealthIndicator.java:
##########
@@ -0,0 +1,51 @@
+package org.apache.camel.spring.boot.actuate.health.readiness;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import 
org.springframework.boot.actuate.availability.ReadinessStateHealthIndicator;
+import org.springframework.boot.availability.ApplicationAvailability;
+import org.springframework.boot.availability.AvailabilityState;
+import org.springframework.boot.availability.ReadinessState;
+
+import java.util.Collection;
+
+public class CamelReadinessStateHealthIndicator extends 
ReadinessStateHealthIndicator {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(CamelReadinessStateHealthIndicator.class);
+
+       private CamelContext camelContext;
+
+       public CamelReadinessStateHealthIndicator(
+                       ApplicationAvailability availability,
+                       CamelContext camelContext) {
+               super(availability);
+
+               this.camelContext = camelContext;
+       }
+
+       @Override
+       protected AvailabilityState getState(ApplicationAvailability 
applicationAvailability) {
+               Collection<HealthCheck.Result> results = 
HealthCheckHelper.invokeReadiness(camelContext);
+
+               boolean isReady = checkState(results, LOG);
+
+               return isReady ?
+                               ReadinessState.ACCEPTING_TRAFFIC : 
ReadinessState.REFUSING_TRAFFIC;
+       }
+
+       public static boolean checkState(Collection<HealthCheck.Result> 
results, Logger log) {
+               boolean isUp = true;
+               for (HealthCheck.Result result : results) {
+                       if (!HealthCheck.State.UP.equals(result.getState())) {
+                               isUp = false;
+
+                               result.getError().ifPresent(error -> 
log.warn(result.getCheck().getId(), error));

Review Comment:
   Does spring boot not have more details you can set/enrich to the object your 
return. It should not be every custom check that has to do their own kind of 
logging or whatever - SB should really deal with this generally.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to