CAMEL-11581: SupervisingRouteController should have spring-boot auto configuration
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b354cba3 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b354cba3 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b354cba3 Branch: refs/heads/master Commit: b354cba3f9af46490754ceb8668e6f7259a38183 Parents: 6893a37 Author: lburgazzoli <lburgazz...@gmail.com> Authored: Fri Aug 4 18:03:50 2017 +0200 Committer: lburgazzoli <lburgazz...@gmail.com> Committed: Tue Aug 8 13:29:27 2017 +0200 ---------------------------------------------------------------------- ...rvisingRouteControllerAutoConfiguration.java | 78 +++++++++++++ ...SupervisingRouteControllerConfiguration.java | 109 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + ...rvisingRouteControllerAutoConfiguration.java | 79 -------------- ...SupervisingRouteControllerConfiguration.java | 109 ------------------- .../main/resources/META-INF/spring.factories | 1 - 6 files changed, 188 insertions(+), 189 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b354cba3/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java new file mode 100644 index 0000000..7382c6f --- /dev/null +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerAutoConfiguration.java @@ -0,0 +1,78 @@ +/** + * 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; + +import java.util.Map; +import java.util.Optional; + +import org.apache.camel.converter.TimePatternConverter; +import org.apache.camel.impl.SupervisingRouteController; +import org.apache.camel.spi.RouteController; +import org.apache.camel.spring.boot.SupervisingRouteControllerConfiguration.BackOffConfiguration; +import org.apache.camel.spring.boot.SupervisingRouteControllerConfiguration.RouteConfiguration; +import org.apache.camel.util.backoff.BackOff; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +@Configuration +@AutoConfigureBefore(CamelAutoConfiguration.class) +@ConditionalOnProperty(prefix = "camel.supervising.controller", name = "enabled") +@EnableConfigurationProperties(SupervisingRouteControllerConfiguration.class) +public class SupervisingRouteControllerAutoConfiguration { + @Autowired + private SupervisingRouteControllerConfiguration configuration; + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) + @ConditionalOnMissingBean + public RouteController routeController() { + SupervisingRouteController controller = new SupervisingRouteController(); + + controller.setDefaultBackOff(configureBackOff(Optional.empty(), configuration.getBackOff())); + + for (Map.Entry<String, RouteConfiguration> entry: configuration.getRoutes().entrySet()) { + controller.setBackOff( + entry.getKey(), + configureBackOff( + Optional.ofNullable(controller.getDefaultBackOff()), + entry.getValue().getBackOff() + ) + ); + } + + return controller; + } + + private BackOff configureBackOff(Optional<BackOff> template, BackOffConfiguration conf) { + final BackOff.Builder builder = template.map(t -> BackOff.builder().read(t)).orElseGet(BackOff::builder); + + Optional.ofNullable(conf.getDelay()).map(TimePatternConverter::toMilliSeconds).ifPresent(builder::delay); + Optional.ofNullable(conf.getMaxDelay()).map(TimePatternConverter::toMilliSeconds).ifPresent(builder::maxDelay); + Optional.ofNullable(conf.getMaxElapsedTime()).map(TimePatternConverter::toMilliSeconds).ifPresent(builder::maxElapsedTime); + Optional.ofNullable(conf.getMaxAttempts()).ifPresent(builder::maxAttempts); + Optional.ofNullable(conf.getMultiplier()).ifPresent(builder::multiplier); + + return builder.build(); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b354cba3/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java new file mode 100644 index 0000000..01c2d0e --- /dev/null +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SupervisingRouteControllerConfiguration.java @@ -0,0 +1,109 @@ +/** + * 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; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.supervising.controller") +public class SupervisingRouteControllerConfiguration { + private boolean enabled; + private BackOffConfiguration backOff = new BackOffConfiguration(); + private Map<String, RouteConfiguration> routes = new HashMap<>(); + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public BackOffConfiguration getBackOff() { + return backOff; + } + + public Map<String, RouteConfiguration> getRoutes() { + return routes; + } + + // ***************************************** + // Configuration Classes + // ***************************************** + + public static class RouteConfiguration { + private BackOffConfiguration backOff; + + public BackOffConfiguration getBackOff() { + return backOff; + } + + public void setBackOff(BackOffConfiguration backOff) { + this.backOff = backOff; + } + } + + public static class BackOffConfiguration { + private String delay; + private String maxDelay; + private String maxElapsedTime; + private Long maxAttempts; + private Double multiplier; + + public String getDelay() { + return delay; + } + + public void setDelay(String delay) { + this.delay = delay; + } + + public String getMaxDelay() { + return maxDelay; + } + + public void setMaxDelay(String maxDelay) { + this.maxDelay = maxDelay; + } + + public String getMaxElapsedTime() { + return maxElapsedTime; + } + + public void setMaxElapsedTime(String maxElapsedTime) { + this.maxElapsedTime = maxElapsedTime; + } + + public Long getMaxAttempts() { + return maxAttempts; + } + + public void setMaxAttempts(Long maxAttempts) { + this.maxAttempts = maxAttempts; + } + + public Double getMultiplier() { + return multiplier; + } + + public void setMultiplier(Double multiplier) { + this.multiplier = multiplier; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b354cba3/components/camel-spring-boot/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- 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 15dd1a7..8550060 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 @@ -17,6 +17,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.apache.camel.spring.boot.CamelAutoConfiguration,\ +org.apache.camel.spring.boot.SupervisingRouteControllerAutoConfiguration,\ org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpointAutoConfiguration,\ org.apache.camel.spring.boot.actuate.health.CamelHealthAutoConfiguration,\ org.apache.camel.spring.boot.cloud.CamelCloudAutoConfiguration,\ http://git-wip-us.apache.org/repos/asf/camel/blob/b354cba3/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerAutoConfiguration.java deleted file mode 100644 index d872ec3..0000000 --- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerAutoConfiguration.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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.impl.springboot; - -import java.util.Map; -import java.util.Optional; - -import org.apache.camel.converter.TimePatternConverter; -import org.apache.camel.impl.SupervisingRouteController; -import org.apache.camel.impl.springboot.SupervisingRouteControllerConfiguration.BackOffConfiguration; -import org.apache.camel.impl.springboot.SupervisingRouteControllerConfiguration.RouteConfiguration; -import org.apache.camel.spi.RouteController; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.util.backoff.BackOff; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Scope; - -@Configuration -@AutoConfigureBefore(CamelAutoConfiguration.class) -@ConditionalOnProperty(prefix = "camel.supervising.controller", name = "enabled") -@EnableConfigurationProperties(SupervisingRouteControllerConfiguration.class) -public class SupervisingRouteControllerAutoConfiguration { - @Autowired - private SupervisingRouteControllerConfiguration configuration; - - @Bean - @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) - @ConditionalOnMissingBean - public RouteController routeController() { - SupervisingRouteController controller = new SupervisingRouteController(); - - controller.setDefaultBackOff(configureBackOff(Optional.empty(), configuration.getBackOff())); - - for (Map.Entry<String, RouteConfiguration> entry: configuration.getRoutes().entrySet()) { - controller.setBackOff( - entry.getKey(), - configureBackOff( - Optional.ofNullable(controller.getDefaultBackOff()), - entry.getValue().getBackOff() - ) - ); - } - - return controller; - } - - private BackOff configureBackOff(Optional<BackOff> template, BackOffConfiguration conf) { - final BackOff.Builder builder = template.map(t -> BackOff.builder().read(t)).orElseGet(BackOff::builder); - - Optional.ofNullable(conf.getDelay()).map(TimePatternConverter::toMilliSeconds).ifPresent(builder::delay); - Optional.ofNullable(conf.getMaxDelay()).map(TimePatternConverter::toMilliSeconds).ifPresent(builder::maxDelay); - Optional.ofNullable(conf.getMaxElapsedTime()).map(TimePatternConverter::toMilliSeconds).ifPresent(builder::maxElapsedTime); - Optional.ofNullable(conf.getMaxAttempts()).ifPresent(builder::maxAttempts); - Optional.ofNullable(conf.getMultiplier()).ifPresent(builder::multiplier); - - return builder.build(); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/b354cba3/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerConfiguration.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerConfiguration.java deleted file mode 100644 index 4460671..0000000 --- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/impl/springboot/SupervisingRouteControllerConfiguration.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * 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.impl.springboot; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "camel.supervising.controller") -public class SupervisingRouteControllerConfiguration { - private boolean enabled; - private BackOffConfiguration backOff = new BackOffConfiguration(); - private Map<String, RouteConfiguration> routes = new HashMap<>(); - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public BackOffConfiguration getBackOff() { - return backOff; - } - - public Map<String, RouteConfiguration> getRoutes() { - return routes; - } - - // ***************************************** - // Configuration Classes - // ***************************************** - - public static class RouteConfiguration { - private BackOffConfiguration backOff; - - public BackOffConfiguration getBackOff() { - return backOff; - } - - public void setBackOff(BackOffConfiguration backOff) { - this.backOff = backOff; - } - } - - public static class BackOffConfiguration { - private String delay; - private String maxDelay; - private String maxElapsedTime; - private Long maxAttempts; - private Double multiplier; - - public String getDelay() { - return delay; - } - - public void setDelay(String delay) { - this.delay = delay; - } - - public String getMaxDelay() { - return maxDelay; - } - - public void setMaxDelay(String maxDelay) { - this.maxDelay = maxDelay; - } - - public String getMaxElapsedTime() { - return maxElapsedTime; - } - - public void setMaxElapsedTime(String maxElapsedTime) { - this.maxElapsedTime = maxElapsedTime; - } - - public Long getMaxAttempts() { - return maxAttempts; - } - - public void setMaxAttempts(Long maxAttempts) { - this.maxAttempts = maxAttempts; - } - - public Double getMultiplier() { - return multiplier; - } - - public void setMultiplier(Double multiplier) { - this.multiplier = multiplier; - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/b354cba3/platforms/spring-boot/components-starter/camel-core-starter/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-core-starter/src/main/resources/META-INF/spring.factories index 656661c..253b608 100644 --- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/resources/META-INF/spring.factories @@ -29,7 +29,6 @@ org.apache.camel.impl.springboot.StringDataFormatAutoConfiguration,\ org.apache.camel.impl.springboot.ZipDataFormatAutoConfiguration,\ org.apache.camel.impl.springboot.GzipDataFormatAutoConfiguration,\ org.apache.camel.impl.springboot.SerializationDataFormatAutoConfiguration,\ -org.apache.camel.impl.springboot.SupervisingRouteControllerAutoConfiguration,\ org.apache.camel.language.constant.springboot.ConstantLanguageAutoConfiguration,\ org.apache.camel.language.simple.springboot.SimpleLanguageAutoConfiguration,\ org.apache.camel.language.ref.springboot.RefLanguageAutoConfiguration,\