This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit e5373c0d3e899d5d377535ec8204441c13c1bf83 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Mar 20 15:23:39 2018 +0100 CAMEL-11430: Spring Boot 2 - Add Camel info contributor to /actuator/info to show Camel information. --- .../boot/actuate/health/CamelHealthIndicator.java | 8 +++- .../actuate/info/CamelInfoAutoConfiguration.java | 48 ++++++++++++++++++++ .../boot/actuate/info/CamelInfoContributor.java | 46 +++++++++++++++++++ .../additional-spring-configuration-metadata.json | 6 +++ .../src/main/resources/META-INF/spring.factories | 1 + .../spring/boot/actuate/info/CamelInfoTest.java | 53 ++++++++++++++++++++++ examples/camel-example-spring-boot/pom.xml | 2 +- .../src/main/resources/application.properties | 11 +++-- 8 files changed, 167 insertions(+), 8 deletions(-) diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java index 1968068..09c723a 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/health/CamelHealthIndicator.java @@ -26,7 +26,7 @@ import org.springframework.boot.actuate.health.HealthIndicator; */ public class CamelHealthIndicator extends AbstractHealthIndicator { - private CamelContext camelContext; + private final CamelContext camelContext; public CamelHealthIndicator(CamelContext camelContext) { this.camelContext = camelContext; @@ -39,7 +39,11 @@ public class CamelHealthIndicator extends AbstractHealthIndicator { } else { builder.withDetail("name", camelContext.getName()); builder.withDetail("version", camelContext.getVersion()); - builder.withDetail("contextStatus", camelContext.getStatus().name()); + if (camelContext.getUptime() != null) { + builder.withDetail("uptime", camelContext.getUptime()); + builder.withDetail("uptimeMillis", camelContext.getUptimeMillis()); + } + builder.withDetail("status", camelContext.getStatus().name()); if (camelContext.getStatus().isStarted()) { builder.up(); } else if (camelContext.getStatus().isStopped()) { diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/info/CamelInfoAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/info/CamelInfoAutoConfiguration.java new file mode 100644 index 0000000..0b71129 --- /dev/null +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/info/CamelInfoAutoConfiguration.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.boot.actuate.info; + +import org.apache.camel.CamelContext; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor; +import org.springframework.boot.actuate.info.InfoContributor; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConditionalOnClass({InfoContributor.class}) +@ConditionalOnBean(CamelAutoConfiguration.class) +@AutoConfigureAfter(CamelAutoConfiguration.class) +public class CamelInfoAutoConfiguration { + + @ConditionalOnClass({CamelContext.class}) + @ConditionalOnMissingBean(CamelInfoContributor.class) + @ConditionalOnEnabledInfoContributor(value = "camel") + protected static class CamelInfoContributorInitializer { + + @Bean + public InfoContributor camelInfoContributor(CamelContext camelContext) { + return new CamelInfoContributor(camelContext); + } + + } + +} diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/info/CamelInfoContributor.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/info/CamelInfoContributor.java new file mode 100644 index 0000000..811e721 --- /dev/null +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/info/CamelInfoContributor.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.boot.actuate.info; + +import org.apache.camel.CamelContext; +import org.springframework.boot.actuate.info.Info; +import org.springframework.boot.actuate.info.InfoContributor; + +/** + * Camel {@link InfoContributor} + */ +public class CamelInfoContributor implements InfoContributor { + + private final CamelContext camelContext; + + public CamelInfoContributor(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + public void contribute(Info.Builder builder) { + if (camelContext != null) { + builder.withDetail("camel.name", camelContext.getName()); + builder.withDetail("camel.version", camelContext.getVersion()); + if (camelContext.getUptime() != null) { + builder.withDetail("camel.uptime", camelContext.getUptime()); + builder.withDetail("camel.uptimeMillis", camelContext.getUptimeMillis()); + } + builder.withDetail("camel.status", camelContext.getStatus().name()); + } + } +} diff --git a/components/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/components/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 6074cb7..d9610aa 100644 --- a/components/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/components/camel-spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -17,6 +17,12 @@ "type": "java.lang.Boolean", "description": "To turn on or off information about Camel Routes via actuator endpoint.", "defaultValue": true + }, + { + "name": "management.info.camel.enabled", + "type": "java.lang.Boolean", + "description": "Whether to enable Camel info.", + "defaultValue": true } ] } diff --git a/components/camel-spring-boot/src/main/resources/META-INF/spring.factories b/components/camel-spring-boot/src/main/resources/META-INF/spring.factories index 2d21167..312323c 100644 --- a/components/camel-spring-boot/src/main/resources/META-INF/spring.factories +++ b/components/camel-spring-boot/src/main/resources/META-INF/spring.factories @@ -21,6 +21,7 @@ org.apache.camel.spring.boot.SupervisingRouteControllerAutoConfiguration,\ org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpointAutoConfiguration,\ org.apache.camel.spring.boot.actuate.endpoint.CamelRouteControllerEndpointAutoConfiguration,\ org.apache.camel.spring.boot.actuate.health.CamelHealthAutoConfiguration,\ +org.apache.camel.spring.boot.actuate.info.CamelInfoAutoConfiguration,\ org.apache.camel.spring.boot.cloud.CamelCloudAutoConfiguration,\ org.apache.camel.spring.boot.cloud.CamelCloudServiceCallConfigurationAutoConfiguration,\ org.apache.camel.spring.boot.cloud.CamelCloudServiceDiscoveryAutoConfiguration,\ diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/info/CamelInfoTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/info/CamelInfoTest.java new file mode 100644 index 0000000..83c08bd --- /dev/null +++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/info/CamelInfoTest.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.boot.actuate.info; + +import org.apache.camel.CamelContext; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.info.Info; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@EnableAutoConfiguration +@SpringBootApplication +@SpringBootTest(classes = {CamelAutoConfiguration.class, CamelInfoAutoConfiguration.class}) +public class CamelInfoTest extends Assert { + + @Autowired + CamelInfoContributor indicator; + + @Autowired + CamelContext camelContext; + + @Test + public void shouldHaveInfo() throws Exception { + Info.Builder builder = new Info.Builder(); + indicator.contribute(builder); + assertNotNull(builder); + + assertEquals(camelContext.getName(), builder.build().get("camel.name")); + assertEquals(camelContext.getVersion(), builder.build().get("camel.version")); + } + +} diff --git a/examples/camel-example-spring-boot/pom.xml b/examples/camel-example-spring-boot/pom.xml index 6f64fc6..d771ba3 100644 --- a/examples/camel-example-spring-boot/pom.xml +++ b/examples/camel-example-spring-boot/pom.xml @@ -74,7 +74,7 @@ </dependency> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-actuator</artifactId> + <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- Camel --> diff --git a/examples/camel-example-spring-boot/src/main/resources/application.properties b/examples/camel-example-spring-boot/src/main/resources/application.properties index 34397fc..032746e 100644 --- a/examples/camel-example-spring-boot/src/main/resources/application.properties +++ b/examples/camel-example-spring-boot/src/main/resources/application.properties @@ -31,15 +31,16 @@ timer.period = 2000 # add for example: &repeatCount=5 to the timer endpoint to make Camel idle #camel.springboot.duration-max-idle-seconds=15 -# all access to actuator endpoints without security -management.security.enabled = false -# turn on actuator health check -endpoints.health.enabled = true +# show verbose /health/health details so you can see Camel information also +management.endpoint.health.show-details=always -# allow to obtain basic information about camel routes (read only mode) +# allow to obtain basic information about Camel routes (read only mode) endpoints.camelroutes.enabled = true endpoints.camelroutes.read-only = true +# to turn off Camel info in: /health/info +#management.info.camel.enabled=false + # to configure logging levels #logging.level.org.springframework = INFO #logging.level.org.apache.camel.spring.boot = INFO -- To stop receiving notification emails like this one, please contact davscl...@apache.org.