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 2019/11/18 09:01:01 UTC

[camel] 19/23: CAMEL-14186: camel-core-starter - Spring Boot auto-configuration is not generated for some models

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-13691
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f1bd476dafe5a59d30434aedee2f0b3b13d016e0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 18 07:08:16 2019 +0100

    CAMEL-14186: camel-core-starter - Spring Boot auto-configuration is not generated for some models
---
 .../RestConfigurationDefinitionProperties.java     |  10 +-
 .../Resilience4jConfigurationDefinitionCommon.java | 219 +++++++++++++++++++++
 ...ilience4jConfigurationDefinitionProperties.java |  50 +++++
 .../packaging/SpringBootAutoConfigurationMojo.java |  45 +++--
 4 files changed, 299 insertions(+), 25 deletions(-)

diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionProperties.java
index 7cebfff..5111217 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionProperties.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionProperties.java
@@ -33,11 +33,11 @@ public class RestConfigurationDefinitionProperties {
 
     /**
      * The Camel Rest component to use for the REST transport (consumer), such
-     * as netty-http, jetty, servlet, undertow. If no component has been explicit configured,
-     * then Camel will lookup if there is a Camel component that integrates with
-     * the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is
-     * registered in the registry. If either one is found, then that is being
-     * used.
+     * as netty-http, jetty, servlet, undertow. If no component has been
+     * explicit configured, then Camel will lookup if there is a Camel component
+     * that integrates with the Rest DSL, or if a
+     * org.apache.camel.spi.RestConsumerFactory is registered in the registry.
+     * If either one is found, then that is being used.
      */
     private String component;
     /**
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/Resilience4jConfigurationDefinitionCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/Resilience4jConfigurationDefinitionCommon.java
new file mode 100644
index 0000000..b9ecfda
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/Resilience4jConfigurationDefinitionCommon.java
@@ -0,0 +1,219 @@
+/*
+ * 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.model.springboot;
+
+import javax.annotation.Generated;
+
+/**
+ * Resilience4j Circuit Breaker EIP configuration
+ * 
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+public class Resilience4jConfigurationDefinitionCommon {
+
+    /**
+     * Refers to an existing
+     * io.github.resilience4j.circuitbreaker.CircuitBreaker instance to lookup
+     * and use from the registry. When using this, then any other circuit
+     * breaker options are not in use.
+     */
+    private String circuitBreakerRef;
+    /**
+     * Refers to an existing
+     * io.github.resilience4j.circuitbreaker.CircuitBreakerConfig instance to
+     * lookup and use from the registry.
+     */
+    private String configRef;
+    /**
+     * Configures the failure rate threshold in percentage. If the failure rate
+     * is equal or greater than the threshold the CircuitBreaker transitions to
+     * open and starts short-circuiting calls. The threshold must be greater
+     * than 0 and not greater than 100. Default value is 50 percentage.
+     */
+    private Float failureRateThreshold;
+    /**
+     * Configures the number of permitted calls when the CircuitBreaker is half
+     * open. The size must be greater than 0. Default size is 10.
+     */
+    private Integer permittedNumberOfCallsInHalfOpenState = 10;
+    /**
+     * Configures the size of the sliding window which is used to record the
+     * outcome of calls when the CircuitBreaker is closed. slidingWindowSize
+     * configures the size of the sliding window. Sliding window can either be
+     * count-based or time-based. If slidingWindowType is COUNT_BASED, the last
+     * slidingWindowSize calls are recorded and aggregated. If slidingWindowType
+     * is TIME_BASED, the calls of the last slidingWindowSize seconds are
+     * recorded and aggregated. The slidingWindowSize must be greater than 0.
+     * The minimumNumberOfCalls must be greater than 0. If the slidingWindowType
+     * is COUNT_BASED, the minimumNumberOfCalls cannot be greater than
+     * slidingWindowSize. If the slidingWindowType is TIME_BASED, you can pick
+     * whatever you want. Default slidingWindowSize is 100.
+     */
+    private Integer slidingWindowSize = 100;
+    /**
+     * Configures the type of the sliding window which is used to record the
+     * outcome of calls when the CircuitBreaker is closed. Sliding window can
+     * either be count-based or time-based. If slidingWindowType is COUNT_BASED,
+     * the last slidingWindowSize calls are recorded and aggregated. If
+     * slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize
+     * seconds are recorded and aggregated. Default slidingWindowType is
+     * COUNT_BASED.
+     */
+    private String slidingWindowType = "COUNT_BASED";
+    /**
+     * Configures configures the minimum number of calls which are required (per
+     * sliding window period) before the CircuitBreaker can calculate the error
+     * rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls
+     * must be recorded, before the failure rate can be calculated. If only 9
+     * calls have been recorded the CircuitBreaker will not transition to open
+     * even if all 9 calls have failed. Default minimumNumberOfCalls is 100
+     */
+    private Integer minimumNumberOfCalls = 100;
+    /**
+     * Enables writable stack traces. When set to false, Exception.getStackTrace
+     * returns a zero length array. This may be used to reduce log spam when the
+     * circuit breaker is open as the cause of the exceptions is already known
+     * (the circuit breaker is short-circuiting calls).
+     */
+    private Boolean writableStackTraceEnabled = true;
+    /**
+     * Configures the wait duration (in seconds) which specifies how long the
+     * CircuitBreaker should stay open, before it switches to half open. Default
+     * value is 60 seconds.
+     */
+    private Integer waitDurationInOpenState = 60;
+    /**
+     * Enables automatic transition from OPEN to HALF_OPEN state once the
+     * waitDurationInOpenState has passed.
+     */
+    private Boolean automaticTransitionFromOpenToHalfOpenEnabled = false;
+    /**
+     * Configures a threshold in percentage. The CircuitBreaker considers a call
+     * as slow when the call duration is greater than
+     * slowCallDurationThreshold(Duration. When the percentage of slow calls is
+     * equal or greater the threshold, the CircuitBreaker transitions to open
+     * and starts short-circuiting calls. The threshold must be greater than 0
+     * and not greater than 100. Default value is 100 percentage which means
+     * that all recorded calls must be slower than slowCallDurationThreshold.
+     */
+    private Float slowCallRateThreshold;
+    /**
+     * Configures the duration threshold (seconds) above which calls are
+     * considered as slow and increase the slow calls percentage. Default value
+     * is 60 seconds.
+     */
+    private Integer slowCallDurationThreshold = 60;
+
+    public String getCircuitBreakerRef() {
+        return circuitBreakerRef;
+    }
+
+    public void setCircuitBreakerRef(String circuitBreakerRef) {
+        this.circuitBreakerRef = circuitBreakerRef;
+    }
+
+    public String getConfigRef() {
+        return configRef;
+    }
+
+    public void setConfigRef(String configRef) {
+        this.configRef = configRef;
+    }
+
+    public Float getFailureRateThreshold() {
+        return failureRateThreshold;
+    }
+
+    public void setFailureRateThreshold(Float failureRateThreshold) {
+        this.failureRateThreshold = failureRateThreshold;
+    }
+
+    public Integer getPermittedNumberOfCallsInHalfOpenState() {
+        return permittedNumberOfCallsInHalfOpenState;
+    }
+
+    public void setPermittedNumberOfCallsInHalfOpenState(
+            Integer permittedNumberOfCallsInHalfOpenState) {
+        this.permittedNumberOfCallsInHalfOpenState = permittedNumberOfCallsInHalfOpenState;
+    }
+
+    public Integer getSlidingWindowSize() {
+        return slidingWindowSize;
+    }
+
+    public void setSlidingWindowSize(Integer slidingWindowSize) {
+        this.slidingWindowSize = slidingWindowSize;
+    }
+
+    public String getSlidingWindowType() {
+        return slidingWindowType;
+    }
+
+    public void setSlidingWindowType(String slidingWindowType) {
+        this.slidingWindowType = slidingWindowType;
+    }
+
+    public Integer getMinimumNumberOfCalls() {
+        return minimumNumberOfCalls;
+    }
+
+    public void setMinimumNumberOfCalls(Integer minimumNumberOfCalls) {
+        this.minimumNumberOfCalls = minimumNumberOfCalls;
+    }
+
+    public Boolean getWritableStackTraceEnabled() {
+        return writableStackTraceEnabled;
+    }
+
+    public void setWritableStackTraceEnabled(Boolean writableStackTraceEnabled) {
+        this.writableStackTraceEnabled = writableStackTraceEnabled;
+    }
+
+    public Integer getWaitDurationInOpenState() {
+        return waitDurationInOpenState;
+    }
+
+    public void setWaitDurationInOpenState(Integer waitDurationInOpenState) {
+        this.waitDurationInOpenState = waitDurationInOpenState;
+    }
+
+    public Boolean getAutomaticTransitionFromOpenToHalfOpenEnabled() {
+        return automaticTransitionFromOpenToHalfOpenEnabled;
+    }
+
+    public void setAutomaticTransitionFromOpenToHalfOpenEnabled(
+            Boolean automaticTransitionFromOpenToHalfOpenEnabled) {
+        this.automaticTransitionFromOpenToHalfOpenEnabled = automaticTransitionFromOpenToHalfOpenEnabled;
+    }
+
+    public Float getSlowCallRateThreshold() {
+        return slowCallRateThreshold;
+    }
+
+    public void setSlowCallRateThreshold(Float slowCallRateThreshold) {
+        this.slowCallRateThreshold = slowCallRateThreshold;
+    }
+
+    public Integer getSlowCallDurationThreshold() {
+        return slowCallDurationThreshold;
+    }
+
+    public void setSlowCallDurationThreshold(Integer slowCallDurationThreshold) {
+        this.slowCallDurationThreshold = slowCallDurationThreshold;
+    }
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/Resilience4jConfigurationDefinitionProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/Resilience4jConfigurationDefinitionProperties.java
new file mode 100644
index 0000000..dcc6b32
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/Resilience4jConfigurationDefinitionProperties.java
@@ -0,0 +1,50 @@
+/*
+ * 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.model.springboot;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.resilience4j")
+public class Resilience4jConfigurationDefinitionProperties
+        extends
+            Resilience4jConfigurationDefinitionCommon {
+
+    /**
+     * Enable the component
+     */
+    private boolean enabled = true;
+    /**
+     * Define additional configuration definitions
+     */
+    private Map<String, Resilience4jConfigurationDefinitionCommon> configurations = new HashMap<>();
+
+    public Map<String, Resilience4jConfigurationDefinitionCommon> getConfigurations() {
+        return configurations;
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+}
\ No newline at end of file
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
index 32d6dce..e7257d8 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
@@ -197,7 +197,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         }
 
         // Spring-boot configuration has been moved on starters
-        File starterDir = SpringBootHelper.starterDir(baseDir, project.getArtifactId());
+        File starterDir = SpringBootHelper.starterDir(baseDir, getStarterArtifactId());
         if (!starterDir.exists() || !(new File(starterDir, "pom.xml").exists())) {
             // If the starter does not exist, no configuration can be created
             getLog().info("Component auto-configuration will not be created: the starter does not exist");
@@ -209,9 +209,13 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
 
     private void executeAll() throws MojoExecutionException, MojoFailureException {
         Map<File, Supplier<String>> files = PackageHelper.findJsonFiles(buildDir, p -> p.isDirectory() || p.getName().endsWith(".json")).stream()
-            .collect(Collectors.toMap(Function.identity(), s -> cache(() -> loadJson(s))));
+                .collect(Collectors.toMap(Function.identity(), s -> cache(() -> loadJson(s))));
+
+        // special for camel-core-engine where we generate some special auto-configuration source code
+        if ("camel-core-engine".equals(project.getArtifactId())) {
+            executeModels(files);
+        }
 
-        executeModels(files);
         executeComponent(files);
         executeDataFormat(files);
         executeLanguage(files);
@@ -250,8 +254,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-hystrix-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createOtherModelConfigurationSource(pkg, model, "camel.hystrix", true);
         }
 
@@ -263,8 +266,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-resilience4j-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createOtherModelConfigurationSource(pkg, model, "camel.resilience4j", true);
         }
 
@@ -276,8 +278,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-consul-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createOtherModelConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery", true);
         }
 
@@ -289,8 +290,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-dns-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createOtherModelConfigurationSource(pkg, model, "camel.cloud.dns.service-discovery", true);
         }
 
@@ -302,8 +302,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-etcd-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createOtherModelConfigurationSource(pkg, model, "camel.cloud.etcd.service-discovery", true);
         }
 
@@ -328,8 +327,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-kubernetes-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createOtherModelConfigurationSource(pkg, model, "camel.cloud.ribbon.load-balancer", true);
         }
 
@@ -341,8 +339,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             int pos = model.getJavaType().lastIndexOf(".");
             String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-            // Generate properties, auto-configuration happens in
-            // camel-kubernetes-starter
+            // Generate properties, auto-configuration for camel-core-starter
             createRestConfigurationSource(pkg, model, "camel.rest");
             createRestModuleAutoConfigurationSource(pkg, model);
         }
@@ -2178,7 +2175,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
 
     private void writeSourceIfChanged(String source, String fileName) throws MojoFailureException {
 
-        File target = new File(SpringBootHelper.starterSrcDir(baseDir, project.getArtifactId()), fileName);
+        File target = new File(SpringBootHelper.starterSrcDir(baseDir, getStarterArtifactId()), fileName);
 
         deleteFileOnMainArtifact(target);
 
@@ -2204,7 +2201,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         sb.append(lineToAdd);
 
         String fileName = "META-INF/spring.factories";
-        File target = new File(SpringBootHelper.starterResourceDir(baseDir, project.getArtifactId()), fileName);
+        File target = new File(SpringBootHelper.starterResourceDir(baseDir, getStarterArtifactId()), fileName);
 
         deleteFileOnMainArtifact(target);
 
@@ -2268,12 +2265,20 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         }
     }
 
+    private String getStarterArtifactId() {
+        if ("camel-core-engine".equals(project.getArtifactId())) {
+            return "camel-core";
+        } else {
+            return project.getArtifactId();
+        }
+    }
+
     private void deleteFileOnMainArtifact(File starterFile) {
         if (!DELETE_FILES_ON_MAIN_ARTIFACTS) {
             return;
         }
 
-        String relativePath = SpringBootHelper.starterDir(baseDir, project.getArtifactId()).toPath().relativize(starterFile.toPath()).toString();
+        String relativePath = SpringBootHelper.starterDir(baseDir, getStarterArtifactId()).toPath().relativize(starterFile.toPath()).toString();
         File mainArtifactFile = new File(baseDir, relativePath);
         if (mainArtifactFile.exists()) {
             boolean deleted = mainArtifactFile.delete();