You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/04/26 13:12:25 UTC

[camel] branch master updated: CAMEL-12460 Fix camel actuator endpoints to get it working with SB2 (#2307)

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


The following commit(s) were added to refs/heads/master by this push:
     new dc6caa6  CAMEL-12460 Fix camel actuator endpoints to get it working with SB2 (#2307)
dc6caa6 is described below

commit dc6caa696255240a2a27c3bf229fc3aac9014401
Author: Tomohisa Igarashi <tm...@gmail.com>
AuthorDate: Thu Apr 26 09:12:19 2018 -0400

    CAMEL-12460 Fix camel actuator endpoints to get it working with SB2 (#2307)
    
    * CAMEL-12460 Fix camel actuator endpoints to get it working with SB2
    
    Also extracted CamelRoutesEndpointProperties as a separated class from CamelRoutesEndpoint
    
    * CAMEL-12460 Update camel-archetype-spring-boot to align with SB2
    
    Reflected review comments:
     * Updated actuator properties in archetype template to get working with SB2
     * Added a comment on the -parameter javac option that it's required for SB2 actuator endpoint
---
 .../main/resources/archetype-resources/readme.adoc |  4 +--
 .../src/main/resources/application.properties      |  9 ++++--
 .../boot/actuate/endpoint/CamelRoutesEndpoint.java | 21 +++++--------
 .../CamelRoutesEndpointAutoConfiguration.java      | 12 +++++++-
 .../endpoint/CamelRoutesEndpointProperties.java    | 34 ++++++++++++++++++++++
 .../additional-spring-configuration-metadata.json  |  8 +----
 .../pom.xml                                        |  2 +-
 .../readme.adoc                                    | 10 +++----
 .../src/main/resources/application.properties      |  4 ++-
 examples/camel-example-spring-boot/readme.adoc     |  4 +--
 .../src/main/resources/application.properties      |  4 +++
 parent/pom.xml                                     |  6 ++++
 12 files changed, 82 insertions(+), 36 deletions(-)

diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
index 310c8fb..1fc8d6d 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
@@ -26,13 +26,13 @@ You can run this example using
 To show a summary of all the routes
 
 ----
-curl -XGET -s http://localhost:8080/camel/routes
+curl -XGET -s http://localhost:8080/camelroutes
 ----
 
 To show detailed information for a specific route
 
 ----
-curl -XGET -s http://localhost:8080/camel/routes/{id}/info
+curl -XGET -s http://localhost:8080/camelroutes/{id}/detail
 ----
 
 
diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
index 34397fc..24b20c1 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
@@ -31,14 +31,17 @@ timer.period = 2000
 # add for example: &repeatCount=5 to the timer endpoint to make Camel idle
 #camel.springboot.duration-max-idle-seconds=15
 
+# expose actuator endpoint via HTTP
+management.endpoints.web.exposure.include=info,health,camelroutes
+
 # all access to actuator endpoints without security
 management.security.enabled = false
 # turn on actuator health check
-endpoints.health.enabled = true
+management.endpoint.health.enabled = true
 
 # allow to obtain basic information about camel routes (read only mode)
-endpoints.camelroutes.enabled = true
-endpoints.camelroutes.read-only = true
+management.endpoint.camelroutes.enabled = true
+management.endpoint.camelroutes.read-only = true
 
 # to configure logging levels
 #logging.level.org.springframework = INFO
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
index e9f8a53..f7978e4 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
@@ -39,19 +39,20 @@ import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
 import org.springframework.boot.actuate.endpoint.annotation.Selector;
 import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.lang.Nullable;
 
 /**
  * {@link Endpoint} to expose {@link org.apache.camel.Route} information.
  */
 @Endpoint(id = "camelroutes", enableByDefault = true)
-@ConfigurationProperties("management.endpoint.camelroutes")
 public class CamelRoutesEndpoint {
 
     private CamelContext camelContext;
-    private boolean readOnly = true;
+    private CamelRoutesEndpointProperties properties;
 
-    public CamelRoutesEndpoint(CamelContext camelContext) {
+    public CamelRoutesEndpoint(CamelContext camelContext, CamelRoutesEndpointProperties properties) {
         this.camelContext = camelContext;
+        this.properties = properties;
     }
 
     @ReadOperation
@@ -72,8 +73,8 @@ public class CamelRoutesEndpoint {
     }
 
     @WriteOperation
-    public void doWriteAction(@Selector String id, @Selector WriteAction action, TimeInfo timeInfo) {
-        if (this.isReadOnly()) {
+    public void doWriteAction(@Selector String id, @Selector WriteAction action, @Nullable TimeInfo timeInfo) {
+        if (this.properties.isReadOnly()) {
             throw new IllegalArgumentException(String.format("Read only: write action %s is not allowed", action));
         }
 
@@ -106,7 +107,7 @@ public class CamelRoutesEndpoint {
 
     @WriteOperation
     public String getRouteDump(@Selector String id) {
-        if (this.isReadOnly()) {
+        if (this.properties.isReadOnly()) {
             throw new IllegalArgumentException("Read only: route dump is not permitted in read-only mode");
         }
 
@@ -121,14 +122,6 @@ public class CamelRoutesEndpoint {
         return null;
     }
 
-    public boolean isReadOnly() {
-        return readOnly;
-    }
-
-    public void setReadOnly(boolean readOnly) {
-        this.readOnly = readOnly;
-    }
-
     private RouteEndpointInfo getRouteInfo(String id) {
         Route route = camelContext.getRoute(id);
         if (route != null) {
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
index 5b44269..8a2ccda 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
@@ -18,11 +18,14 @@ package org.apache.camel.spring.boot.actuate.endpoint;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
 import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
+import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
 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.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -30,17 +33,24 @@ import org.springframework.context.annotation.Configuration;
  * Auto configuration for the {@link CamelRoutesEndpoint}.
  */
 @Configuration
+@EnableConfigurationProperties({ CamelRoutesEndpointProperties.class })
 @ConditionalOnClass({CamelRoutesEndpoint.class})
 @ConditionalOnBean(CamelAutoConfiguration.class)
 @AutoConfigureAfter(CamelAutoConfiguration.class)
 public class CamelRoutesEndpointAutoConfiguration {
 
+    private CamelRoutesEndpointProperties properties;
+
+    public CamelRoutesEndpointAutoConfiguration(CamelRoutesEndpointProperties properties) {
+        this.properties = properties;
+    }
+
     @Bean
     @ConditionalOnClass(CamelContext.class)
     @ConditionalOnMissingBean
     @ConditionalOnEnabledEndpoint
     public CamelRoutesEndpoint camelEndpoint(CamelContext camelContext) {
-        return new CamelRoutesEndpoint(camelContext);
+        return new CamelRoutesEndpoint(camelContext, properties);
     }
 
 }
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointProperties.java
new file mode 100644
index 0000000..a5a18d1
--- /dev/null
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointProperties.java
@@ -0,0 +1,34 @@
+/**
+ * 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.endpoint;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("management.endpoint.camelroutes")
+public class CamelRoutesEndpointProperties {
+
+    private boolean readOnly = true;
+
+    public boolean isReadOnly() {
+        return readOnly;
+    }
+
+    public void setReadOnly(boolean readOnly) {
+        this.readOnly = readOnly;
+    }
+
+}
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 e756628..cf56bd1 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
@@ -1,16 +1,10 @@
 {
   "properties": [
     {
-      "name": "management.endpoint.camelroutes.path",
-      "type": "java.lang.String",
-      "description": "The URL path to use for Camel Routes actuator endpoint.",
-      "defaultValue": "/camel/routes"
-    },
-    {
       "name": "management.endpoint.camelroutes.read-only",
       "type": "java.lang.Boolean",
       "description": "Whether Camel Routes actuator is in read-only mode. If not in read-only mode then operations to start/stop routes would be enabled.",
-      "defaultValue": "true"
+      "defaultValue": true
     },
     {
       "name": "management.endpoint.camelroutes.enabled",
diff --git a/examples/camel-example-spring-boot-supervising-route-controller/pom.xml b/examples/camel-example-spring-boot-supervising-route-controller/pom.xml
index 11b7ec9..c00d489 100644
--- a/examples/camel-example-spring-boot-supervising-route-controller/pom.xml
+++ b/examples/camel-example-spring-boot-supervising-route-controller/pom.xml
@@ -85,7 +85,7 @@
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-actuator</artifactId>
+      <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
diff --git a/examples/camel-example-spring-boot-supervising-route-controller/readme.adoc b/examples/camel-example-spring-boot-supervising-route-controller/readme.adoc
index 8c7bb28..2c5aa35 100644
--- a/examples/camel-example-spring-boot-supervising-route-controller/readme.adoc
+++ b/examples/camel-example-spring-boot-supervising-route-controller/readme.adoc
@@ -14,35 +14,35 @@ Beside JMX you can use Spring Boot Endpoints to interact with the routes:
 +
 [source]
 ----
-curl -XGET -s http://localhost:8080/camel/routes
+curl -XGET -s http://localhost:8080/actuator/camelroutes
 ----
 +
 +* To get details about a route
 ++
 +[source]
 +----
-+curl -XGET -s http://localhost:8080/camel/routes/{id}/detail
++curl -XGET -s http://localhost:8080/actuator/camelroutes/{id}/detail
 +----
 
 * To get info about a route
 +
 [source]
 ----
-curl -XGET -s http://localhost:8080/camel/routes/{id}/info
+curl -XGET -s http://localhost:8080/actuator/camelroutes/{id}/info
 ----
 
 * To stop a route
 +
 [source]
 ----
-curl -XPOST -s http://localhost:8080/camel/routes/{id}/stop
+curl -XPOST -H "Content-Type: application/json" -s http://localhost:8080/actuator/camelroutes/{id}/stop
 ----
 
 * To start a route
 +
 [source]
 ----
-curl -XPOST -s http://localhost:8080/camel/routes/{id}/stop
+curl -XPOST -H "Content-Type: application/json" -s http://localhost:8080/actuator/camelroutes/{id}/start
 ----
 
 
diff --git a/examples/camel-example-spring-boot-supervising-route-controller/src/main/resources/application.properties b/examples/camel-example-spring-boot-supervising-route-controller/src/main/resources/application.properties
index e19589a..63741bd 100644
--- a/examples/camel-example-spring-boot-supervising-route-controller/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-supervising-route-controller/src/main/resources/application.properties
@@ -24,13 +24,15 @@ logging.level.org.apache.camel.impl.SupervisingRouteController = DEBUG
 logging.level.org.apache.camel.util.backoff = DEBUG
 logging.level.sample.camel = DEBUG
 
+# expose actuator endpoint via HTTP
+management.endpoints.web.exposure.include=info,health,camelroutes
+
 management.endpoints.enabled-by-default = true
 management.endpoints.jmx.enabled = false
 management.endpoint.health.enabled = true
 
 # camel routes is by default enabled
 # so you do not have to configure below
-# management.endpoint.camelroutes.path = /camel/routes
 # management.endpoint.camelroutes.enabled = true
 
 # turn off read-only so we can stop/start the Camel routes
diff --git a/examples/camel-example-spring-boot/readme.adoc b/examples/camel-example-spring-boot/readme.adoc
index ca38462..7e5d7f0 100644
--- a/examples/camel-example-spring-boot/readme.adoc
+++ b/examples/camel-example-spring-boot/readme.adoc
@@ -34,13 +34,13 @@ curl -XGET -s http://localhost:8080/actuator/health
 To show a summary of all the routes
 
 ----
-curl -XGET -s http://localhost:8080/actuator/camel/routes
+curl -XGET -s http://localhost:8080/actuator/camelroutes
 ----
 
 To show detailed information for a specific route
 
 ----
-curl -XGET -s http://localhost:8080/actuator/camel/routes/{id}/info
+curl -XGET -s http://localhost:8080/actuator/camelroutes/{id}/detail
 ----
 
 
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 cefe0da..0c5cc55 100644
--- a/examples/camel-example-spring-boot/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot/src/main/resources/application.properties
@@ -31,6 +31,9 @@ timer.period = 2000
 # add for example: &repeatCount=5 to the timer endpoint to make Camel idle
 #camel.springboot.duration-max-idle-seconds=15
 
+# expose actuator endpoint via HTTP
+management.endpoints.web.exposure.include=info,health,camelroutes
+
 # show verbose health details (/actuator/info) so you can see Camel information also
 management.endpoint.health.show-details=always
 
@@ -46,3 +49,4 @@ management.endpoint.camelroutes.read-only = true
 #logging.level.org.apache.camel.spring.boot = INFO
 #logging.level.org.apache.camel.impl = DEBUG
 #logging.level.sample.camel = DEBUG
+
diff --git a/parent/pom.xml b/parent/pom.xml
index 36341a8..7a9a2f4 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -5009,6 +5009,10 @@
               <target>${jdk.version}</target>
               <maxmem>512M</maxmem>
               <fork>${compiler.fork}</fork>
+              <compilerArgs>
+                <!-- SB2 actuator endpoint requires MethodParameter metadata -->
+                <arg>-parameters</arg>
+              </compilerArgs>
           </configuration>
         </plugin>
         <plugin>
@@ -5687,6 +5691,8 @@
                 <compilerArgs>
                   <arg>-J--add-modules</arg>
                   <arg>-Jjava.xml.bind</arg>
+                  <!-- SB2 actuator endpoint requires MethodParameter metadata -->
+                  <arg>-parameters</arg>
                 </compilerArgs>
               </configuration>
             </plugin>

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.